Search in sources :

Example 6 with DocumentBuilder

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

the class HtmlLanguageBuilderTest method addSpanFontWithSpanSupport.

@Test
public void addSpanFontWithSpanSupport() {
    StringWriter writer = new StringWriter();
    HtmlLanguage language = builder.addSpanFont().add(BlockType.PARAGRAPH).add(SpanType.SPAN).document("", "").name("Test").create();
    DocumentBuilder builder = language.createDocumentBuilder(writer);
    builder.beginDocument();
    builder.beginSpan(SpanType.SPAN, new Attributes());
    builder.characters("test");
    builder.endSpan();
    builder.characters(" ");
    addSpanWithCssColor(builder);
    builder.endDocument();
    assertEquals("<span>test</span> <font color=\"purple\">inside font</font>", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) Test(org.junit.Test)

Example 7 with DocumentBuilder

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

the class HtmlLanguageBuilderTest method spanSubstitution.

@Test
public void spanSubstitution() {
    StringWriter writer = new StringWriter();
    HtmlLanguage language = builder.addSpanFont().add(SpanType.DELETED).addSubstitution(SpanType.DELETED, "strike").document("", "").name("Test").create();
    DocumentBuilder builder = language.createDocumentBuilder(writer);
    builder.beginDocument();
    builder.beginSpan(SpanType.DELETED, new Attributes());
    builder.characters("test");
    builder.endSpan();
    assertEquals("<strike>test</strike>", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) Test(org.junit.Test)

Example 8 with DocumentBuilder

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

the class HtmlLanguageBuilderTest method spanToCompositeTransformation.

@Test
public void spanToCompositeTransformation() {
    StringWriter writer = new StringWriter();
    HtmlLanguage language = builder.add(BlockType.PARAGRAPH).add(SpanType.BOLD).add(SpanType.MONOSPACE).add(SpanType.EMPHASIS).document("", "").name("Test").create();
    DocumentBuilder builder = language.createDocumentBuilder(writer);
    builder.beginDocument();
    builder.beginSpan(SpanType.SPAN, new Attributes(null, null, "font-weight:bold; font-family: courrier, monospace;font-style:italic;unknown: rule", null));
    builder.characters("test");
    builder.endSpan();
    builder.endDocument();
    assertEquals("<b><tt><em>test</em></tt></b>", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) Test(org.junit.Test)

Example 9 with DocumentBuilder

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

the class FontElementStrategyTest method spanStrategyNestedSpansBuildsCorrectHtml.

@Test
public void spanStrategyNestedSpansBuildsCorrectHtml() {
    StringWriter out = new StringWriter();
    DocumentBuilder builder = HtmlLanguage.builder().add(BlockType.PARAGRAPH).addSpanFont().name("Test").create().createDocumentBuilder(out);
    builder.beginSpan(SpanType.SPAN, new Attributes(null, null, "color:blue;", null));
    builder.beginSpan(SpanType.SPAN, new Attributes(null, null, "", null));
    builder.beginSpan(SpanType.SPAN, new Attributes(null, null, "font-size: 15px", null));
    builder.characters("test");
    builder.endSpan();
    builder.endSpan();
    builder.endSpan();
    assertEquals("<font color=\"blue\"><font size=\"15px\">test</font></font>", out.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) EventDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) Test(org.junit.Test)

Example 10 with DocumentBuilder

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

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