use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder in project mylyn.docs by eclipse.
the class ConfluenceLanguageIntegrationTest method toMarkup.
private String toMarkup(String characterContent) {
StringWriter writer = new StringWriter();
DocumentBuilder builder = new ConfluenceLanguage().createDocumentBuilder(writer);
builder.beginDocument();
builder.characters(characterContent);
builder.endDocument();
return writer.toString().trim();
}
use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder in project mylyn.docs by eclipse.
the class ConfluenceLanguageIntegrationTest method assertHtmlToConfluenceColor.
private void assertHtmlToConfluenceColor(String color, String hex) {
HtmlLanguage htmlLanguage = HtmlLanguage.builder().add(BlockType.PARAGRAPH).add(SpanType.SPAN).name("Test").create();
MarkupParser parser = new MarkupParser(htmlLanguage);
Writer confluenceOut = new StringWriter();
DocumentBuilder confuenceBuilder = new ConfluenceLanguage().createDocumentBuilder(confluenceOut);
parser.setBuilder(confuenceBuilder);
parser.parse("<html><body><span style=\"color: " + color + "\"><del>this text here</del></span></body></html>", true);
assertEquals("{color:" + hex + "}-this text here-{color}\n\n", confluenceOut.toString());
}
use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder in project mylyn.docs by eclipse.
the class CommonMarkAsserts method parseToHtml.
private static String parseToHtml(MarkupLanguage markupLanguage, String input) {
StringWriter out = new StringWriter();
DocumentBuilder builder = createDocumentBuilder(out);
MarkupParser parser = new MarkupParser(markupLanguage, builder);
try {
parser.parse(new StringReader(input));
} catch (IOException e) {
throw Throwables.propagate(e);
}
return out.toString();
}
use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder in project mylyn.docs by eclipse.
the class HtmlToMarkupTask method processFile.
private void processFile(MarkupLanguage markupLanguage, File folder, File source) {
// $NON-NLS-1$
log(MessageFormat.format(Messages.getString("MarkupToHtmlTask.14"), source), Project.MSG_VERBOSE);
if (isValidate()) {
// $NON-NLS-1$
log(MessageFormat.format(Messages.getString("HtmlToMarkupTask.1"), source), Project.MSG_WARN);
}
String name = source.getName();
if (name.lastIndexOf('.') != -1) {
name = name.substring(0, name.lastIndexOf('.'));
}
File outputFile = computeTargetFile(markupLanguage, source, name);
if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
Writer writer;
try {
// $NON-NLS-1$
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
} catch (Exception e) {
throw new BuildException(MessageFormat.format(Messages.getString("MarkupToHtmlTask.16"), outputFile, e.getMessage()), // $NON-NLS-1$
e);
}
try {
DocumentBuilder builder = markupLanguage.createDocumentBuilder(writer);
Reader input;
InputStream in;
try {
in = new BufferedInputStream(new FileInputStream(source));
input = getSourceEncoding() == null ? new InputStreamReader(in) : new InputStreamReader(in, getSourceEncoding());
} catch (Exception e) {
throw new BuildException(MessageFormat.format(Messages.getString("MarkupTask.cannotReadSource"), source, e.getMessage()), // $NON-NLS-1$
e);
}
try {
new HtmlParser().parse(new InputSource(input), builder);
} catch (Exception e) {
throw new BuildException(MessageFormat.format(Messages.getString("HtmlToMarkupTask.failedToProcessContent"), source, e.getMessage()), // $NON-NLS-1$
e);
} finally {
try {
in.close();
} catch (Exception e) {
throw new BuildException(MessageFormat.format(Messages.getString("MarkupTask.cannotReadSource"), source, e.getMessage()), // $NON-NLS-1$
e);
}
}
} finally {
try {
writer.close();
} catch (Exception e) {
throw new BuildException(MessageFormat.format(// $NON-NLS-1$
Messages.getString("MarkupToHtmlTask.17"), // $NON-NLS-1$
outputFile, e.getMessage()), e);
}
}
}
}
use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder in project mylyn.docs by eclipse.
the class TextileLanguage method processContent.
@Override
public void processContent(MarkupParser parser, String markupContent, boolean asDocument) {
if (preprocessFootnotes) {
boolean previousBlocksOnly = isBlocksOnly();
boolean previousFilterGenerativeContents = isFilterGenerativeContents();
setBlocksOnly(true);
setFilterGenerativeContents(true);
DocumentBuilder builder = parser.getBuilder();
parser.setBuilder(new NoOpDocumentBuilder());
currentState = new TextileContentState();
TextileContentState preprocessingState = currentState;
super.processContent(parser, markupContent, asDocument);
setBlocksOnly(previousBlocksOnly);
setFilterGenerativeContents(previousFilterGenerativeContents);
currentState = new TextileContentState();
currentState.setFootnoteNumbers(preprocessingState.getFootnoteNumbers());
parser.setBuilder(builder);
super.processContent(parser, markupContent, asDocument);
currentState = null;
} else {
currentState = null;
super.processContent(parser, markupContent, asDocument);
}
}
Aggregations