Search in sources :

Example 1 with Heading

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

the class Navbar method extractSiteTitle.

private void extractSiteTitle() {
    for (Node c = node.getFirstChild(); c != null; c = c.getNext()) {
        if (c instanceof Heading) {
            Heading h = (Heading) c;
            if (h.getLevel() == 1) {
                siteTitle = MarkdownUtil.getInnerText(h);
                h.unlink();
                break;
            }
        }
    }
}
Also used : Heading(org.commonmark.node.Heading) Node(org.commonmark.node.Node)

Example 2 with Heading

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

the class TocFormatter method format.

void format() {
    int startLevel = countH1 > 1 ? 1 : 2;
    level = startLevel;
    html.open("div").attribute("class", "toc").attribute("role", "navigation").open("h2").appendAndEscape("Contents").close("h2").open("div").attribute("class", "toc-aux").open("ul");
    for (Heading header : outline) {
        outline(header);
    }
    while (level >= startLevel) {
        html.close("ul");
        level--;
    }
    html.close("div").close("div");
}
Also used : Heading(org.commonmark.node.Heading)

Example 3 with Heading

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

the class TocFormatter method generateIds.

private Map<Heading, String> generateIds(ListMultimap<String, TocEntry> entries) {
    ListMultimap<String, TocEntry> tmp = MultimapBuilder.hashKeys(entries.size()).arrayListValues(2).build();
    for (Collection<TocEntry> headers : entries.asMap().values()) {
        if (headers.size() == 1) {
            TocEntry entry = Iterables.getOnlyElement(headers);
            tmp.put(entry.id, entry);
            continue;
        }
        // Try to deduplicate by prefixing with text derived from parents.
        for (TocEntry entry : headers) {
            if (!entry.generated) {
                tmp.put(entry.id, entry);
                continue;
            }
            StringBuilder b = new StringBuilder();
            for (Heading p : entry.path) {
                if (p.getLevel() > 1 || countH1 > 1) {
                    String text = MarkdownUtil.getInnerText(p);
                    if (text != null) {
                        b.append(idFromTitle(text)).append('-');
                    }
                }
            }
            b.append(idFromTitle(MarkdownUtil.getInnerText(entry.header)));
            entry.id = b.toString();
            tmp.put(entry.id, entry);
        }
    }
    Map<Heading, String> ids = Maps.newHashMapWithExpectedSize(tmp.size());
    for (Collection<TocEntry> headers : tmp.asMap().values()) {
        if (headers.size() == 1) {
            TocEntry entry = Iterables.getOnlyElement(headers);
            ids.put(entry.header, entry.id);
        } else {
            int i = 1;
            for (TocEntry entry : headers) {
                ids.put(entry.header, entry.id + "-" + (i++));
            }
        }
    }
    return ids;
}
Also used : Heading(org.commonmark.node.Heading)

Aggregations

Heading (org.commonmark.node.Heading)3 Node (org.commonmark.node.Node)1