Search in sources :

Example 16 with MarkupParser

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

the class AsciiDocLanguageWithConfigurationIntegrationTest method parseWithCommonMarkupLanguageConfiguration.

@Test
public void parseWithCommonMarkupLanguageConfiguration() {
    MarkupLanguageConfiguration configuration = new MarkupLanguageConfiguration();
    MarkupParser parser = createParserWithConfiguration(configuration);
    String html = parseAsciiDocToHtml(AsciiDocLanguageAttributeTest.MARKUP_FOR_DEFAULT, parser);
    AsciiDocLanguageAttributeTest.ensureDefaultValues(html);
}
Also used : MarkupLanguageConfiguration(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguageConfiguration) AsciiDocMarkupLanguageConfiguration(org.eclipse.mylyn.wikitext.asciidoc.AsciiDocMarkupLanguageConfiguration) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser) Test(org.junit.Test)

Example 17 with MarkupParser

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

the class HtmlLanguageIntegrationTest method defaultMarkupLanguageHasImageSupport.

@Test
public void defaultMarkupLanguageHasImageSupport() {
    MarkupLanguage sourceLanguage = getDefaultMarkupLanguage("Source HTML");
    MarkupLanguage targetLanguage = getDefaultMarkupLanguage("Target HTML");
    StringWriter stringWriter = new StringWriter();
    MarkupParser markupParser = getMarkupParser(sourceLanguage, targetLanguage, stringWriter);
    markupParser.parse("Text Before Image<img src=\"/favicon.ico\"/>Text After Image", false);
    assertEquals("Text Before Image<img border=\"0\" src=\"/favicon.ico\"/>Text After Image", stringWriter.toString());
}
Also used : StringWriter(java.io.StringWriter) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser) Test(org.junit.Test)

Example 18 with MarkupParser

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

the class MarkupToEclipseHelpMojo method processMarkup.

protected void processMarkup(File sourceFile, String relativePath, MarkupLanguage markupLanguage) {
    getLog().info(format("Processing markup file: {0}", sourceFile));
    String name = sourceFile.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File htmlOutputFile = computeHtmlFile(relativePath, name);
    if (!htmlOutputFile.exists() || htmlOutputFile.lastModified() < sourceFile.lastModified()) {
        String markupContent = readFully(sourceFile);
        if (!htmlOutputFile.getParentFile().exists()) {
            if (!htmlOutputFile.getParentFile().mkdirs()) {
                throw new BuildFailureException(format("Cannot create folder {0}", htmlOutputFile.getParentFile()));
            }
        }
        Writer writer = createWriter(htmlOutputFile);
        try {
            HtmlDocumentBuilder builder = createRootBuilder(writer, name, relativePath);
            SplittingStrategy splittingStrategy = createSplittingStrategy();
            SplittingOutlineParser outlineParser = createOutlineParser(markupLanguage, splittingStrategy);
            SplitOutlineItem rootTocItem = outlineParser.parse(markupContent);
            rootTocItem.setSplitTarget(htmlOutputFile.getName());
            SplittingHtmlDocumentBuilder splittingBuilder = createSplittingBuilder(builder, rootTocItem, htmlOutputFile, relativePath);
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(splittingBuilder);
            parser.parse(markupContent);
            createEclipseHelpToc(rootTocItem, sourceFile, relativePath, htmlOutputFile, name);
        } finally {
            close(writer, htmlOutputFile);
        }
    }
}
Also used : SplittingStrategy(org.eclipse.mylyn.wikitext.splitter.SplittingStrategy) NoSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy) SplittingOutlineParser(org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 19 with MarkupParser

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

the class CreoleLanguageTest method setUp.

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

Example 20 with MarkupParser

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

the class LinkDefinitionValidationRule method findProblems.

@Override
public List<ValidationProblem> findProblems(String markup, int offset, int length) {
    MarkupParser parser = new MarkupParser(new MarkdownLanguage());
    MarkdownContentStateDocumentBuilder builder = new MarkdownContentStateDocumentBuilder();
    parser.setBuilder(builder);
    parser.parse(markup);
    MarkdownContentState markdownContentState = builder.markdownContentState;
    LinkDefinitionUsageTracker linkDefinitionUsageTracker = markdownContentState.getLinkDefinitionUsageTracker();
    List<ValidationProblem> problems = new ArrayList<ValidationProblem>();
    List<Position> missingLinkDefinitionPositions = linkDefinitionUsageTracker.getMissingLinkDefinitionPositions();
    for (Position position : missingLinkDefinitionPositions) {
        problems.add(new ValidationProblem(Severity.ERROR, MessageFormat.format(// $NON-NLS-1$
        Messages.getString("LinkDefinitionValidationRule.missing"), position.getId()), position.getOffset(), position.getLength()));
    }
    List<Position> unusedLinkDefinitionPositions = linkDefinitionUsageTracker.getUnusedLinkDefinitionPositions();
    for (Position position : unusedLinkDefinitionPositions) {
        problems.add(new ValidationProblem(Severity.WARNING, MessageFormat.format(// $NON-NLS-1$
        Messages.getString("LinkDefinitionValidationRule.unused"), position.getId()), position.getOffset(), position.getLength()));
    }
    return problems;
}
Also used : LinkDefinitionUsageTracker(org.eclipse.mylyn.wikitext.markdown.internal.LinkDefinitionUsageTracker) Position(org.eclipse.mylyn.wikitext.markdown.internal.LinkDefinitionUsageTracker.Position) MarkdownLanguage(org.eclipse.mylyn.wikitext.markdown.MarkdownLanguage) ArrayList(java.util.ArrayList) ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem) MarkdownContentState(org.eclipse.mylyn.wikitext.markdown.internal.MarkdownContentState) 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