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