Search in sources :

Example 31 with MarkupParser

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

the class AsciiDocIdGenerationStrategy method parseToHtml.

private static String parseToHtml(String markup) {
    MarkupParser localParser = new MarkupParser(new AsciiDocLanguage());
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.setEmitAsDocument(false);
    localParser.setBuilder(builder);
    localParser.parse(markup);
    return out.toString();
}
Also used : StringWriter(java.io.StringWriter) AsciiDocLanguage(org.eclipse.mylyn.wikitext.asciidoc.AsciiDocLanguage) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 32 with MarkupParser

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

the class MarkupToDocbookTask method processFile.

private void processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToDocbookTask.8"), source), Project.MSG_VERBOSE);
    String markupContent = null;
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    // $NON-NLS-1$
    File docbookOutputFile = new File(source.getParentFile(), docbookFilenameFormat.replace("$1", name));
    if (!docbookOutputFile.exists() || overwrite || docbookOutputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        Writer writer;
        try {
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(docbookOutputFile)), // $NON-NLS-1$
            "utf-8");
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(// $NON-NLS-1$
            Messages.getString("MarkupToDocbookTask.11"), // $NON-NLS-1$
            docbookOutputFile, e.getMessage()), e);
        }
        try {
            DocBookDocumentBuilder builder = new DocBookDocumentBuilder(writer) {

                @Override
                protected XmlStreamWriter createXmlStreamWriter(Writer out) {
                    return super.createFormattingXmlStreamWriter(out);
                }
            };
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(builder);
            builder.setBookTitle(bookTitle == null ? name : bookTitle);
            if (doctype != null) {
                builder.setDoctype(doctype);
            }
            parser.parse(markupContent);
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToDocbookTask.12"), // $NON-NLS-1$
                docbookOutputFile, e.getMessage()), e);
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) XmlStreamWriter(org.eclipse.mylyn.wikitext.util.XmlStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) DocBookDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 33 with MarkupParser

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

the class SplittingHtmlDocumentBuilderTest method generateContents.

private void generateContents(String markup, boolean embeddedTableOfContents) throws IOException, FileNotFoundException {
    try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
        rootBuilder = new HtmlDocumentBuilder(out, true);
        SplittingOutlineParser outlineParser = new SplittingOutlineParser();
        outlineParser.setMarkupLanguage(new TextileLanguage());
        outlineParser.setSplittingStrategy(new DefaultSplittingStrategy());
        SplitOutlineItem outline = outlineParser.parse(markup);
        outline.setSplitTarget(outputFile.getName());
        builder.setEmbeddedTableOfContents(embeddedTableOfContents);
        builder.setRootBuilder(rootBuilder);
        builder.setRootFile(outputFile);
        builder.setFormatting(true);
        builder.setOutline(outline);
        MarkupParser parser = new MarkupParser(new TextileLanguage());
        parser.setBuilder(builder);
        parser.parse(markup);
    }
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) FileOutputStream(java.io.FileOutputStream) SplittingOutlineParser(org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser) OutputStreamWriter(java.io.OutputStreamWriter) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 34 with MarkupParser

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

the class TextileLanguageDefinitionListTest method initParser.

@Before
public void initParser() throws IOException {
    parser = new MarkupParser();
    markupLanguage = new TextileLanguage();
    parser.setMarkupLanguage(markupLanguage);
}
Also used : MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser) Before(org.junit.Before)

Example 35 with MarkupParser

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

the class TextileLanguageDefinitionListTest method offsets.

@Test
public void offsets() {
    RecordingDocumentBuilder builder = new RecordingDocumentBuilder();
    MarkupParser markupParser = new MarkupParser(markupLanguage);
    markupParser.setBuilder(builder);
    markupParser.parse("- one := two");
    Event event = findEvent(builder.getEvents(), BlockType.DEFINITION_TERM);
    assertEquals(1, event.locator.getLineNumber());
    assertEquals(0, event.locator.getLineCharacterOffset());
    assertEquals(6, event.locator.getLineSegmentEndOffset());
    Event itemEvent = findEvent(builder.getEvents(), BlockType.DEFINITION_ITEM);
    assertEquals(1, itemEvent.locator.getLineNumber());
    assertEquals(6, itemEvent.locator.getLineCharacterOffset());
}
Also used : Event(org.eclipse.mylyn.wikitext.toolkit.RecordingDocumentBuilder.Event) RecordingDocumentBuilder(org.eclipse.mylyn.wikitext.toolkit.RecordingDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser) Test(org.junit.Test)

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