use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.
the class SplittingHtmlDocumentBuilder method beginHeading.
@Override
public void beginHeading(int level, Attributes attributes) {
SplitOutlineItem item = outline.getOutlineItemById(attributes.getId());
if (item != null && !currentFile.getName().equals(item.getSplitTarget())) {
try {
documentFooter();
out.endDocument();
if (writer != null) {
writer.close();
writer = null;
}
currentFile = new File(rootFile.getParent(), item.getSplitTarget());
// $NON-NLS-1$
writer = new OutputStreamWriter(new FileOutputStream(currentFile), "UTF-8");
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer, formatting);
rootBuilder.copyConfiguration(builder);
if (item.getLabel() != null) {
String title = rootBuilder.getTitle();
if (title == null) {
title = item.getLabel();
} else {
// $NON-NLS-1$
title += " - " + item.getLabel();
}
builder.setTitle(title);
}
out = builder;
out.beginDocument();
documentHeader();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
out.beginHeading(level, attributes);
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.
the class ConvertMarkupToHtml method handleFile.
@Override
protected void handleFile(final IFile file, String name) {
// $NON-NLS-1$
final IFile newFile = file.getParent().getFile(new Path(name + ".html"));
if (newFile.exists()) {
if (!MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.ConvertMarkupToHtml_overwrite, NLS.bind(Messages.ConvertMarkupToHtml_fileExistsOverwrite, new Object[] { newFile.getFullPath() }))) {
return;
}
}
final StringWriter writer = new StringWriter();
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer, true);
final MarkupParser parser = new MarkupParser();
parser.setMarkupLanguage(markupLanguage);
parser.setBuilder(builder);
builder.setEmitDtd(true);
try {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
String inputContent = IOUtil.readFully(file);
parser.parse(inputContent);
String xhtmlContent = writer.toString();
if (newFile.exists()) {
// $NON-NLS-1$
newFile.setContents(// $NON-NLS-1$
new ByteArrayInputStream(xhtmlContent.getBytes("utf-8")), // $NON-NLS-1$
false, // $NON-NLS-1$
true, monitor);
} else {
// $NON-NLS-1$
newFile.create(new ByteArrayInputStream(xhtmlContent.getBytes("utf-8")), false, monitor);
}
newFile.setCharset(StandardCharsets.UTF_8.name(), monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
} catch (InterruptedException e) {
return;
} catch (InvocationTargetException e) {
throw e.getCause();
}
} catch (Throwable e) {
StringWriter message = new StringWriter();
PrintWriter out = new PrintWriter(message);
out.println(Messages.ConvertMarkupToHtml_cannotConvert + e.getMessage());
out.println(Messages.ConvertMarkupToHtml_detailsFollow);
e.printStackTrace(out);
out.close();
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.ConvertMarkupToHtml_cannotCompleteOperation, message.toString());
}
}
use of org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder 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.builder.HtmlDocumentBuilder 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.builder.HtmlDocumentBuilder in project mylyn.docs by eclipse.
the class AbstractSourceSpanTest method assertParseToHtml.
public void assertParseToHtml(String expected, String markup) {
StringWriter writer = new StringWriter();
HtmlDocumentBuilder builder = new SimplifiedHtmlDocumentBuilder(writer);
builder.setEmitAsDocument(false);
builder.beginDocument();
InlineParser parser = new InlineParser(span, new AllCharactersSpan());
List<Inline> inlines = parser.parse(ProcessingContext.builder().build(), new TextSegment(ImmutableList.of(new Line(1, 0, markup))));
for (Inline inline : inlines) {
inline.emit(builder);
}
builder.endDocument();
assertEquals(expected, writer.toString());
}
Aggregations