Search in sources :

Example 6 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage in project mylyn.docs by eclipse.

the class WikiToDocTask method markupToDoc.

private void markupToDoc(MarkupLanguage markupLanguage, Path path, String markupContent, Map<String, SplitOutlineItem> pathNameToOutline, Set<String> imageFilenames) throws BuildException {
    File htmlOutputFile = computeHtmlOutputFile(path);
    File pathDir = htmlOutputFile.getParentFile();
    if (!pathDir.exists()) {
        if (!pathDir.mkdirs()) {
            throw new BuildException(// $NON-NLS-1$
            MessageFormat.format(// $NON-NLS-1$
            Messages.getString("WikiToDocTask_cannot_create_dest_folder"), pathDir.getAbsolutePath()));
        }
    }
    Writer writer;
    try {
        // $NON-NLS-1$
        writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(htmlOutputFile)), "utf-8");
    } catch (Exception e) {
        throw new BuildException(// $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        Messages.getString("WikiToDocTask_cannot_create_output_file"), // $NON-NLS-1$
        htmlOutputFile, e.getMessage()), e);
    }
    try {
        HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer, formatOutput);
        for (Stylesheet stylesheet : stylesheets) {
            HtmlDocumentBuilder.Stylesheet builderStylesheet = createBuilderStylesheet(pathDir, stylesheet);
            builder.addCssStylesheet(builderStylesheet);
        }
        builder.setTitle(computeTitle(path));
        builder.setEmitDtd(emitDoctype);
        if (emitDoctype && htmlDoctype != null) {
            builder.setHtmlDtd(htmlDoctype);
        }
        builder.setUseInlineStyles(useInlineCssStyles);
        builder.setSuppressBuiltInStyles(suppressBuiltInCssStyles);
        builder.setLinkRel(linkRel);
        builder.setDefaultAbsoluteLinkTarget(defaultAbsoluteLinkTarget);
        builder.setPrependImagePrefix(prependImagePrefix);
        builder.setXhtmlStrict(xhtmlStrict);
        MarkupLanguage markupLanguageClone = markupLanguage.clone();
        if (markupLanguageClone instanceof MediaWikiLanguage) {
            MediaWikiLanguage mediaWikiLanguage = (MediaWikiLanguage) markupLanguageClone;
            mediaWikiLanguage.setPageMapping(new PathPageMapping(path, paths, pathNameToOutline));
            if (imageFilenames != null) {
                mediaWikiLanguage.setImageNames(imageFilenames);
            }
        }
        SplitOutlineItem item = pathNameToOutline.get(path.name);
        SplittingHtmlDocumentBuilder splittingBuilder = new SplittingHtmlDocumentBuilder();
        splittingBuilder.setRootBuilder(builder);
        splittingBuilder.setOutline(item);
        splittingBuilder.setRootFile(htmlOutputFile);
        splittingBuilder.setNavigationImages(navigationImages);
        splittingBuilder.setFormatting(formatOutput);
        splittingBuilder.setNavigationImagePath(computeNavigationImagePath(pathDir));
        MarkupParser parser = new MarkupParser();
        parser.setMarkupLanguage(markupLanguageClone);
        parser.setBuilder(splittingBuilder);
        parser.parse(markupContent);
    } finally {
        try {
            writer.close();
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(// $NON-NLS-1$
            Messages.getString("WikiToDocTask_cannot_write_output_file"), // $NON-NLS-1$
            htmlOutputFile, e.getMessage()), e);
        }
    }
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileOutputStream(java.io.FileOutputStream) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 7 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage in project mylyn.docs by eclipse.

the class XslfoDocumentBuilderIntegrationTest method testforTableRowAlign_bug336813.

public void testforTableRowAlign_bug336813() {
    final String markup = "{|\n" + "|- valign=\"top\"\n |'''Row heading'''\n" + "| A longer piece of text. Lorem ipsum...\n |A shorter piece of text.\n" + "|- style=\"vertical-align: bottom;\"\n |'''Row heading'''\n" + "|A longer piece of text. Lorem ipsum... \n |A shorter piece of text.\n" + "|}";
    documentBuilder.getConfiguration().setPageNumbering(true);
    documentBuilder.getConfiguration().setTitle("Title");
    OutlineItem op = new OutlineParser(new MediaWikiLanguage()).parse(markup);
    documentBuilder.setOutline(op);
    parser.setMarkupLanguage(new MediaWikiLanguage());
    parser.parse(markup, true);
    final String xslfo = out.toString();
    // From "valign" attribute
    assertTrue(Pattern.compile("<table-row display-align=\"before\">").matcher(xslfo).find());
    // From css styling
    assertTrue(Pattern.compile("<table-row display-align=\"after\">").matcher(xslfo).find());
}
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 8 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage in project mylyn.docs by eclipse.

the class ParagraphBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    nestedStartOffset = -1;
    nestedLineNumber = -1;
    if (blockLineCount == 0) {
        Attributes attributes = new Attributes();
        builder.beginBlock(BlockType.PARAGRAPH, attributes);
    }
    if (markupLanguage.isEmptyLine(line)) {
        setClosed(true);
        return 0;
    }
    MediaWikiLanguage dialect = (MediaWikiLanguage) getMarkupLanguage();
    // paragraphs can have nested lists and other things
    for (Block block : dialect.getParagraphBreakingBlocks()) {
        if (block.canStart(line, offset)) {
            setClosed(true);
            return offset;
        }
    }
    nestedStartOffset = calculateNestedStartOffset(line, offset);
    if (nestedStartOffset != -1) {
        nestedLineNumber = getState().getLineNumber();
    }
    ++blockLineCount;
    if (testPreformattedBlocks && offset == 0 && line.length() > 0 && line.charAt(0) == ' ') {
        // a preformatted block.
        setClosed(true);
        return 0;
    }
    if (blockLineCount != 1 && nestedStartOffset == -1 && lastLineNumber != getState().getLineNumber()) {
        // note: normally newlines don't automatically convert to line breaks
        if (newlinesCauseLineBreak) {
            builder.lineBreak();
        } else {
            // $NON-NLS-1$
            builder.characters("\n");
        }
    }
    if (nestedStartOffset > 0) {
        line = line.substring(0, nestedStartOffset);
    }
    if (nestedStartOffset != offset) {
        dialect.emitMarkupLine(getParser(), state, line, offset);
    }
    lastLineNumber = getState().getLineNumber();
    return nestedStartOffset;
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) Block(org.eclipse.mylyn.wikitext.parser.markup.Block)

Example 9 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage 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 10 with MediaWikiLanguage

use of org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage in project mylyn.docs by eclipse.

the class DitaTopicDocumentBuilderTest method testImageWithCaption.

public void testImageWithCaption() {
    parser.setMarkupLanguage(new MediaWikiLanguage());
    parser.parse("[[Image:images/editor-assist-proposals.png|alt=Alternative text|Caption text.]]");
    String dita = out.toString();
    assertTrue(Pattern.compile("<fig>\\s*<title>Caption text.</title>\\s*<image href=\"images/editor-assist-proposals.png\" alt=\"Alternative text\"/>\\s*</fig>", Pattern.DOTALL).matcher(dita).find());
}
Also used : MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)

Aggregations

MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)17 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)9 OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)9 AbstractMarkupGenerationTest (org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)3 Test (org.junit.Test)3 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BuildException (org.apache.tools.ant.BuildException)2 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)2 SplitOutlineItem (org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1