Search in sources :

Example 1 with InlineParser

use of org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser 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 InlineParser

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

the class ProcessingContextTest method inlineParser.

@Test
public void inlineParser() {
    InlineParser inlineParser = new InlineParser(ImmutableList.<SourceSpan>of());
    ProcessingContext context = ProcessingContext.builder().inlineParser(inlineParser).build();
    assertSame(inlineParser, context.getInlineParser());
    assertNotNull(ProcessingContext.builder().build().getInlineParser());
}
Also used : InlineParser(org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser) Test(org.junit.Test)

Example 3 with InlineParser

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

the class InlineContent method markdown.

public static InlineParser markdown() {
    ImmutableList.Builder<SourceSpan> spansBuilder = ImmutableList.builder();
    addStandardSpans(spansBuilder);
    spansBuilder.add(new AutoLinkWithoutDemarcationSpan());
    addTerminatorSpans(spansBuilder);
    return new InlineParser(spansBuilder.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourceSpan(org.eclipse.mylyn.wikitext.commonmark.internal.inlines.SourceSpan) InlineParser(org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser) AutoLinkWithoutDemarcationSpan(org.eclipse.mylyn.wikitext.commonmark.internal.inlines.AutoLinkWithoutDemarcationSpan)

Example 4 with InlineParser

use of org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser 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)

Example 5 with InlineParser

use of org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser 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();
    }
}
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)

Aggregations

InlineParser (org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser)5 Line (org.eclipse.mylyn.wikitext.commonmark.internal.Line)3 TextSegment (org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment)3 Matcher (java.util.regex.Matcher)2 HeadingAttributes (org.eclipse.mylyn.wikitext.parser.HeadingAttributes)2 ImmutableList (com.google.common.collect.ImmutableList)1 AutoLinkWithoutDemarcationSpan (org.eclipse.mylyn.wikitext.commonmark.internal.inlines.AutoLinkWithoutDemarcationSpan)1 SourceSpan (org.eclipse.mylyn.wikitext.commonmark.internal.inlines.SourceSpan)1 Test (org.junit.Test)1