Search in sources :

Example 1 with HardLineBreak

use of org.commonmark.node.HardLineBreak in project gitiles by GerritCodeReview.

the class GitilesHtmlExtension method inline.

private static void inline(HtmlInline curr) {
    String html = curr.getLiteral();
    Matcher m = BREAK.matcher(html);
    if (m.matches()) {
        switch(m.group(1).toLowerCase()) {
            case "br":
                curr.insertAfter(new HardLineBreak());
                curr.unlink();
                return;
            case "hr":
                curr.insertAfter(new ThematicBreak());
                curr.unlink();
                return;
        }
    }
    m = ANCHOR_OPEN.matcher(html);
    if (m.matches()) {
        String name = m.group(2);
        Node next = curr.getNext();
        // HtmlInline{<a name="id">}HtmlInline{</a>}
        if (isAnchorClose(next)) {
            next.unlink();
            NamedAnchor anchor = new NamedAnchor();
            anchor.setName(name);
            curr.insertAfter(anchor);
            curr.unlink();
            MarkdownUtil.trimPreviousWhitespace(anchor);
            return;
        }
    }
}
Also used : ThematicBreak(org.commonmark.node.ThematicBreak) Matcher(java.util.regex.Matcher) Node(org.commonmark.node.Node) HardLineBreak(org.commonmark.node.HardLineBreak)

Aggregations

Matcher (java.util.regex.Matcher)1 HardLineBreak (org.commonmark.node.HardLineBreak)1 Node (org.commonmark.node.Node)1 ThematicBreak (org.commonmark.node.ThematicBreak)1