org.commonmark.node.Paragraph Java Examples

The following examples show how to use org.commonmark.node.Paragraph. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HtmlBlockParser.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
@Override
public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) {
    int nextNonSpace = state.getNextNonSpaceIndex();
    CharSequence line = state.getLine();

    if (state.getIndent() < 4 && line.charAt(nextNonSpace) == '<') {
        for (int blockType = 1; blockType <= 7; blockType++) {
            // Type 7 can not interrupt a paragraph
            if (blockType == 7 && matchedBlockParser.getMatchedBlockParser().getBlock() instanceof Paragraph) {
                continue;
            }
            Pattern opener = BLOCK_PATTERNS[blockType][0];
            Pattern closer = BLOCK_PATTERNS[blockType][1];
            boolean matches = opener.matcher(line.subSequence(nextNonSpace, line.length())).find();
            if (matches) {
                return BlockStart.of(new HtmlBlockParser(closer)).atIndex(state.getIndex());
            }
        }
    }
    return BlockStart.none();
}
 
Example #2
Source File: ListItemParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public BlockContinue tryContinue(ParserState state) {
    if (state.isBlank()) {
        if (block.getFirstChild() == null) {
            // Blank line after empty list item
            return BlockContinue.none();
        } else {
            Block activeBlock = state.getActiveBlockParser().getBlock();
            // If the active block is a code block, blank lines in it should not affect if the list is tight.
            hadBlankLine = activeBlock instanceof Paragraph || activeBlock instanceof ListItem;
            return BlockContinue.atIndex(state.getNextNonSpaceIndex());
        }
    }

    if (state.getIndent() >= contentIndent) {
        return BlockContinue.atColumn(state.getColumn() + contentIndent);
    } else {
        return BlockContinue.none();
    }
}
 
Example #3
Source File: HtmlBlockParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) {
    int nextNonSpace = state.getNextNonSpaceIndex();
    CharSequence line = state.getLine();

    if (state.getIndent() < 4 && line.charAt(nextNonSpace) == '<') {
        for (int blockType = 1; blockType <= 7; blockType++) {
            // Type 7 can not interrupt a paragraph
            if (blockType == 7 && matchedBlockParser.getMatchedBlockParser().getBlock() instanceof Paragraph) {
                continue;
            }
            Pattern opener = BLOCK_PATTERNS[blockType][0];
            Pattern closer = BLOCK_PATTERNS[blockType][1];
            boolean matches = opener.matcher(line.subSequence(nextNonSpace, line.length())).find();
            if (matches) {
                return BlockStart.of(new HtmlBlockParser(closer)).atIndex(state.getIndex());
            }
        }
    }
    return BlockStart.none();
}
 
Example #4
Source File: CompactHtmlRenderer.java    From Kandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(Paragraph node) {
    // Replace paragraphs with line breaks to get a compact view.
    if (node.getNext() == null) {
        html.line();
        visitChildren(node);
        html.line();
    } else {
        super.visit(node);
    }
}
 
Example #5
Source File: DashProjectsAdapter.java    From Kandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(Paragraph node) {
    // Replace paragraphs with line breaks to get a compact view.
    html.line();
    visitChildren(node);
    if (node.getNext() != null) {
        html.tag("br /");
        html.line();
    }
}
 
Example #6
Source File: CorePlugin.java    From Markwon with Apache License 2.0 5 votes vote down vote up
private static boolean isInTightList(@NonNull Paragraph paragraph) {
    final Node parent = paragraph.getParent();
    if (parent != null) {
        final Node gramps = parent.getParent();
        if (gramps instanceof ListBlock) {
            ListBlock list = (ListBlock) gramps;
            return list.isTight();
        }
    }
    return false;
}
 
Example #7
Source File: MarkwonSpansFactoryImplTest.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@Test
public void builder() {
    // all passed to builder will be in factory

    final SpanFactory text = mock(SpanFactory.class);
    final SpanFactory link = mock(SpanFactory.class);

    final MarkwonSpansFactory factory = new MarkwonSpansFactoryImpl.BuilderImpl()
            .setFactory(Text.class, text)
            .setFactory(Link.class, link)
            .build();

    assertNotNull(factory.get(Text.class));

    assertNotNull(factory.get(Link.class));

    // a bunch of non-present factories
    //noinspection unchecked
    final Class<? extends Node>[] types = new Class[]{
            Image.class,
            Block.class,
            Emphasis.class,
            Paragraph.class
    };

    for (Class<? extends Node> type : types) {
        assertNull(factory.get(type));
    }
}
 
Example #8
Source File: CompactHtmlRenderer.java    From Kandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(Paragraph node) {
    // Replace paragraphs with line breaks to get a compact view.
    if (node.getNext() == null) {
        html.line();
        visitChildren(node);
        html.line();
    } else {
        super.visit(node);
    }
}
 
Example #9
Source File: DashProjectsAdapter.java    From Kandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(Paragraph node) {
    // Replace paragraphs with line breaks to get a compact view.
    html.line();
    visitChildren(node);
    if (node.getNext() != null) {
        html.tag("br /");
        html.line();
    }
}
 
Example #10
Source File: MarkDownParser.java    From blog-app-android with MIT License 5 votes vote down vote up
@Override public void visit(Paragraph paragraph) {
  super.visit(paragraph);

  final Block parent = paragraph.getParent();
  if (parent instanceof Document) {
    if (parent.getFirstChild() == paragraph && parent.getLastChild() == paragraph) {
      while (paragraph.getFirstChild() != null) {
        paragraph.insertBefore(paragraph.getFirstChild());
      }
      paragraph.unlink();
    }
  }
}
 
Example #11
Source File: IndentedCodeBlockParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) {
    // An indented code block cannot interrupt a paragraph.
    if (state.getIndent() >= Parsing.CODE_BLOCK_INDENT && !state.isBlank() && !(state.getActiveBlockParser().getBlock() instanceof Paragraph)) {
        return BlockStart.of(new IndentedCodeBlockParser()).atColumn(state.getColumn() + Parsing.CODE_BLOCK_INDENT);
    } else {
        return BlockStart.none();
    }
}
 
Example #12
Source File: MarkwonVisitorImpl.java    From Markwon with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(Paragraph paragraph) {
    visit((Node) paragraph);
}