Search in sources :

Example 46 with Attributes

use of org.eclipse.mylyn.wikitext.parser.Attributes 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 47 with Attributes

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

the class HtmlDocumentBuilder2Test method testDefaultTargetForInternalLinks.

public void testDefaultTargetForInternalLinks() throws Exception {
    builder.setDefaultAbsoluteLinkTarget("_external");
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.link("foo", "test");
    builder.endBlock();
    builder.endDocument();
    String html = out.toString();
    assertTrue(html.contains("<a href=\"foo\">test</a>"));
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 48 with Attributes

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

the class HtmlDocumentBuilder2Test method testSuppressBuiltInlineStyles.

public void testSuppressBuiltInlineStyles() throws Exception {
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.setSuppressBuiltInStyles(true);
    builder.beginDocument();
    builder.beginBlock(BlockType.NOTE, new Attributes());
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("foo");
    builder.endBlock();
    builder.endBlock();
    builder.endDocument();
    String html = out.toString();
    assertTrue(html.contains("<body><div class=\"note\"><p>foo</p></div></body>"));
    assertTrue(!html.contains("<style type=\"text/css\">"));
}
Also used : StringWriter(java.io.StringWriter) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)

Example 49 with Attributes

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

the class HtmlDocumentBuilder2Test method testSuppressInlineStyles.

public void testSuppressInlineStyles() throws Exception {
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.setUseInlineStyles(false);
    builder.beginDocument();
    builder.beginBlock(BlockType.NOTE, new Attributes());
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("foo");
    builder.endBlock();
    builder.endBlock();
    builder.endDocument();
    String html = out.toString();
    assertTrue(html.contains("<body><div class=\"note\"><p>foo</p></div></body>"));
    assertTrue(html.contains("<style type=\"text/css\">"));
}
Also used : StringWriter(java.io.StringWriter) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)

Example 50 with Attributes

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

the class HtmlDocumentBuilder2Test method testDefaultTargetForExternalLinks.

public void testDefaultTargetForExternalLinks() throws Exception {
    builder.setDefaultAbsoluteLinkTarget("_external");
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.link("http://www.example.com", "test");
    builder.endBlock();
    builder.endDocument();
    String html = out.toString();
    assertTrue(html.contains("<a href=\"http://www.example.com\" target=\"_external\">test</a>"));
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Aggregations

Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)428 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)248 ImageAttributes (org.eclipse.mylyn.wikitext.parser.ImageAttributes)223 Test (org.junit.Test)176 Matcher (java.util.regex.Matcher)33 ListAttributes (org.eclipse.mylyn.wikitext.parser.ListAttributes)29 TableAttributes (org.eclipse.mylyn.wikitext.parser.TableAttributes)17 StringWriter (java.io.StringWriter)14 BlockType (org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType)12 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)10 Pattern (java.util.regex.Pattern)9 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)9 SpanStrategies (org.eclipse.mylyn.wikitext.html.internal.SpanStrategies)8 Block (org.eclipse.mylyn.wikitext.parser.markup.Block)8 SpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SpanStrategy)6 SubstitutionBlockStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionBlockStrategy)6 SubstitutionSpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionSpanStrategy)6 SubstitutionWithoutCssSpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionWithoutCssSpanStrategy)6 TableCellAttributes (org.eclipse.mylyn.wikitext.parser.TableCellAttributes)6 EventDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)6