Search in sources :

Example 56 with HtmlDocumentBuilder

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

the class TextileLanguageTest method testBug50XHTMLCompliance.

@Test
public void testBug50XHTMLCompliance() throws Exception {
    StringWriter writer = new StringWriter();
    MarkupParser parser = new MarkupParser(new TextileLanguage());
    final HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer);
    builder.setXhtmlStrict(true);
    builder.setEmitDtd(true);
    builder.setHtmlDtd("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
    parser.setBuilder(builder);
    parser.parse("!<image.png!:http://foo.bar");
    String html = writer.toString();
    assertTrue(html.contains("<a href=\"http://foo.bar\"><img style=\"border-width: 0px;text-align: left;\" alt=\"\" src=\"image.png\"/></a>"));
}
Also used : StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser) Test(org.junit.Test) AbstractMarkupGenerationTest(org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)

Example 57 with HtmlDocumentBuilder

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

the class TextileLanguageTest method testBlockCodeWithTabsFormatted.

/**
 * bug 320007
 */
@Test
public void testBlockCodeWithTabsFormatted() throws IOException {
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder documentBuilder = new HtmlDocumentBuilder(out, true);
    parser.setBuilder(documentBuilder);
    parser.parse("bc. one\n\ttwo\n\nthree");
    String html = out.toString();
    assertTrue(html.contains("one\n\ttwo"));
}
Also used : StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) Test(org.junit.Test) AbstractMarkupGenerationTest(org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)

Example 58 with HtmlDocumentBuilder

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

the class HubspotDocumentBuilder method beginHeading.

/**
 * <p>
 * The begin of a heading has been encountered. If it is an H1 heading, we
 * have to write the first part of the contents template into the stream.
 * Placeholders <em>${h1.id}</em> and <em>${h1.title}</em> have to be
 * replaced by actual values.
 * </p>
 * <p>
 * <strong>Please note:</strong> At this point the title text is not yet
 * known! This is only the case at {@link #endHeading()}.
 * </p>
 */
@Override
public void beginHeading(final int level, final Attributes attributes) {
    isProcessingHeading = true;
    final String id = attributes.getId();
    if (!isEarlySeparator) {
        isFollowingEarlySeparator = isEarlySeparator;
        isEarlySeparator = level == 1 && "%EARLY_SEPARATOR%".equals(attributes.getCssStyle());
    } else {
        isFollowingEarlySeparator = isEarlySeparator;
        isEarlySeparator = false;
    }
    if (isEarlySeparator) {
        /*
			 * Collect everything between the early separator and the next H1 in
			 * another writer.
			 */
        s2 = new StringWriter();
        w2 = new PrintWriter(s2);
        h2 = new HtmlDocumentBuilder(w2);
    } else
        currentHeading = new Heading(resource, level, id);
    if (level == 1) {
        if (!isFirstH1 && !isFollowingEarlySeparator)
            w.print(resolveHeadingIdAndTitle(contentsTemplate[1], 1, id, null));
        else
            isFirstH1 = false;
        if (!isEarlySeparator) {
            w.println(resolveHeadingIdAndTitle(contentsTemplate[0], 1, id, null));
            if (isFollowingEarlySeparator) {
                w2.close();
                w.println(s2.toString());
                h2 = null;
                w2 = null;
            }
            super.beginHeading(level, attributes);
        }
    } else
        super.beginHeading(level, attributes);
}
Also used : StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) PrintWriter(java.io.PrintWriter)

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