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);
}
}
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);
}
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();
}
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"));
}
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());
}
Aggregations