use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.
the class MarkupToDocbook method parse.
public String parse(String markupContent) throws Exception {
if (markupLanguage == null) {
// $NON-NLS-1$
throw new IllegalStateException("must set markupLanguage");
}
StringWriter out = new StringWriter();
DocBookDocumentBuilder builder = new DocBookDocumentBuilder(out) {
@Override
protected XmlStreamWriter createXmlStreamWriter(Writer out) {
return super.createFormattingXmlStreamWriter(out);
}
};
builder.setBookTitle(bookTitle);
MarkupParser markupParser = new MarkupParser();
markupParser.setBuilder(builder);
markupParser.setMarkupLanguage(markupLanguage);
markupParser.parse(markupContent);
return out.toString();
}
use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.
the class MediaWikiLanguageTest method testListOrderedWithContinuationToDocBook.
@Test
public void testListOrderedWithContinuationToDocBook() throws IOException {
StringWriter out = new StringWriter();
parser.setBuilder(new DocBookDocumentBuilder(out));
parser.parse("# a list\n" + "## a nested item\n" + "### another nested item\n" + "#: continued\n" + "# another item");
String docbook = out.toString();
// should look like this:
//
// <orderedlist>
// <listitem>
// <para>a list</para>
// <orderedlist>
// <listitem>
// <para>a nested item</para>
// <orderedlist>
// <listitem>
// <para>another nested item</para>
// </listitem>
// </orderedlist>
// <para>continued</para>
// </listitem>
// </orderedlist>
// </listitem>
// <listitem>
// <para>another item</para>
// </listitem>
// </orderedlist>
assertTrue(docbook.contains("<orderedlist><listitem><para>a list</para><orderedlist><listitem><para>a nested item</para><orderedlist><listitem><para>another nested item</para></listitem></orderedlist><para>continued</para></listitem></orderedlist></listitem><listitem><para>another item</para></listitem></orderedlist>"));
}
use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.
the class ConfluenceLanguageTest method testImageWithAttributesAlignCenterToDocbook.
@Test
public void testImageWithAttributesAlignCenterToDocbook() {
StringWriter out = new StringWriter();
DocBookDocumentBuilder builder = new DocBookDocumentBuilder(out);
parser.setBuilder(builder);
parser.parse("an !image.png|align=center! image");
String result = out.toString();
assertTrue(result.contains("<para>an <mediaobject><imageobject><imagedata fileref=\"image.png\"/></imageobject></mediaobject> image</para>"));
}
use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder 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.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.
the class ConfluenceLanguageTest method testTipToDocBook.
@Test
public void testTipToDocBook() {
StringWriter out = new StringWriter();
parser.setBuilder(new DocBookDocumentBuilder(out));
parser.parse("h1. a header\n" + "\n" + "Some text\n" + "{tip:title=A Title}\n" + "the body of the note\n" + "which may span multiple lines\n" + "\n" + "And may even have multiple paragraphs or *other* _textile_ ??markup??\n" + "{tip}" + "\n" + "More text...");
String docbook = out.toString();
assertTrue(docbook.contains("<tip><title>A Title</title><para>the body of"));
assertTrue(docbook.contains("paragraphs or <emphasis role=\"bold\">other</emphasis> <emphasis>textile</emphasis> <citation>markup</citation></para></tip>"));
}
Aggregations