Search in sources :

Example 11 with OutlineParser

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

the class MarkupToXslfoTask method processFile.

/**
 * process the file
 *
 * @param baseDir
 * @param source
 * @return
 * @return the lightweight markup, or null if the file was not written
 * @throws BuildException
 */
protected String processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToXslfoTask.7"), source), Project.MSG_VERBOSE);
    String markupContent = null;
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File outputFile = computeXslfoFile(source, name);
    if (targetdir != null) {
        outputFile = new File(targetdir, outputFile.getName());
    }
    if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        Writer out;
        try {
            // $NON-NLS-1$
            out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToXslfoTask.8"), outputFile, e.getMessage()), // $NON-NLS-1$
            e);
        }
        try {
            XslfoDocumentBuilder builder = new XslfoDocumentBuilder(out);
            XslfoDocumentBuilder.Configuration configuration = this.configuration.clone();
            if (configuration.getTitle() == null) {
                configuration.setTitle(name);
            }
            builder.setConfiguration(configuration);
            builder.setBase(source.getParentFile().toURI());
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(builder);
            if (generateBookmarks) {
                OutlineItem outline = new OutlineParser(markupLanguage).parse(markupContent);
                builder.setOutline(outline);
            }
            parser.parse(markupContent);
        } finally {
            try {
                out.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToXslfoTask.9"), // $NON-NLS-1$
                outputFile, e.getMessage()), e);
            }
        }
    }
    return markupContent;
}
Also used : BuildException(org.apache.tools.ant.BuildException) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) XslfoDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 12 with OutlineParser

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

the class TableOfContentsBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineNumber++ > 0) {
        setClosed(true);
        return 0;
    }
    if (!getMarkupLanguage().isFilterGenerativeContents()) {
        OutlineParser outlineParser = new OutlineParser(new TWikiLanguage());
        OutlineItem rootItem = outlineParser.parse(state.getMarkupContent());
        emitToc(rootItem);
    }
    return -1;
}
Also used : OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) TWikiLanguage(org.eclipse.mylyn.wikitext.twiki.TWikiLanguage) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 13 with OutlineParser

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

the class TableOfContentsBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineNumber++ > 0) {
        setClosed(true);
        return 0;
    }
    if (!getMarkupLanguage().isFilterGenerativeContents()) {
        String options = matcher.group(1);
        setOptions(options);
        OutlineParser outlineParser = new OutlineParser(new ConfluenceLanguage());
        OutlineItem rootItem = outlineParser.parse(state.getMarkupContent());
        emitToc(rootItem);
    }
    setClosed(true);
    return matcher.start(2);
}
Also used : ConfluenceLanguage(org.eclipse.mylyn.wikitext.confluence.ConfluenceLanguage) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 14 with OutlineParser

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

the class OutlineParserTest method testHeadersWithHtmlTags.

public void testHeadersWithHtmlTags() {
    // bug 374019
    outlineParser = new OutlineParser(new MediaWikiLanguage());
    OutlineItem outline = outlineParser.parse("= <span style=\"font-family:monospace\">Heading Text</span> =\n\n text");
    assertEquals(1, outline.getChildren().size());
    OutlineItem headingItem = outline.getChildren().get(0);
    assertEquals("Heading_Text", headingItem.getId());
    assertEquals("Heading Text", headingItem.getLabel());
}
Also used : OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 15 with OutlineParser

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

the class MediaWikiLanguageTest method testComputeOutline.

@Test
public void testComputeOutline() throws IOException {
    OutlineParser outlineParser = new OutlineParser();
    outlineParser.setMarkupLanguage(new MediaWikiLanguage());
    OutlineItem outline = outlineParser.parse(readFully("sample.mediawiki"));
    Set<String> topLevelLabels = new LinkedHashSet<String>();
    Set<String> topLevelIds = new LinkedHashSet<String>();
    List<OutlineItem> children = outline.getChildren();
    for (OutlineItem item : children) {
        topLevelLabels.add(item.getLabel());
        topLevelIds.add(item.getId());
    }
    assertEquals(children.size(), topLevelIds.size());
    assertEquals(children.size(), topLevelLabels.size());
    assertTrue("Top-level labels: " + topLevelLabels, topLevelLabels.contains("Task-Focused UI"));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) AbstractMarkupGenerationTest(org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest) Test(org.junit.Test)

Aggregations

OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)19 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)18 MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)9 TextileLanguage (org.eclipse.mylyn.wikitext.textile.TextileLanguage)3 BufferedOutputStream (java.io.BufferedOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 BuildException (org.apache.tools.ant.BuildException)2 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)2 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 CoreException (org.eclipse.core.runtime.CoreException)1 ConfluenceLanguage (org.eclipse.mylyn.wikitext.confluence.ConfluenceLanguage)1 DitaBookMapDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.DitaBookMapDocumentBuilder)1 DitaTopicDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.DitaTopicDocumentBuilder)1 XslfoDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder)1 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)1 AbstractMarkupGenerationTest (org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)1