Search in sources :

Example 1 with TextSegment

use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.

the class SetextHeaderBlock method process.

@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
    Line currentLine = lineSequence.getCurrentLine();
    Line nextLine = lineSequence.getNextLine();
    Matcher matcher = setextUnderlinePattern.matcher(nextLine.getText());
    checkState(matcher.matches());
    lineSequence.advance();
    builder.setLocator(currentLine.toLocator());
    int headingLevel = headingLevel(matcher);
    TextSegment textSegment = new TextSegment(Collections.singletonList(currentLine));
    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();
    lineSequence.advance();
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) Matcher(java.util.regex.Matcher) HeadingAttributes(org.eclipse.mylyn.wikitext.parser.HeadingAttributes) InlineParser(org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser) TextSegment(org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment)

Example 2 with TextSegment

use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.

the class ParagraphBlock method createContext.

@Override
public void createContext(ProcessingContextBuilder contextBuilder, LineSequence lineSequence) {
    TextSegment textSegment = extractTextSegment(lineSequence);
    contextBuilder.getInlineParser().createContext(contextBuilder, textSegment);
}
Also used : TextSegment(org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment)

Example 3 with TextSegment

use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.

the class PotentialEmphasisSpanTest method createCursor.

private Cursor createCursor(String markup, int offset) {
    TextSegment segment = new TextSegment(ImmutableList.of(new Line(1, 0, markup)));
    Cursor cursor = new Cursor(segment);
    cursor.advance(offset);
    return cursor;
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) TextSegment(org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment)

Example 4 with TextSegment

use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.

the class CursorTest method toCursorOffset.

@Test
public void toCursorOffset() {
    Cursor cursor = new Cursor(new TextSegment(ImmutableList.of(new Line(1, 10, "abc"))));
    assertEquals(0, cursor.toCursorOffset(10));
    assertEquals(2, cursor.toCursorOffset(12));
    thrown.expect(IllegalArgumentException.class);
    cursor.toCursorOffset(9);
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) TextSegment(org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment) Test(org.junit.Test)

Example 5 with TextSegment

use of org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment in project mylyn.docs by eclipse.

the class FencedCodeBlock method addInfoTextCssClass.

private void addInfoTextCssClass(ProcessingContext processingContext, Attributes codeAttributes, Matcher matcher) {
    String infoText = matcher.group(3);
    if (infoText != null && !infoText.isEmpty()) {
        InlineParser inlineParser = processingContext.getInlineParser();
        String language = inlineParser.toStringContent(processingContext, new TextSegment(Collections.singletonList(new Line(0, 0, infoText))));
        codeAttributes.setCssClass("language-" + language);
    }
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) InlineParser(org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser) TextSegment(org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment)

Aggregations

TextSegment (org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment)10 Line (org.eclipse.mylyn.wikitext.commonmark.internal.Line)7 InlineParser (org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser)3 Matcher (java.util.regex.Matcher)2 HeadingAttributes (org.eclipse.mylyn.wikitext.parser.HeadingAttributes)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 Inline (org.eclipse.mylyn.wikitext.commonmark.internal.inlines.Inline)1 SimplifiedHtmlDocumentBuilder (org.eclipse.mylyn.wikitext.commonmark.internal.spec.SimplifiedHtmlDocumentBuilder)1 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)1 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)1