Search in sources :

Example 21 with DocumentBuilder

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

the class HtmlLanguageBuilderTest method assertEmittedCharsEqual.

private void assertEmittedCharsEqual(boolean xhtmlStrict, String expected, String... chars) {
    StringWriter writer = new StringWriter();
    DocumentBuilder builder = newDocumentBuilder(writer, xhtmlStrict);
    builder.beginDocument();
    for (String characters : chars) {
        builder.characters(characters);
    }
    builder.endDocument();
    assertEquals(expected, writer.toString());
}
Also used : StringWriter(java.io.StringWriter) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder)

Example 22 with DocumentBuilder

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

the class HtmlLanguageBuilderTest method addSpanFont.

@Test
public void addSpanFont() {
    StringWriter writer = new StringWriter();
    HtmlLanguage language = builder.addSpanFont().add(BlockType.PARAGRAPH).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("test <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 23 with DocumentBuilder

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

the class HtmlLanguageBuilderTest method spanToStrongTransformation.

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

Example 24 with DocumentBuilder

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

the class InlineTest method create.

@Test
public void create() {
    Line line = new Line(3, 5, "text");
    Inline inline = new Inline(line, 8, 3) {

        @Override
        public void emit(DocumentBuilder builder) {
        }
    };
    assertSame(line, inline.getLine());
    assertEquals(8, inline.getOffset());
    assertEquals(3, inline.getLength());
    Locator locator = inline.getLocator();
    assertEquals(3, locator.getLineCharacterOffset());
    assertEquals(6, locator.getLineSegmentEndOffset());
    assertEquals(8, locator.getDocumentOffset());
    assertEquals(line.getOffset(), locator.getLineDocumentOffset());
    assertEquals(line.getText().length(), locator.getLineLength());
    assertEquals(line.getLineNumber() + 1, locator.getLineNumber());
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) Locator(org.eclipse.mylyn.wikitext.parser.Locator) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) Test(org.junit.Test)

Example 25 with DocumentBuilder

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

the class InlineTest method createContext.

@Test
public void createContext() {
    ProcessingContextBuilder builder = ProcessingContext.builder();
    new Inline(new Line(1, 2, "text"), 0, 1) {

        @Override
        public void emit(DocumentBuilder builder) {
        }
    }.createContext(builder);
    ProcessingContext context = builder.build();
    assertTrue(context.isEmpty());
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) ProcessingContext(org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContext) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) ProcessingContextBuilder(org.eclipse.mylyn.wikitext.commonmark.internal.ProcessingContextBuilder) 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