Search in sources :

Example 16 with DocumentBuilder

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

the class SourceBlocksTest method mockBlock.

private SourceBlock mockBlock(final BlockType blockType, final String startString) {
    return new SourceBlock() {

        @Override
        public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
            builder.beginBlock(blockType, new Attributes());
            for (Line line : lineSequence.with(not(LinePredicates.empty()))) {
                builder.characters(line.getText());
            }
            builder.endBlock();
        }

        @Override
        public boolean canStart(LineSequence lineSequence) {
            return lineSequence.getCurrentLine() != null && lineSequence.getCurrentLine().getText().startsWith(startString);
        }
    };
}
Also used : DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) EventDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 17 with DocumentBuilder

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

the class HtmlLanguageTest method newDocumentBuilderIsFormatting.

@Test
public void newDocumentBuilderIsFormatting() {
    Writer out = new StringWriter();
    DocumentBuilder builder = new HtmlLanguage().createDocumentBuilder(out, true);
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("test");
    builder.endBlock();
    builder.endDocument();
    assertEquals(loadResourceContent("newDocumentBuilderIsFormatting.xml"), out.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) HtmlLanguage(org.eclipse.mylyn.wikitext.html.HtmlLanguage) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 18 with DocumentBuilder

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

the class HtmlLanguageTest method newDocumentBuilderIsNotFormatting.

@Test
public void newDocumentBuilderIsNotFormatting() {
    Writer out = new StringWriter();
    DocumentBuilder builder = new HtmlLanguage().createDocumentBuilder(out, false);
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("test");
    builder.endBlock();
    builder.endDocument();
    assertEquals(loadResourceContent("newDocumentBuilderIsNotFormatting.xml"), out.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) HtmlLanguage(org.eclipse.mylyn.wikitext.html.HtmlLanguage) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 19 with DocumentBuilder

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

the class HtmlParserTest method assertParse.

private void assertParse(String expected, String content) {
    StringWriter out = new StringWriter();
    DocumentBuilder builder = new HtmlDocumentBuilder(out);
    parse(content, builder);
    assertEquals(expected, out.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)

Example 20 with DocumentBuilder

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

the class HtmlLanguageBuilderTest method spanToBoldTransformation.

@Test
public void spanToBoldTransformation() {
    StringWriter writer = new StringWriter();
    HtmlLanguage language = builder.add(BlockType.PARAGRAPH).add(SpanType.BOLD).document("", "").name("Test").create();
    DocumentBuilder builder = language.createDocumentBuilder(writer);
    builder.beginDocument();
    addSpanWithCssFontWeightBold(builder);
    builder.characters(" ");
    addSpanWithCssColor(builder);
    builder.endDocument();
    assertEquals("<b>test</b> inside font", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) Test(org.junit.Test)

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