Search in sources :

Example 51 with OutlineItem

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

the class WikiToDocTask method createToc.

private void createToc(List<Path> paths, final Map<String, SplitOutlineItem> pathNameToOutline) {
    // $NON-NLS-1$
    getProject().log(// $NON-NLS-1$
    MessageFormat.format(Messages.getString("WikiToDocTask_writing_toc"), tocFile), Project.MSG_VERBOSE);
    final OutlineItem rootItem = new // $NON-NLS-1$
    OutlineItem(// $NON-NLS-1$
    null, // $NON-NLS-1$
    0, // $NON-NLS-1$
    "<root>", // $NON-NLS-1$
    0, // $NON-NLS-1$
    -1, title == null ? computeTitle(paths.get(0)) : title);
    final Map<OutlineItem, Path> outlineItemToPath = new HashMap<OutlineItem, Path>();
    final Map<String, OutlineItem> nameToItem = new HashMap<String, OutlineItem>();
    // create root-level items
    for (Path path : paths) {
        if (path.includeInUnifiedToc) {
            SplitOutlineItem pathItem = pathNameToOutline.get(path.name);
            outlineItemToPath.put(pathItem, path);
            nameToItem.put(path.name, pathItem);
            if (path.getTocParentName() == null) {
                rootItem.getChildren().add(pathItem);
            }
        }
    }
    for (Path path : paths) {
        if (path.includeInUnifiedToc) {
            if (path.getTocParentName() != null) {
                SplitOutlineItem pathItem = pathNameToOutline.get(path.name);
                if (nameToItem.containsKey(path.getTocParentName())) {
                    nameToItem.get(path.getTocParentName()).getChildren().add(pathItem);
                } else {
                    throw new ConfigurationException(MessageFormat.format(Messages.getString("WikiToDocTask_unknown_tocParentName"), // $NON-NLS-1$
                    path.getTocParentName()));
                }
            }
        }
    }
    SplittingMarkupToEclipseToc markupToEclipseToc = new SplittingMarkupToEclipseToc() {

        @Override
        protected String computeFile(OutlineItem item) {
            if (item instanceof SplitOutlineItem) {
                return computeTocRelativeFile(outlineItemToPath, item);
            }
            return super.computeFile(item);
        }
    };
    markupToEclipseToc.setBookTitle(rootItem.getLabel());
    markupToEclipseToc.setHtmlFile(computeTocRelativeFile(outlineItemToPath, rootItem.getChildren().get(0)));
    String tocContents = markupToEclipseToc.createToc(rootItem);
    try {
        // $NON-NLS-1$
        Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(tocFile)), "UTF-8");
        try {
            writer.write(tocContents);
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        String message = MessageFormat.format("Cannot write {0}: {1}", tocFile, e.getMessage());
        throw new BuildException(message, e);
    }
}
Also used : HashMap(java.util.HashMap) SplittingMarkupToEclipseToc(org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) IOException(java.io.IOException) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) BufferedOutputStream(java.io.BufferedOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 52 with OutlineItem

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

the class WikiToDocTask method computeTocRelativeFile.

private String computeTocRelativeFile(Map<OutlineItem, Path> outlineItemToPath, final OutlineItem item) {
    Path path = outlineItemToPath.get(item);
    OutlineItem pathItem = item;
    while (path == null && pathItem.getParent() != null) {
        pathItem = pathItem.getParent();
        path = outlineItemToPath.get(pathItem);
    }
    return computeTocRelativeFile(item, path);
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 53 with OutlineItem

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

the class AbstractTableOfContentsBlock method emitToc.

protected void emitToc(OutlineItem item) {
    if (item.getChildren().isEmpty()) {
        return;
    }
    if ((item.getLevel() + 1) > maxLevel) {
        return;
    }
    Attributes nullAttributes = new Attributes();
    // $NON-NLS-1$ //$NON-NLS-2$
    builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes(null, null, "list-style: " + style + ";", null));
    for (OutlineItem child : item.getChildren()) {
        builder.beginBlock(BlockType.LIST_ITEM, nullAttributes);
        builder.link('#' + child.getId(), child.getLabel());
        emitToc(child);
        builder.endBlock();
    }
    builder.endBlock();
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 54 with OutlineItem

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

Example 55 with OutlineItem

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

the class XslfoDocumentBuilderIntegrationTest method testforTableCellTextAlign_bug336813.

public void testforTableCellTextAlign_bug336813() {
    final String markup = "{|\n" + "|- \n |'''Row heading'''\n" + "| align=\"left\" | A longer piece of text. Lorem ipsum...\n |A shorter piece of text.\n" + "|- \n |'''Row heading'''\n" + "| style=\"text-align: right;\" | 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 "text-align" attribute
    assertTrue(Pattern.compile("<table-cell text-align=\"left\"").matcher(xslfo).find());
    // From css styling
    assertTrue(Pattern.compile("<block font-size=\"10.0pt\" text-align=\"right\">").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)

Aggregations

OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)58 OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)18 MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)9 Point (org.eclipse.swt.graphics.Point)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ITextSelection (org.eclipse.jface.text.ITextSelection)5 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)5 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)5 BufferedOutputStream (java.io.BufferedOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Writer (java.io.Writer)4 BuildException (org.apache.tools.ant.BuildException)4 ISelection (org.eclipse.jface.viewers.ISelection)4 AbstractMarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3 MenuManager (org.eclipse.jface.action.MenuManager)3