use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testSuppressBuiltInlineStyles.
public void testSuppressBuiltInlineStyles() throws Exception {
StringWriter out = new StringWriter();
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
builder.setSuppressBuiltInStyles(true);
builder.beginDocument();
builder.beginBlock(BlockType.NOTE, new Attributes());
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("foo");
builder.endBlock();
builder.endBlock();
builder.endDocument();
String html = out.toString();
assertTrue(html.contains("<body><div class=\"note\"><p>foo</p></div></body>"));
assertTrue(!html.contains("<style type=\"text/css\">"));
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testSuppressInlineStyles.
public void testSuppressInlineStyles() throws Exception {
StringWriter out = new StringWriter();
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
builder.setUseInlineStyles(false);
builder.beginDocument();
builder.beginBlock(BlockType.NOTE, new Attributes());
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("foo");
builder.endBlock();
builder.endBlock();
builder.endDocument();
String html = out.toString();
assertTrue(html.contains("<body><div class=\"note\"><p>foo</p></div></body>"));
assertTrue(html.contains("<style type=\"text/css\">"));
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method setUp.
@Override
public void setUp() {
parser = new MarkupParser();
parser.setMarkupLanguage(new TextileLanguage());
out = new StringWriter();
builder = new HtmlDocumentBuilder(out) {
@Override
protected void checkFileReadable(File file) {
if (!fileToUrl.containsKey(file)) {
super.checkFileReadable(file);
}
}
@Override
protected Reader getReader(File inputFile) throws FileNotFoundException {
URL url = fileToUrl.get(inputFile);
if (url != null) {
try {
return new InputStreamReader(url.openStream());
} catch (IOException e) {
throw new FileNotFoundException(String.format("%s (%s)", inputFile, url));
}
}
return super.getReader(inputFile);
}
};
parser.setBuilder(builder);
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.
the class WikiToDocTask method markupToDoc.
private void markupToDoc(MarkupLanguage markupLanguage, Path path, String markupContent, Map<String, SplitOutlineItem> pathNameToOutline, Set<String> imageFilenames) throws BuildException {
File htmlOutputFile = computeHtmlOutputFile(path);
File pathDir = htmlOutputFile.getParentFile();
if (!pathDir.exists()) {
if (!pathDir.mkdirs()) {
throw new BuildException(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiToDocTask_cannot_create_dest_folder"), pathDir.getAbsolutePath()));
}
}
Writer writer;
try {
// $NON-NLS-1$
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(htmlOutputFile)), "utf-8");
} catch (Exception e) {
throw new BuildException(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiToDocTask_cannot_create_output_file"), // $NON-NLS-1$
htmlOutputFile, e.getMessage()), e);
}
try {
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer, formatOutput);
for (Stylesheet stylesheet : stylesheets) {
HtmlDocumentBuilder.Stylesheet builderStylesheet = createBuilderStylesheet(pathDir, stylesheet);
builder.addCssStylesheet(builderStylesheet);
}
builder.setTitle(computeTitle(path));
builder.setEmitDtd(emitDoctype);
if (emitDoctype && htmlDoctype != null) {
builder.setHtmlDtd(htmlDoctype);
}
builder.setUseInlineStyles(useInlineCssStyles);
builder.setSuppressBuiltInStyles(suppressBuiltInCssStyles);
builder.setLinkRel(linkRel);
builder.setDefaultAbsoluteLinkTarget(defaultAbsoluteLinkTarget);
builder.setPrependImagePrefix(prependImagePrefix);
builder.setXhtmlStrict(xhtmlStrict);
MarkupLanguage markupLanguageClone = markupLanguage.clone();
if (markupLanguageClone instanceof MediaWikiLanguage) {
MediaWikiLanguage mediaWikiLanguage = (MediaWikiLanguage) markupLanguageClone;
mediaWikiLanguage.setPageMapping(new PathPageMapping(path, paths, pathNameToOutline));
if (imageFilenames != null) {
mediaWikiLanguage.setImageNames(imageFilenames);
}
}
SplitOutlineItem item = pathNameToOutline.get(path.name);
SplittingHtmlDocumentBuilder splittingBuilder = new SplittingHtmlDocumentBuilder();
splittingBuilder.setRootBuilder(builder);
splittingBuilder.setOutline(item);
splittingBuilder.setRootFile(htmlOutputFile);
splittingBuilder.setNavigationImages(navigationImages);
splittingBuilder.setFormatting(formatOutput);
splittingBuilder.setNavigationImagePath(computeNavigationImagePath(pathDir));
MarkupParser parser = new MarkupParser();
parser.setMarkupLanguage(markupLanguageClone);
parser.setBuilder(splittingBuilder);
parser.parse(markupContent);
} finally {
try {
writer.close();
} catch (Exception e) {
throw new BuildException(MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiToDocTask_cannot_write_output_file"), // $NON-NLS-1$
htmlOutputFile, e.getMessage()), e);
}
}
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.
the class HtmlDocumentBuilderIntegrationTest method setUp.
@Override
public void setUp() {
parser = new MarkupParser();
parser.setMarkupLanguage(new TextileLanguage());
out = new StringWriter();
builder = new HtmlDocumentBuilder(out);
parser.setBuilder(builder);
}
Aggregations