Search in sources :

Example 6 with HtmlDocumentBuilder

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

the class HtmlDocumentBuilder2Test method testSuppressBuiltInlineStyles.

public void testSuppressBuiltInlineStyles() throws Exception {
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.setSuppressBuiltInStyles(true);
    builder.beginDocument();
    builder.beginBlock(BlockType.NOTE, new Attributes());
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("foo");
    builder.endBlock();
    builder.endBlock();
    builder.endDocument();
    String html = out.toString();
    assertTrue(html.contains("<body><div class=\"note\"><p>foo</p></div></body>"));
    assertTrue(!html.contains("<style type=\"text/css\">"));
}
Also used : StringWriter(java.io.StringWriter) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)

Example 7 with HtmlDocumentBuilder

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

the class HtmlDocumentBuilder2Test method testSuppressInlineStyles.

public void testSuppressInlineStyles() throws Exception {
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.setUseInlineStyles(false);
    builder.beginDocument();
    builder.beginBlock(BlockType.NOTE, new Attributes());
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("foo");
    builder.endBlock();
    builder.endBlock();
    builder.endDocument();
    String html = out.toString();
    assertTrue(html.contains("<body><div class=\"note\"><p>foo</p></div></body>"));
    assertTrue(html.contains("<style type=\"text/css\">"));
}
Also used : StringWriter(java.io.StringWriter) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)

Example 8 with HtmlDocumentBuilder

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

the class HtmlDocumentBuilder2Test method setUp.

@Override
public void setUp() {
    parser = new MarkupParser();
    parser.setMarkupLanguage(new TextileLanguage());
    out = new StringWriter();
    builder = new HtmlDocumentBuilder(out) {

        @Override
        protected void checkFileReadable(File file) {
            if (!fileToUrl.containsKey(file)) {
                super.checkFileReadable(file);
            }
        }

        @Override
        protected Reader getReader(File inputFile) throws FileNotFoundException {
            URL url = fileToUrl.get(inputFile);
            if (url != null) {
                try {
                    return new InputStreamReader(url.openStream());
                } catch (IOException e) {
                    throw new FileNotFoundException(String.format("%s (%s)", inputFile, url));
                }
            }
            return super.getReader(inputFile);
        }
    };
    parser.setBuilder(builder);
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) File(java.io.File) URL(java.net.URL) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 9 with HtmlDocumentBuilder

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

the class WikiToDocTask method markupToDoc.

private void markupToDoc(MarkupLanguage markupLanguage, Path path, String markupContent, Map<String, SplitOutlineItem> pathNameToOutline, Set<String> imageFilenames) throws BuildException {
    File htmlOutputFile = computeHtmlOutputFile(path);
    File pathDir = htmlOutputFile.getParentFile();
    if (!pathDir.exists()) {
        if (!pathDir.mkdirs()) {
            throw new BuildException(// $NON-NLS-1$
            MessageFormat.format(// $NON-NLS-1$
            Messages.getString("WikiToDocTask_cannot_create_dest_folder"), pathDir.getAbsolutePath()));
        }
    }
    Writer writer;
    try {
        // $NON-NLS-1$
        writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(htmlOutputFile)), "utf-8");
    } catch (Exception e) {
        throw new BuildException(// $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        Messages.getString("WikiToDocTask_cannot_create_output_file"), // $NON-NLS-1$
        htmlOutputFile, e.getMessage()), e);
    }
    try {
        HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer, formatOutput);
        for (Stylesheet stylesheet : stylesheets) {
            HtmlDocumentBuilder.Stylesheet builderStylesheet = createBuilderStylesheet(pathDir, stylesheet);
            builder.addCssStylesheet(builderStylesheet);
        }
        builder.setTitle(computeTitle(path));
        builder.setEmitDtd(emitDoctype);
        if (emitDoctype && htmlDoctype != null) {
            builder.setHtmlDtd(htmlDoctype);
        }
        builder.setUseInlineStyles(useInlineCssStyles);
        builder.setSuppressBuiltInStyles(suppressBuiltInCssStyles);
        builder.setLinkRel(linkRel);
        builder.setDefaultAbsoluteLinkTarget(defaultAbsoluteLinkTarget);
        builder.setPrependImagePrefix(prependImagePrefix);
        builder.setXhtmlStrict(xhtmlStrict);
        MarkupLanguage markupLanguageClone = markupLanguage.clone();
        if (markupLanguageClone instanceof MediaWikiLanguage) {
            MediaWikiLanguage mediaWikiLanguage = (MediaWikiLanguage) markupLanguageClone;
            mediaWikiLanguage.setPageMapping(new PathPageMapping(path, paths, pathNameToOutline));
            if (imageFilenames != null) {
                mediaWikiLanguage.setImageNames(imageFilenames);
            }
        }
        SplitOutlineItem item = pathNameToOutline.get(path.name);
        SplittingHtmlDocumentBuilder splittingBuilder = new SplittingHtmlDocumentBuilder();
        splittingBuilder.setRootBuilder(builder);
        splittingBuilder.setOutline(item);
        splittingBuilder.setRootFile(htmlOutputFile);
        splittingBuilder.setNavigationImages(navigationImages);
        splittingBuilder.setFormatting(formatOutput);
        splittingBuilder.setNavigationImagePath(computeNavigationImagePath(pathDir));
        MarkupParser parser = new MarkupParser();
        parser.setMarkupLanguage(markupLanguageClone);
        parser.setBuilder(splittingBuilder);
        parser.parse(markupContent);
    } finally {
        try {
            writer.close();
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(// $NON-NLS-1$
            Messages.getString("WikiToDocTask_cannot_write_output_file"), // $NON-NLS-1$
            htmlOutputFile, e.getMessage()), e);
        }
    }
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileOutputStream(java.io.FileOutputStream) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 10 with HtmlDocumentBuilder

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

the class HtmlDocumentBuilderIntegrationTest method setUp.

@Override
public void setUp() {
    parser = new MarkupParser();
    parser.setMarkupLanguage(new TextileLanguage());
    out = new StringWriter();
    builder = new HtmlDocumentBuilder(out);
    parser.setBuilder(builder);
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

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