Search in sources :

Example 11 with DocumentBuilder

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

the class ConfluenceLanguageIntegrationTest method toMarkup.

private String toMarkup(String characterContent) {
    StringWriter writer = new StringWriter();
    DocumentBuilder builder = new ConfluenceLanguage().createDocumentBuilder(writer);
    builder.beginDocument();
    builder.characters(characterContent);
    builder.endDocument();
    return writer.toString().trim();
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) EventDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)

Example 12 with DocumentBuilder

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

the class ConfluenceLanguageIntegrationTest method assertHtmlToConfluenceColor.

private void assertHtmlToConfluenceColor(String color, String hex) {
    HtmlLanguage htmlLanguage = HtmlLanguage.builder().add(BlockType.PARAGRAPH).add(SpanType.SPAN).name("Test").create();
    MarkupParser parser = new MarkupParser(htmlLanguage);
    Writer confluenceOut = new StringWriter();
    DocumentBuilder confuenceBuilder = new ConfluenceLanguage().createDocumentBuilder(confluenceOut);
    parser.setBuilder(confuenceBuilder);
    parser.parse("<html><body><span style=\"color: " + color + "\"><del>this text here</del></span></body></html>", true);
    assertEquals("{color:" + hex + "}-this text here-{color}\n\n", confluenceOut.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) EventDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder) HtmlLanguage(org.eclipse.mylyn.wikitext.html.HtmlLanguage) StringWriter(java.io.StringWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 13 with DocumentBuilder

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

the class CommonMarkAsserts method parseToHtml.

private static String parseToHtml(MarkupLanguage markupLanguage, String input) {
    StringWriter out = new StringWriter();
    DocumentBuilder builder = createDocumentBuilder(out);
    MarkupParser parser = new MarkupParser(markupLanguage, builder);
    try {
        parser.parse(new StringReader(input));
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return out.toString();
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SimplifiedHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.commonmark.internal.spec.SimplifiedHtmlDocumentBuilder) StringReader(java.io.StringReader) IOException(java.io.IOException) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 14 with DocumentBuilder

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

the class HtmlToMarkupTask method processFile.

private void processFile(MarkupLanguage markupLanguage, File folder, File source) {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToHtmlTask.14"), source), Project.MSG_VERBOSE);
    if (isValidate()) {
        // $NON-NLS-1$
        log(MessageFormat.format(Messages.getString("HtmlToMarkupTask.1"), source), Project.MSG_WARN);
    }
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File outputFile = computeTargetFile(markupLanguage, source, name);
    if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
        Writer writer;
        try {
            // $NON-NLS-1$
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToHtmlTask.16"), outputFile, e.getMessage()), // $NON-NLS-1$
            e);
        }
        try {
            DocumentBuilder builder = markupLanguage.createDocumentBuilder(writer);
            Reader input;
            InputStream in;
            try {
                in = new BufferedInputStream(new FileInputStream(source));
                input = getSourceEncoding() == null ? new InputStreamReader(in) : new InputStreamReader(in, getSourceEncoding());
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(Messages.getString("MarkupTask.cannotReadSource"), source, e.getMessage()), // $NON-NLS-1$
                e);
            }
            try {
                new HtmlParser().parse(new InputSource(input), builder);
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(Messages.getString("HtmlToMarkupTask.failedToProcessContent"), source, e.getMessage()), // $NON-NLS-1$
                e);
            } finally {
                try {
                    in.close();
                } catch (Exception e) {
                    throw new BuildException(MessageFormat.format(Messages.getString("MarkupTask.cannotReadSource"), source, e.getMessage()), // $NON-NLS-1$
                    e);
                }
            }
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToHtmlTask.17"), // $NON-NLS-1$
                outputFile, e.getMessage()), e);
            }
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BuildException(org.apache.tools.ant.BuildException) FileInputStream(java.io.FileInputStream) HtmlParser(org.eclipse.mylyn.wikitext.parser.HtmlParser) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 15 with DocumentBuilder

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

the class TextileLanguage method processContent.

@Override
public void processContent(MarkupParser parser, String markupContent, boolean asDocument) {
    if (preprocessFootnotes) {
        boolean previousBlocksOnly = isBlocksOnly();
        boolean previousFilterGenerativeContents = isFilterGenerativeContents();
        setBlocksOnly(true);
        setFilterGenerativeContents(true);
        DocumentBuilder builder = parser.getBuilder();
        parser.setBuilder(new NoOpDocumentBuilder());
        currentState = new TextileContentState();
        TextileContentState preprocessingState = currentState;
        super.processContent(parser, markupContent, asDocument);
        setBlocksOnly(previousBlocksOnly);
        setFilterGenerativeContents(previousFilterGenerativeContents);
        currentState = new TextileContentState();
        currentState.setFootnoteNumbers(preprocessingState.getFootnoteNumbers());
        parser.setBuilder(builder);
        super.processContent(parser, markupContent, asDocument);
        currentState = null;
    } else {
        currentState = null;
        super.processContent(parser, markupContent, asDocument);
    }
}
Also used : NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) TextileDocumentBuilder(org.eclipse.mylyn.wikitext.textile.internal.TextileDocumentBuilder) TextileContentState(org.eclipse.mylyn.wikitext.textile.internal.TextileContentState)

Aggregations

DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)31 StringWriter (java.io.StringWriter)20 Test (org.junit.Test)15 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)9 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)9 EventDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)7 Writer (java.io.Writer)6 NoOpDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder)6 HtmlLanguage (org.eclipse.mylyn.wikitext.html.HtmlLanguage)5 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)3 Line (org.eclipse.mylyn.wikitext.commonmark.internal.Line)2 ProcessingContext (org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContext)2 SimplifiedHtmlDocumentBuilder (org.eclipse.mylyn.wikitext.commonmark.internal.spec.SimplifiedHtmlDocumentBuilder)2 Locator (org.eclipse.mylyn.wikitext.parser.Locator)2 MultiplexingDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.MultiplexingDocumentBuilder)2 InputSource (org.xml.sax.InputSource)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1