Search in sources :

Example 21 with MarkupParser

use of org.eclipse.mylyn.wikitext.parser.MarkupParser 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 22 with MarkupParser

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

the class ConfluenceLanguageIntegrationTest method parseToEvents.

private DocumentBuilderEvents parseToEvents(String markup) {
    EventDocumentBuilder eventBuilder = new EventDocumentBuilder();
    MarkupParser parser = new MarkupParser(new ConfluenceLanguage(), eventBuilder);
    parser.parse(markup);
    DocumentBuilderEvents events = eventBuilder.getDocumentBuilderEvents();
    return events;
}
Also used : DocumentBuilderEvents(org.eclipse.mylyn.wikitext.parser.builder.event.DocumentBuilderEvents) EventDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 23 with MarkupParser

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

the class ConfluenceLanguageIntegrationTest method assertHtmlToConfluence.

private void assertHtmlToConfluence(boolean parseAsDocument) {
    HtmlLanguage htmlLanguage = HtmlLanguage.builder().add(BlockType.PARAGRAPH).add(SpanType.BOLD).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>some text <b>bold here</b> more text</body></html>", parseAsDocument);
    assertEquals("some text *bold here* more text\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 24 with MarkupParser

use of org.eclipse.mylyn.wikitext.parser.MarkupParser 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 25 with MarkupParser

use of org.eclipse.mylyn.wikitext.parser.MarkupParser 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)

Aggregations

MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)55 StringWriter (java.io.StringWriter)24 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)17 Writer (java.io.Writer)13 Test (org.junit.Test)10 File (java.io.File)8 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)8 TextileLanguage (org.eclipse.mylyn.wikitext.textile.TextileLanguage)8 OutputStreamWriter (java.io.OutputStreamWriter)7 FileOutputStream (java.io.FileOutputStream)6 BufferedOutputStream (java.io.BufferedOutputStream)5 IOException (java.io.IOException)5 BuildException (org.apache.tools.ant.BuildException)5 IFile (org.eclipse.core.resources.IFile)4 EventDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)4 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HtmlLanguage (org.eclipse.mylyn.wikitext.html.HtmlLanguage)3 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)3