Search in sources :

Example 41 with HtmlDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder 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 42 with HtmlDocumentBuilder

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

the class HtmlParserTest method assertCanParseSomething.

protected void assertCanParseSomething(HtmlParser parser) throws IOException, SAXException {
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.setEmitAsDocument(false);
    parser.parse(new InputSource(new StringReader("<body><p>test</p></body>")), builder);
    String result = out.toString();
    Assert.assertEquals("<p>test</p>", result.trim());
}
Also used : InputSource(org.xml.sax.InputSource) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)

Example 43 with HtmlDocumentBuilder

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

the class FontElementStrategyTest method assertHtmlFromSpanWithCss.

void assertHtmlFromSpanWithCss(String expectedHtml, String spanCssStyle) {
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    SpanStrategy spanStrategy = strategy.spanStrategy();
    spanStrategy.beginSpan(builder, SpanType.SPAN, new Attributes(null, null, spanCssStyle, null));
    builder.characters("test");
    spanStrategy.endSpan(builder);
    assertEquals(expectedHtml, out.toString());
}
Also used : SpanStrategy(org.eclipse.mylyn.wikitext.html.internal.SpanStrategy) StringWriter(java.io.StringWriter) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)

Example 44 with HtmlDocumentBuilder

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

the class CommonMarkAsserts method createDocumentBuilder.

private static DocumentBuilder createDocumentBuilder(StringWriter out) {
    HtmlDocumentBuilder builder = new SimplifiedHtmlDocumentBuilder(out);
    builder.setDocumentHandler(new HtmlDocumentHandler() {

        @Override
        public void endDocument(HtmlDocumentBuilder builder, XmlStreamWriter writer) {
        }

        @Override
        public void beginDocument(HtmlDocumentBuilder builder, XmlStreamWriter writer) {
        }
    });
    return builder;
}
Also used : SimplifiedHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.commonmark.internal.spec.SimplifiedHtmlDocumentBuilder) HtmlDocumentHandler(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentHandler) XmlStreamWriter(org.eclipse.mylyn.wikitext.util.XmlStreamWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SimplifiedHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.commonmark.internal.spec.SimplifiedHtmlDocumentBuilder)

Example 45 with HtmlDocumentBuilder

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

the class CommonMarkLanguageDocumentOffsetsTest method assertSpanOffsets.

private void assertSpanOffsets(int offset, int length, String expectedHtml, String markup) {
    final AtomicReference<Locator> spanLocator = new AtomicReference<Locator>();
    CommonMarkLanguage language = new CommonMarkLanguage();
    MarkupParser parser = new MarkupParser(language);
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out) {

        @Override
        public void beginSpan(SpanType type, Attributes attributes) {
            assertNull(spanLocator.get());
            spanLocator.set(new LocatorImpl(getLocator()));
            super.beginSpan(type, attributes);
        }
    };
    builder.setEmitAsDocument(false);
    parser.setBuilder(builder);
    parser.parse(markup);
    assertEquals(expectedHtml, out.toString());
    Locator locator = spanLocator.get();
    assertNotNull(locator);
    assertEquals(offset, locator.getDocumentOffset());
    int actualLength = locator.getLineSegmentEndOffset() - locator.getLineCharacterOffset();
    assertEquals(length, actualLength);
}
Also used : Locator(org.eclipse.mylyn.wikitext.parser.Locator) StringWriter(java.io.StringWriter) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) AtomicReference(java.util.concurrent.atomic.AtomicReference) LocatorImpl(org.eclipse.mylyn.wikitext.util.LocatorImpl) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Aggregations

HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)58 StringWriter (java.io.StringWriter)46 Test (org.junit.Test)17 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)16 SplittingHtmlDocumentBuilder (org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder)10 AbstractMarkupGenerationTest (org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)10 File (java.io.File)8 Writer (java.io.Writer)7 StringReader (java.io.StringReader)6 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)6 SplitOutlineItem (org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem)6 OutputStreamWriter (java.io.OutputStreamWriter)5 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 TextileLanguage (org.eclipse.mylyn.wikitext.textile.TextileLanguage)4 PrintWriter (java.io.PrintWriter)3 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)3 DefaultSplittingStrategy (org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy)3 SplittingOutlineParser (org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser)3 Before (org.junit.Before)3