use of org.eclipse.mylyn.wikitext.parser.MarkupParser in project mylyn.docs by eclipse.
the class AsciiDocIdGenerationStrategy method parseToHtml.
private static String parseToHtml(String markup) {
MarkupParser localParser = new MarkupParser(new AsciiDocLanguage());
StringWriter out = new StringWriter();
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
builder.setEmitAsDocument(false);
localParser.setBuilder(builder);
localParser.parse(markup);
return out.toString();
}
use of org.eclipse.mylyn.wikitext.parser.MarkupParser in project mylyn.docs by eclipse.
the class MarkupToDocbookTask method processFile.
private void processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
// $NON-NLS-1$
log(MessageFormat.format(Messages.getString("MarkupToDocbookTask.8"), source), Project.MSG_VERBOSE);
String markupContent = null;
String name = source.getName();
if (name.lastIndexOf('.') != -1) {
name = name.substring(0, name.lastIndexOf('.'));
}
// $NON-NLS-1$
File docbookOutputFile = new File(source.getParentFile(), docbookFilenameFormat.replace("$1", name));
if (!docbookOutputFile.exists() || overwrite || docbookOutputFile.lastModified() < source.lastModified()) {
if (markupContent == null) {
markupContent = readFully(source);
}
performValidation(source, markupContent);
Writer writer;
try {
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(docbookOutputFile)), // $NON-NLS-1$
"utf-8");
} catch (Exception e) {
throw new BuildException(MessageFormat.format(// $NON-NLS-1$
Messages.getString("MarkupToDocbookTask.11"), // $NON-NLS-1$
docbookOutputFile, e.getMessage()), e);
}
try {
DocBookDocumentBuilder builder = new DocBookDocumentBuilder(writer) {
@Override
protected XmlStreamWriter createXmlStreamWriter(Writer out) {
return super.createFormattingXmlStreamWriter(out);
}
};
MarkupParser parser = new MarkupParser();
parser.setMarkupLanguage(markupLanguage);
parser.setBuilder(builder);
builder.setBookTitle(bookTitle == null ? name : bookTitle);
if (doctype != null) {
builder.setDoctype(doctype);
}
parser.parse(markupContent);
} finally {
try {
writer.close();
} catch (Exception e) {
throw new BuildException(MessageFormat.format(// $NON-NLS-1$
Messages.getString("MarkupToDocbookTask.12"), // $NON-NLS-1$
docbookOutputFile, e.getMessage()), e);
}
}
}
}
use of org.eclipse.mylyn.wikitext.parser.MarkupParser in project mylyn.docs by eclipse.
the class SplittingHtmlDocumentBuilderTest method generateContents.
private void generateContents(String markup, boolean embeddedTableOfContents) throws IOException, FileNotFoundException {
try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
rootBuilder = new HtmlDocumentBuilder(out, true);
SplittingOutlineParser outlineParser = new SplittingOutlineParser();
outlineParser.setMarkupLanguage(new TextileLanguage());
outlineParser.setSplittingStrategy(new DefaultSplittingStrategy());
SplitOutlineItem outline = outlineParser.parse(markup);
outline.setSplitTarget(outputFile.getName());
builder.setEmbeddedTableOfContents(embeddedTableOfContents);
builder.setRootBuilder(rootBuilder);
builder.setRootFile(outputFile);
builder.setFormatting(true);
builder.setOutline(outline);
MarkupParser parser = new MarkupParser(new TextileLanguage());
parser.setBuilder(builder);
parser.parse(markup);
}
}
use of org.eclipse.mylyn.wikitext.parser.MarkupParser in project mylyn.docs by eclipse.
the class TextileLanguageDefinitionListTest method initParser.
@Before
public void initParser() throws IOException {
parser = new MarkupParser();
markupLanguage = new TextileLanguage();
parser.setMarkupLanguage(markupLanguage);
}
use of org.eclipse.mylyn.wikitext.parser.MarkupParser in project mylyn.docs by eclipse.
the class TextileLanguageDefinitionListTest method offsets.
@Test
public void offsets() {
RecordingDocumentBuilder builder = new RecordingDocumentBuilder();
MarkupParser markupParser = new MarkupParser(markupLanguage);
markupParser.setBuilder(builder);
markupParser.parse("- one := two");
Event event = findEvent(builder.getEvents(), BlockType.DEFINITION_TERM);
assertEquals(1, event.locator.getLineNumber());
assertEquals(0, event.locator.getLineCharacterOffset());
assertEquals(6, event.locator.getLineSegmentEndOffset());
Event itemEvent = findEvent(builder.getEvents(), BlockType.DEFINITION_ITEM);
assertEquals(1, itemEvent.locator.getLineNumber());
assertEquals(6, itemEvent.locator.getLineCharacterOffset());
}
Aggregations