Search in sources :

Example 1 with HeadingAttributes

use of org.eclipse.mylyn.wikitext.parser.HeadingAttributes in project mylyn.docs by eclipse.

the class UnderlinedHeadingBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineCount == 0) {
        HeadingAttributes attributes = new HeadingAttributes();
        attributes.setId(state.getIdGenerator().newId(null, line));
        int level = LanguageSupport.computeHeadingLevel(lineLevel, getAsciiDocState());
        builder.beginHeading(level, attributes);
        builder.characters(line.trim());
    } else {
        builder.endHeading();
        setClosed(true);
    }
    blockLineCount++;
    return -1;
}
Also used : HeadingAttributes(org.eclipse.mylyn.wikitext.parser.HeadingAttributes)

Example 2 with HeadingAttributes

use of org.eclipse.mylyn.wikitext.parser.HeadingAttributes in project mylyn.docs by eclipse.

the class HeadingBlock method emitHeading.

private void emitHeading(int level) {
    String text = matcher.group(2);
    String closingGroup = matcher.group(4);
    HeadingAttributes attributes = new HeadingAttributes();
    if (level == 1) {
        attributes.setId("header");
    } else {
        attributes.setId(state.getIdGenerator().newId(null, text));
    }
    builder.beginHeading(level, attributes);
    getMarkupLanguage().emitMarkupLine(getParser(), state, matcher.start(2), text, 0);
    if (closingGroup.length() > 0 && closingGroup.length() != level) {
        builder.characters(matcher.group(3));
        builder.characters(closingGroup);
    }
    builder.endHeading();
}
Also used : HeadingAttributes(org.eclipse.mylyn.wikitext.parser.HeadingAttributes)

Example 3 with HeadingAttributes

use of org.eclipse.mylyn.wikitext.parser.HeadingAttributes 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 4 with HeadingAttributes

use of org.eclipse.mylyn.wikitext.parser.HeadingAttributes in project mylyn.docs by eclipse.

the class HeadingBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    offset = matcher.start(3);
    int level = matcher.group(1).length();
    String bangEscape = matcher.group(2);
    boolean omitFromToc = false;
    if (bangEscape != null && bangEscape.length() > 0) {
        omitFromToc = true;
    }
    if (offset > 0 && level > 0) {
        HeadingAttributes attributes = new HeadingAttributes();
        attributes.setOmitFromTableOfContents(omitFromToc);
        // $NON-NLS-1$
        attributes.setId(state.getIdGenerator().newId("h" + level, line.substring(offset)));
        builder.beginHeading(level, attributes);
        builder.characters(line.substring(offset).trim());
        builder.endHeading();
    }
    setClosed(true);
    return -1;
}
Also used : HeadingAttributes(org.eclipse.mylyn.wikitext.parser.HeadingAttributes)

Example 5 with HeadingAttributes

use of org.eclipse.mylyn.wikitext.parser.HeadingAttributes 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

HeadingAttributes (org.eclipse.mylyn.wikitext.parser.HeadingAttributes)7 Matcher (java.util.regex.Matcher)2 Line (org.eclipse.mylyn.wikitext.commonmark.internal.Line)2 TextSegment (org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment)2 InlineParser (org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser)2 BeginHeadingEvent (org.eclipse.mylyn.wikitext.parser.builder.event.BeginHeadingEvent)2 Test (org.junit.Test)2