use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder.Stylesheet 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.parser.builder.HtmlDocumentBuilder.Stylesheet in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testCssStylesheetEmbedded.
public void testCssStylesheetEmbedded() throws Exception {
URL cssResource = HtmlDocumentBuilder2Test.class.getResource("resources/test.css");
File cssFile = new File(cssResource.toURI().getPath());
fileToUrl.put(cssFile, cssResource);
builder.addCssStylesheet(new Stylesheet(cssFile));
builder.beginDocument();
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("some para text");
builder.endBlock();
builder.endDocument();
String html = out.toString();
html = html.replace("
", "");
assertTrue(Pattern.compile("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/><style type=\"text/css\">\\s*body\\s+\\{\\s+background-image: test-content.png;\\s+\\}\\s*</style></head>", Pattern.MULTILINE).matcher(html).find());
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder.Stylesheet in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testStylesheetWithAttributes.
public void testStylesheetWithAttributes() {
Stylesheet stylesheet = new Stylesheet("a/test.css");
stylesheet.getAttributes().put("foo", "bar");
builder.addCssStylesheet(stylesheet);
builder.beginDocument();
builder.endDocument();
String html = out.toString();
assertTrue(html.contains("<link type=\"text/css\" rel=\"stylesheet\" href=\"a/test.css\" foo=\"bar\"/>"));
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder.Stylesheet in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testCssStylesheetAsLink.
public void testCssStylesheetAsLink() {
builder.addCssStylesheet(new Stylesheet("styles/test.css"));
builder.beginDocument();
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("some para text");
builder.endBlock();
builder.endDocument();
String html = out.toString();
assertTrue(html.contains("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/><link type=\"text/css\" rel=\"stylesheet\" href=\"styles/test.css\"/></head>"));
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder.Stylesheet in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testStylesheetWithNoAttributes.
public void testStylesheetWithNoAttributes() {
builder.addCssStylesheet(new Stylesheet("a/test.css"));
builder.beginDocument();
builder.endDocument();
String html = out.toString();
assertTrue(html.contains("<link type=\"text/css\" rel=\"stylesheet\" href=\"a/test.css\"/>"));
}
Aggregations