use of org.eclipse.mylyn.wikitext.util.XmlStreamWriter in project mylyn.docs by eclipse.
the class MarkupToOPS method parse.
/**
* Parses the markup file and populates the publication with the result.
*
* @param ops
* the publication the content will be added to
* @param markupFile
* the WikiText markup file
* @return the temporary folder used for generating the HTML from markup
* @since 2.0
*/
public File parse(Publication ops, File markupFile) throws IOException, FileNotFoundException {
if (markupLanguage == null) {
// $NON-NLS-1$
throw new IllegalStateException("must set markupLanguage");
}
// Create a temporary working folder
// $NON-NLS-1$
File workingFolder = File.createTempFile("wikitext_", null);
if (workingFolder.delete() && workingFolder.mkdirs()) {
// $NON-NLS-1$
File htmlFile = new File(workingFolder.getAbsolutePath() + File.separator + "markup.html");
FileWriter out = new FileWriter(htmlFile);
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out) {
@Override
protected XmlStreamWriter createXmlStreamWriter(Writer out) {
return super.createFormattingXmlStreamWriter(out);
}
};
List<Item> stylesheets = ops.getItemsByMIMEType(Publication.MIMETYPE_CSS);
for (Item item : stylesheets) {
File file = new File(item.getFile());
Stylesheet css = new Stylesheet(file);
builder.addCssStylesheet(css);
}
// Make sure we get the correct XHTML header
builder.setEmitDtd(true);
builder.setHtmlDtd(// $NON-NLS-1$
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
builder.setXhtmlStrict(true);
MarkupParser markupParser = new MarkupParser();
markupParser.setBuilder(builder);
markupParser.setMarkupLanguage(markupLanguage);
markupParser.parse(new FileReader(markupFile));
ops.setGenerateToc(true);
ops.setIncludeReferencedResources(true);
Item item = ops.addItem(htmlFile);
item.setSourcePath(markupFile.getAbsolutePath());
}
return workingFolder;
}
use of org.eclipse.mylyn.wikitext.util.XmlStreamWriter 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.util.XmlStreamWriter 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.util.XmlStreamWriter in project mylyn.docs by eclipse.
the class HtmlSubsetLanguageTest method cloneSupported.
@Test
public void cloneSupported() {
HtmlDocumentHandler documentHandler = new HtmlDocumentHandler() {
@Override
public void endDocument(HtmlDocumentBuilder builder, XmlStreamWriter writer) {
// ignore
}
@Override
public void beginDocument(HtmlDocumentBuilder builder, XmlStreamWriter writer) {
// ignore
}
};
HtmlSubsetLanguage language = new HtmlSubsetLanguage("Test", documentHandler, 6, Sets.newHashSet(BlockType.PARAGRAPH, BlockType.DIV, BlockType.QUOTE), Sets.newHashSet(SpanType.CITATION, SpanType.EMPHASIS), ImmutableMap.of(SpanType.EMPHASIS, "new-em"), Collections.<SpanHtmlElementStrategy>emptyList(), false, true);
HtmlSubsetLanguage cloned = language.clone();
assertEquals(language.getName(), cloned.getName());
assertEquals(language.getSupportedBlockTypes(), cloned.getSupportedBlockTypes());
assertEquals(language.getSupportedHeadingLevel(), cloned.getSupportedHeadingLevel());
assertEquals(language.getSupportedSpanTypes(), cloned.getSupportedSpanTypes());
assertEquals(language.getTagNameSubstitutions(), cloned.getTagNameSubstitutions());
}
use of org.eclipse.mylyn.wikitext.util.XmlStreamWriter in project mylyn.docs by eclipse.
the class CommonMarkAsserts method createDocumentBuilder.
private static DocumentBuilder createDocumentBuilder(StringWriter out) {
HtmlDocumentBuilder builder = new SimplifiedHtmlDocumentBuilder(out);
builder.setDocumentHandler(new HtmlDocumentHandler() {
@Override
public void endDocument(HtmlDocumentBuilder builder, XmlStreamWriter writer) {
}
@Override
public void beginDocument(HtmlDocumentBuilder builder, XmlStreamWriter writer) {
}
});
return builder;
}
Aggregations