use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.
the class AtxHeaderBlock method process.
@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
Line currentLine = lineSequence.getCurrentLine();
Matcher matcher = PATTERN.matcher(currentLine.getText());
checkState(matcher.matches());
lineSequence.advance();
builder.setLocator(currentLine.toLocator());
int contentOffset = matcher.start(2);
int contentEnd = matcher.end(2);
int headingLevel = headingLevel(matcher);
if (contentEnd > contentOffset) {
Line headerContent = currentLine.segment(contentOffset, contentEnd - contentOffset);
TextSegment textSegment = new TextSegment(Collections.singletonList(headerContent));
HeadingAttributes attributes = new HeadingAttributes();
InlineParser inlineParser = context.getInlineParser();
String headingText = inlineParser.toStringContent(context, textSegment);
attributes.setId(context.generateHeadingId(headingLevel, headingText));
builder.beginHeading(headingLevel, attributes);
inlineParser.emit(context, builder, textSegment);
builder.endHeading();
} else {
builder.beginHeading(headingLevel, new HeadingAttributes());
builder.endHeading();
}
}
use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.
the class ParagraphBlock method processInlines.
void processInlines(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence, boolean asBlock) {
TextSegment textSegment = extractTextSegment(lineSequence);
List<Inline> inlines = context.getInlineParser().parse(context, textSegment);
if (!emptyParagraph(inlines)) {
builder.setLocator(textSegment.getLines().get(0).toLocator());
if (asBlock) {
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
}
InlineParser.emit(builder, inlines);
if (asBlock) {
builder.endBlock();
}
}
}
use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.
the class AbstractSourceSpanTest method assertParseToHtml.
public void assertParseToHtml(String expected, String markup) {
StringWriter writer = new StringWriter();
HtmlDocumentBuilder builder = new SimplifiedHtmlDocumentBuilder(writer);
builder.setEmitAsDocument(false);
builder.beginDocument();
InlineParser parser = new InlineParser(span, new AllCharactersSpan());
List<Inline> inlines = parser.parse(ProcessingContext.builder().build(), new TextSegment(ImmutableList.of(new Line(1, 0, markup))));
for (Inline inline : inlines) {
inline.emit(builder);
}
builder.endDocument();
assertEquals(expected, writer.toString());
}
use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.
the class InlineParserTest method assertParse.
private void assertParse(String content, Inline... inlines) {
List<Inline> expected = Arrays.asList(inlines);
List<Inline> actual = createInlines().parse(ProcessingContext.builder().build(), new TextSegment(LineSequence.create(content)));
for (int x = 0; x < expected.size() && x < actual.size(); ++x) {
assertEquivalent(x, expected.get(x), actual.get(x));
}
assertEquals(expected, actual);
}
use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.
the class InlineParserTest method toStringContent.
@Test
public void toStringContent() {
InlineParser parser = new InlineParser(new CodeSpan(), new AllCharactersSpan());
String stringContent = parser.toStringContent(ProcessingContext.builder().build(), new TextSegment(Collections.singletonList(new Line(1, 0, "one `two` three"))));
assertEquals("one two three", stringContent);
}
Aggregations