Search in sources :

Example 21 with HtmlDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.

the class ConfluenceLanguageTest method testNote2.

@Test
public void testNote2() {
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.setUseInlineStyles(false);
    parser.setBuilder(builder);
    parser.parse("{note}this is a note {note}\n\n* one thing\n* two things");
    String html = out.toString();
    assertTrue(html.contains("<body><div class=\"note\"><p>this is a note </p></div><ul><li>one thing</li><li>two things</li></ul></body>"));
}
Also used : StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) Test(org.junit.Test) AbstractMarkupGenerationTest(org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)

Example 22 with HtmlDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.

the class MarkupToEclipseHelpMojo method processMarkup.

protected void processMarkup(File sourceFile, String relativePath, MarkupLanguage markupLanguage) {
    getLog().info(format("Processing markup file: {0}", sourceFile));
    String name = sourceFile.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File htmlOutputFile = computeHtmlFile(relativePath, name);
    if (!htmlOutputFile.exists() || htmlOutputFile.lastModified() < sourceFile.lastModified()) {
        String markupContent = readFully(sourceFile);
        if (!htmlOutputFile.getParentFile().exists()) {
            if (!htmlOutputFile.getParentFile().mkdirs()) {
                throw new BuildFailureException(format("Cannot create folder {0}", htmlOutputFile.getParentFile()));
            }
        }
        Writer writer = createWriter(htmlOutputFile);
        try {
            HtmlDocumentBuilder builder = createRootBuilder(writer, name, relativePath);
            SplittingStrategy splittingStrategy = createSplittingStrategy();
            SplittingOutlineParser outlineParser = createOutlineParser(markupLanguage, splittingStrategy);
            SplitOutlineItem rootTocItem = outlineParser.parse(markupContent);
            rootTocItem.setSplitTarget(htmlOutputFile.getName());
            SplittingHtmlDocumentBuilder splittingBuilder = createSplittingBuilder(builder, rootTocItem, htmlOutputFile, relativePath);
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(splittingBuilder);
            parser.parse(markupContent);
            createEclipseHelpToc(rootTocItem, sourceFile, relativePath, htmlOutputFile, name);
        } finally {
            close(writer, htmlOutputFile);
        }
    }
}
Also used : SplittingStrategy(org.eclipse.mylyn.wikitext.splitter.SplittingStrategy) NoSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy) SplittingOutlineParser(org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 23 with HtmlDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.

the class SubstitutionBlockStrategyTest method before.

@Before
public void before() {
    writer = new StringWriter();
    builder = new HtmlDocumentBuilder(writer);
    builder.setEmitAsDocument(false);
}
Also used : StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) Before(org.junit.Before)

Example 24 with HtmlDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.

the class HtmlLanguageTest method assertProcessContent.

protected void assertProcessContent(String expectedHtml, String sourceHtml, boolean asDocument, boolean parseCleansHtml) {
    Writer out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    HtmlLanguage language = new HtmlLanguage();
    language.setParseCleansHtml(parseCleansHtml);
    MarkupParser markupParser = new MarkupParser(language, builder);
    markupParser.parse(sourceHtml, asDocument);
    assertEquals(expectedHtml, out.toString());
}
Also used : StringWriter(java.io.StringWriter) HtmlLanguage(org.eclipse.mylyn.wikitext.html.HtmlLanguage) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) StringWriter(java.io.StringWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 25 with HtmlDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.

the class HtmlLanguageTest method newDocumentBuilder.

@Test
public void newDocumentBuilder() {
    Writer out = new StringWriter();
    DocumentBuilder builder = new HtmlLanguage().createDocumentBuilder(out);
    assertNotNull(builder);
    assertTrue(builder instanceof HtmlDocumentBuilder);
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) HtmlLanguage(org.eclipse.mylyn.wikitext.html.HtmlLanguage) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Aggregations

HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)58 StringWriter (java.io.StringWriter)46 Test (org.junit.Test)17 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)16 SplittingHtmlDocumentBuilder (org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder)10 AbstractMarkupGenerationTest (org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)10 File (java.io.File)8 Writer (java.io.Writer)7 StringReader (java.io.StringReader)6 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)6 SplitOutlineItem (org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem)6 OutputStreamWriter (java.io.OutputStreamWriter)5 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 TextileLanguage (org.eclipse.mylyn.wikitext.textile.TextileLanguage)4 PrintWriter (java.io.PrintWriter)3 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)3 DefaultSplittingStrategy (org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy)3 SplittingOutlineParser (org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser)3 Before (org.junit.Before)3