Search in sources :

Example 41 with MarkupParser

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

the class MarkdownLanguageTestBase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    parser = new MarkupParser(new MarkdownLanguage());
}
Also used : MarkdownLanguage(org.eclipse.mylyn.wikitext.markdown.MarkdownLanguage) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 42 with MarkupParser

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

the class MarkdownRoundTripTest method parseMarkdownToHtml.

private String parseMarkdownToHtml(String markupContent) {
    StringWriter htmlWriter = new StringWriter();
    HtmlDocumentBuilder htmlDocumentBuilder = new HtmlDocumentBuilder(htmlWriter);
    htmlDocumentBuilder.setEmitAsDocument(false);
    MarkupParser markupParser = new MarkupParser(language, htmlDocumentBuilder);
    markupParser.parse(markupContent);
    return htmlWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 43 with MarkupParser

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

the class BugzillaTextileLanguageTest method initParser.

private void initParser() throws IOException {
    parser = new MarkupParser();
    TextileLanguage markupLanguage = new TextileLanguage();
    MarkupLanguageConfiguration configuration = Util.create("bugzilla");
    markupLanguage.configure(configuration);
    parser.setMarkupLanguage(markupLanguage);
}
Also used : MarkupLanguageConfiguration(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguageConfiguration) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 44 with MarkupParser

use of org.eclipse.mylyn.wikitext.parser.MarkupParser 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)

Example 45 with MarkupParser

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

the class ConfluenceLanguageIntegrationTest method assertRoundTrip.

private void assertRoundTrip(String textileIn, String textileOut) {
    Writer confluenceOut = new StringWriter();
    ConfluenceLanguage confluenceLanguage = new ConfluenceLanguage();
    MarkupParser parser = new MarkupParser(confluenceLanguage);
    parser.setBuilder(confluenceLanguage.createDocumentBuilder(confluenceOut));
    parser.parse(textileIn, false);
    assertEquals(textileOut, confluenceOut.toString());
}
Also used : StringWriter(java.io.StringWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Aggregations

MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)55 StringWriter (java.io.StringWriter)24 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)17 Writer (java.io.Writer)13 Test (org.junit.Test)10 File (java.io.File)8 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)8 TextileLanguage (org.eclipse.mylyn.wikitext.textile.TextileLanguage)8 OutputStreamWriter (java.io.OutputStreamWriter)7 FileOutputStream (java.io.FileOutputStream)6 BufferedOutputStream (java.io.BufferedOutputStream)5 IOException (java.io.IOException)5 BuildException (org.apache.tools.ant.BuildException)5 IFile (org.eclipse.core.resources.IFile)4 EventDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)4 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HtmlLanguage (org.eclipse.mylyn.wikitext.html.HtmlLanguage)3 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)3