Search in sources :

Example 51 with HtmlDocumentBuilder

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

the class AbstractSaxParserTest method performTest.

protected void performTest(String html, String expectedResult) throws IOException, SAXException {
    parser.parse(sourceForHtml(html), builder, true);
    String generatedMarkup = out.toString();
    assertEquals(expectedResult, generatedMarkup);
    MarkupParser markupParser = new MarkupParser(new TextileLanguage());
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder htmlBuilder = new HtmlDocumentBuilder(out);
    htmlBuilder.setEmitAsDocument(false);
    markupParser.setBuilder(htmlBuilder);
    markupParser.parse(generatedMarkup);
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 52 with HtmlDocumentBuilder

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

the class HtmlDocumentBuilder2Test method testLinkRel.

public void testLinkRel() throws Exception {
    // link-specific rel
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    LinkAttributes attributes = new LinkAttributes();
    attributes.setRel("nofollow");
    builder.link(attributes, "http://www.foo.bar", "Foo Bar");
    builder.endBlock();
    builder.endDocument();
    String html = out.toString();
    assertTrue(html.contains("<a href=\"http://www.foo.bar\" rel=\"nofollow\">Foo Bar</a>"));
    // default link rel
    out = new StringWriter();
    builder = new HtmlDocumentBuilder(out);
    builder.setLinkRel("nofollow");
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    attributes = new LinkAttributes();
    builder.link(attributes, "http://www.foo.bar", "Foo Bar");
    builder.endBlock();
    builder.endDocument();
    html = out.toString();
    assertTrue(html.contains("<a href=\"http://www.foo.bar\" rel=\"nofollow\">Foo Bar</a>"));
    // both link-specific and default link ref
    out = new StringWriter();
    builder = new HtmlDocumentBuilder(out);
    builder.setLinkRel("nofollow");
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    attributes = new LinkAttributes();
    attributes.setRel("foobar");
    builder.link(attributes, "http://www.foo.bar", "Foo Bar");
    builder.endBlock();
    builder.endDocument();
    html = out.toString();
    assertTrue(html.contains("<a href=\"http://www.foo.bar\" rel=\"foobar nofollow\">Foo Bar</a>"));
    // no rel at all
    out = new StringWriter();
    builder = new HtmlDocumentBuilder(out);
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    attributes = new LinkAttributes();
    builder.link(attributes, "http://www.foo.bar", "Foo Bar");
    builder.endBlock();
    builder.endDocument();
    html = out.toString();
    assertTrue(html.contains("<a href=\"http://www.foo.bar\">Foo Bar</a>"));
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) 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 53 with HtmlDocumentBuilder

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

the class MarkupToEclipseHelpMojoTest method createBuilder.

@Test
public void createBuilder() {
    markupToEclipseHelp.copyrightNotice = UUID.randomUUID().toString();
    markupToEclipseHelp.title = UUID.randomUUID().toString();
    markupToEclipseHelp.htmlFilenameFormat = "$1.test.html";
    HtmlDocumentBuilder builder = markupToEclipseHelp.createRootBuilder(new StringWriter(), "test", "");
    assertEquals(markupToEclipseHelp.copyrightNotice, builder.getCopyrightNotice());
    assertEquals(markupToEclipseHelp.title, builder.getTitle());
    assertEquals(markupToEclipseHelp.htmlFilenameFormat, builder.getHtmlFilenameFormat());
}
Also used : StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) Test(org.junit.Test)

Example 54 with HtmlDocumentBuilder

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

the class MarkupToEclipseHelpMojoTest method configureStylesheetUrlsWithRelativePath.

@Test
public void configureStylesheetUrlsWithRelativePath() {
    markupToEclipseHelp.stylesheetUrls = Arrays.asList("bar.css");
    HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
    markupToEclipseHelp.configureStylesheets(builder, "one/two");
    ArgumentCaptor<Stylesheet> captor = ArgumentCaptor.forClass(Stylesheet.class);
    verify(builder).addCssStylesheet(captor.capture());
    assertEquals("../../bar.css", captor.getValue().getUrl());
}
Also used : HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) Stylesheet(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder.Stylesheet) Test(org.junit.Test)

Example 55 with HtmlDocumentBuilder

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

the class MarkupToEclipseHelpMojoTest method configureStylesheetUrls.

@Test
public void configureStylesheetUrls() {
    markupToEclipseHelp.stylesheetUrls = Arrays.asList("test/foo.css", "bar.css");
    HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
    markupToEclipseHelp.configureStylesheets(builder, "");
    verify(builder, times(2)).addCssStylesheet(any(Stylesheet.class));
}
Also used : HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) Stylesheet(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder.Stylesheet) Test(org.junit.Test)

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