Search in sources :

Example 1 with Section

use of org.eclipse.ceylon.common.tools.help.Markdown.Section in project ceylon by eclipse.

the class DocBuilder method buildAdditionalSections.

private List<DescribedSection> buildAdditionalSections(ToolModel<?> model) {
    List<DescribedSection> additionalSections = new ArrayList<DescribedSection>();
    String sections = getSections(model);
    if (sections != null && !sections.isEmpty()) {
        Document doc = Markdown.markdown(sections);
        List<Section> markdownSections = Markdown.extractSections(doc);
        for (Markdown.Section sect : markdownSections) {
            DescribedSection ds = new DescribedSection();
            ds.setRole(Role.ADDITIONAL);
            Document sectionDoc = sect.getDoc();
            if (sect.getHeading() == null) {
                // TODO Warn that there were no section headings
                continue;
            } else {
                // Adjust the heading levels, so that the most prominent
                // heading is H2
                Markdown.adjustHeadings(sectionDoc, 2 - sect.getHeading().getLevel());
            }
            ds.setTitle(sect.getHeading());
            ds.setDescription(sectionDoc);
            additionalSections.add(ds);
        }
    }
    return additionalSections;
}
Also used : Section(org.eclipse.ceylon.common.tools.help.Markdown.Section) ArrayList(java.util.ArrayList) DescribedSection(org.eclipse.ceylon.common.tools.help.model.DescribedSection) Document(org.tautua.markdownpapers.ast.Document) OptionsSection(org.eclipse.ceylon.common.tools.help.model.OptionsSection) SynopsesSection(org.eclipse.ceylon.common.tools.help.model.SynopsesSection) Section(org.eclipse.ceylon.common.tools.help.Markdown.Section) DescribedSection(org.eclipse.ceylon.common.tools.help.model.DescribedSection) SummarySection(org.eclipse.ceylon.common.tools.help.model.SummarySection)

Example 2 with Section

use of org.eclipse.ceylon.common.tools.help.Markdown.Section in project ceylon by eclipse.

the class MarkdownTests method testSplit.

@Test
public void testSplit() {
    Document doc = Markdown.markdown("Some stuff\n" + "\n" + "# First `H1`\n" + "\n" + "A sentence\n" + "\n" + "## `H2` under first `H1`" + "\n" + "A sentence\n" + "\n" + "# Second `H1`\n" + "\n" + "A sentence\n" + "\n" + "## `H2` under second `H1`" + "\n" + "A sentence\n" + "\n");
    List<Section> sections = Markdown.extractSections(doc);
    Assert.assertEquals(3, sections.size());
    Section section = sections.get(0);
    Assert.assertNull(section.getHeading());
    Document sectionBody = section.getDoc();
    Assert.assertEquals("<p>Some stuff</p>", html(sectionBody).trim());
    section = sections.get(1);
    Assert.assertEquals("<h1> First <code>H1</code></h1>", html(section.getHeading()).trim());
    sectionBody = section.getDoc();
    Assert.assertEquals("" + "<p>A sentence</p>\n" + "\n" + "<h2> <code>H2</code> under first <code>H1</code></h2>\n" + "\n" + "<p>A sentence</p>", html(sectionBody).trim());
    section = sections.get(2);
    Assert.assertEquals("<h1> Second <code>H1</code></h1>", html(section.getHeading()).trim());
    sectionBody = section.getDoc();
    Assert.assertEquals("" + "<p>A sentence</p>\n" + "\n" + "<h2> <code>H2</code> under second <code>H1</code></h2>\n" + "\n" + "<p>A sentence</p>", html(sectionBody).trim());
}
Also used : Document(org.tautua.markdownpapers.ast.Document) Section(org.eclipse.ceylon.common.tools.help.Markdown.Section) Test(org.junit.Test)

Aggregations

Section (org.eclipse.ceylon.common.tools.help.Markdown.Section)2 Document (org.tautua.markdownpapers.ast.Document)2 ArrayList (java.util.ArrayList)1 DescribedSection (org.eclipse.ceylon.common.tools.help.model.DescribedSection)1 OptionsSection (org.eclipse.ceylon.common.tools.help.model.OptionsSection)1 SummarySection (org.eclipse.ceylon.common.tools.help.model.SummarySection)1 SynopsesSection (org.eclipse.ceylon.common.tools.help.model.SynopsesSection)1 Test (org.junit.Test)1