Search in sources :

Example 1 with DocumentBuilder

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

the class HtmlParserTest method assertParseEventOrder.

private void assertParseEventOrder(String content, Object... expectedEventTypes) {
    final List<Object> actualEventTypes = new ArrayList<>();
    DocumentBuilder builder = new NoOpDocumentBuilder() {

        @Override
        public void beginBlock(BlockType type, Attributes attributes) {
            actualEventTypes.add(type);
        }

        @Override
        public void beginSpan(SpanType type, Attributes attributes) {
            actualEventTypes.add(type);
        }

        @Override
        public void characters(String text) {
            actualEventTypes.add(text);
        }

        @Override
        public void endBlock() {
            actualEventTypes.add(END_BLOCK);
        }

        @Override
        public void endSpan() {
            actualEventTypes.add(END_SPAN);
        }
    };
    parse(content, builder);
    assertEquals(ImmutableList.copyOf(expectedEventTypes), actualEventTypes);
}
Also used : NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) SpanType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.SpanType) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) ArrayList(java.util.ArrayList) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 2 with DocumentBuilder

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

the class CommonMarkLanguage method processContent.

@Override
public void processContent(MarkupParser parser, String markupContent, boolean asDocument) {
    checkNotNull(parser);
    checkNotNull(markupContent);
    DocumentBuilder builder = checkNotNull(parser.getBuilder());
    if (asDocument) {
        builder.beginDocument();
    }
    SourceBlocks sourceBlocks = CommonMark.sourceBlocks();
    ProcessingContext context = createContext(sourceBlocks, markupContent);
    sourceBlocks.process(context, builder, LineSequence.create(markupContent));
    if (asDocument) {
        builder.endDocument();
    }
}
Also used : ProcessingContext(org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContext) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) SourceBlocks(org.eclipse.mylyn.wikitext.commonmark.internal.SourceBlocks)

Example 3 with DocumentBuilder

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

the class MarkdownRoundTripTest method emitAsMarkdown.

private String emitAsMarkdown(String characters) {
    StringWriter markupWriter = new StringWriter();
    DocumentBuilder documentBuilder = language.createDocumentBuilder(markupWriter);
    documentBuilder.characters(characters);
    documentBuilder.flush();
    return markupWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder)

Example 4 with DocumentBuilder

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

the class HtmlLanguageTest method newDocumentBuilder.

@Test
public void newDocumentBuilder() {
    Writer out = new StringWriter();
    DocumentBuilder builder = new HtmlLanguage().createDocumentBuilder(out);
    assertNotNull(builder);
    assertTrue(builder instanceof HtmlDocumentBuilder);
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) HtmlLanguage(org.eclipse.mylyn.wikitext.html.HtmlLanguage) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 5 with DocumentBuilder

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

the class HtmlLanguageBuilderTest method document.

@Test
public void document() {
    HtmlSubsetLanguage subsetLanguage = (HtmlSubsetLanguage) builder.add(BlockType.PARAGRAPH).document("<div>", "</div>").name("Test").create();
    StringWriter writer = new StringWriter();
    DocumentBuilder documentBuilder = subsetLanguage.createDocumentBuilder(writer);
    documentBuilder.beginDocument();
    documentBuilder.characters("test");
    documentBuilder.endDocument();
    assertEquals("<div>test</div>", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) HtmlSubsetLanguage(org.eclipse.mylyn.wikitext.html.internal.HtmlSubsetLanguage) 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