Search in sources :

Example 1 with LineSequence

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

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

the class ListBlock method emitListItem.

private void emitListItem(ProcessingContext context, DocumentBuilder builder, ListMode listMode, LineSequence lineSequence) {
    List<SourceBlock> blocks = calculateListItemBlocks(context, lineSequence.lookAhead());
    if (blocks.isEmpty()) {
        lineSequence.advance();
        return;
    }
    LineSequence contentLineSequence = listItemLineSequence(lineSequence);
    if (!blocks.isEmpty() && blocks.get(0) instanceof EmptyBlock) {
        blocks.remove(0);
        while (contentLineSequence.getCurrentLine() != null && contentLineSequence.getCurrentLine().isEmpty()) {
            contentLineSequence.advance();
        }
    }
    for (SourceBlock block : blocks) {
        if (listMode == ListMode.TIGHT && block instanceof ParagraphBlock) {
            ParagraphBlock paragraphBlock = (ParagraphBlock) block;
            paragraphBlock.processInlines(context, builder, contentLineSequence, false);
        } else {
            block.process(context, builder, contentLineSequence);
        }
    }
}
Also used : SourceBlock(org.eclipse.mylyn.wikitext.commonmark.internal.SourceBlock) LineSequence(org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence)

Example 3 with LineSequence

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

the class EmptyBlockTest method process.

@Test
public void process() {
    LineSequence lineSequence = LineSequence.create("\n2");
    new EmptyBlock().process(ProcessingContext.builder().build(), null, lineSequence);
    assertEquals("2", lineSequence.getCurrentLine().getText());
}
Also used : LineSequence(org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence) Test(org.junit.Test)

Example 4 with LineSequence

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

the class EmptyBlockTest method assertCanStart.

private void assertCanStart(boolean expected, String lineContent) {
    EmptyBlock emptyBlock = new EmptyBlock();
    LineSequence lineSequence = LineSequence.create(lineContent);
    assertEquals(expected, emptyBlock.canStart(lineSequence));
}
Also used : LineSequence(org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence)

Example 5 with LineSequence

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

the class HtmlBlockTest method canStartDoesNotAdvanceLineSequencePosition.

@Test
public void canStartDoesNotAdvanceLineSequencePosition() {
    LineSequence lineSequence = LineSequence.create("<p\n  a=\"b\"\n>");
    Line firstLine = lineSequence.getCurrentLine();
    assertTrue(block.canStart(lineSequence));
    assertSame(firstLine, lineSequence.getCurrentLine());
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) LineSequence(org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence) Test(org.junit.Test)

Aggregations

LineSequence (org.eclipse.mylyn.wikitext.commonmark.internal.LineSequence)5 Line (org.eclipse.mylyn.wikitext.commonmark.internal.Line)2 Test (org.junit.Test)2 SourceBlock (org.eclipse.mylyn.wikitext.commonmark.internal.SourceBlock)1