Search in sources :

Example 1 with Line

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

the class FencedCodeBlock method process.

@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
    Matcher matcher = openingFencePattern.matcher(lineSequence.getCurrentLine().getText());
    checkState(matcher.matches());
    String indent = matcher.group(1);
    boolean indentedCodeBlock = indent != null && indent.length() == 4;
    Pattern closingFencePattern = closingFencePattern(matcher);
    Attributes codeAttributes = new Attributes();
    addInfoTextCssClass(context, codeAttributes, matcher);
    builder.setLocator(lineSequence.getCurrentLine().toLocator());
    builder.beginBlock(BlockType.CODE, codeAttributes);
    if (indentedCodeBlock) {
        outputLine(builder, indent, lineSequence.getCurrentLine());
    }
    lineSequence.advance();
    for (Line line : lineSequence.with(Predicates.not(LinePredicates.matches(closingFencePattern)))) {
        outputLine(builder, indent, line);
    }
    if (indentedCodeBlock && lineSequence.getCurrentLine() != null) {
        outputLine(builder, indent, lineSequence.getCurrentLine());
    }
    lineSequence.advance();
    builder.endBlock();
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 2 with Line

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

the class HtmlBlock method process.

@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
    for (Line line = lineSequence.getCurrentLine(); line != null && !line.isEmpty(); lineSequence.advance(), line = lineSequence.getCurrentLine()) {
        builder.charactersUnescaped(line.getText());
        builder.charactersUnescaped("\n");
    }
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line)

Example 3 with Line

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

the class HtmlCommentBlock method canStart.

@Override
public boolean canStart(LineSequence lineSequence) {
    Line line = lineSequence.getCurrentLine();
    if (line != null) {
        String text = line.getText();
        Matcher matcher = startPattern().matcher(text);
        if (matcher.matches()) {
            int end = matcher.end(1);
            if (end < text.length() - 1) {
                Matcher doubleHyphenMatcher = doubleHyphen.matcher(text);
                doubleHyphenMatcher.region(end, text.length());
                if (doubleHyphenMatcher.find()) {
                    return false;
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) Matcher(java.util.regex.Matcher)

Example 4 with Line

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

the class ListBlock method listItemLineSequence.

private LineSequence listItemLineSequence(LineSequence lineSequence) {
    final int indentOffset = calculateLineItemIndent(lineSequence.getCurrentLine());
    LineSequence itemLinesSequence = lineSequence.with(new Predicate<Line>() {

        int firstLineNumber = -1;

        @Override
        public boolean apply(Line line) {
            if (firstLineNumber == -1) {
                firstLineNumber = line.getLineNumber();
            }
            return firstLineNumber == line.getLineNumber() || line.isEmpty() || isIndented(line, indentOffset);
        }
    });
    return itemLinesSequence.transform(new Function<Line, Line>() {

        @Override
        public Line apply(Line line) {
            if (line.isEmpty()) {
                return line;
            }
            int length = Math.max(line.getText().length() - indentOffset, 0);
            int offset = Math.min(indentOffset, line.getText().length());
            return line.segment(offset, length);
        }
    });
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) LineSequence(org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence)

Example 5 with Line

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

Aggregations

Line (org.eclipse.mylyn.wikitext.commonmark.internal.Line)19 Matcher (java.util.regex.Matcher)7 TextSegment (org.eclipse.mylyn.wikitext.commonmark.internal.TextSegment)7 Test (org.junit.Test)5 InlineParser (org.eclipse.mylyn.wikitext.commonmark.internal.inlines.InlineParser)3 LineSequence (org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence)2 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)2 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)2 HeadingAttributes (org.eclipse.mylyn.wikitext.parser.HeadingAttributes)2 StringWriter (java.io.StringWriter)1 Pattern (java.util.regex.Pattern)1 ProcessingContext (org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContext)1 ProcessingContextBuilder (org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContextBuilder)1 SimplifiedHtmlDocumentBuilder (org.eclipse.mylyn.wikitext.commonmark.internal.spec.SimplifiedHtmlDocumentBuilder)1 Locator (org.eclipse.mylyn.wikitext.parser.Locator)1 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)1