Search in sources :

Example 6 with Line

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

the class SetextHeaderBlock method canStart.

@Override
public boolean canStart(LineSequence lineSequence) {
    Line line = lineSequence.getCurrentLine();
    Line nextLine = lineSequence.getNextLine();
    return line != null && nextLine != null && indentPattern.matcher(line.getText()).matches() && setextUnderlinePattern.matcher(nextLine.getText()).matches();
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line)

Example 7 with Line

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

the class IndentedCodeBlock method process.

@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
    builder.setLocator(lineSequence.getCurrentLine().toLocator());
    builder.beginBlock(BlockType.CODE, new Attributes());
    boolean blockHasContent = false;
    Iterator<Line> iterator = lineSequence.with(Predicates.or(LinePredicates.matches(PATTERN), LinePredicates.empty())).iterator();
    while (iterator.hasNext()) {
        Line line = iterator.next();
        Matcher matcher = PATTERN.matcher(line.getText());
        if (!matcher.matches()) {
            checkState(line.isEmpty());
            if (iterator.hasNext()) {
                builder.characters("\n");
            }
        } else {
            String content = matcher.group(1);
            if (!content.isEmpty() || (blockHasContent && iterator.hasNext())) {
                blockHasContent = true;
                builder.characters(content);
                builder.characters("\n");
            }
        }
    }
    builder.endBlock();
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) Matcher(java.util.regex.Matcher) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 8 with Line

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

the class HtmlEntitySpan method createInline.

@Override
public Optional<? extends Inline> createInline(Cursor cursor) {
    char c = cursor.getChar();
    if (c == '&') {
        Matcher matcher = cursor.matcher(pattern);
        if (matcher.matches()) {
            String ent = matcher.group(1);
            int offset = cursor.getOffset();
            int length = ent.length() + 2;
            Line lineAtOffset = cursor.getLineAtOffset();
            if (isInvalidUnicodeCodepoint(ent)) {
                return Optional.of(new Characters(lineAtOffset, offset, length, "\ufffd"));
            }
            return Optional.of(new HtmlEntity(lineAtOffset, offset, length, ent));
        }
    }
    return Optional.absent();
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) Matcher(java.util.regex.Matcher)

Example 9 with Line

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

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

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