use of org.eclipse.mylyn.internal.wikitext.ui.viewer.HtmlTextPresentationParser in project mylyn.docs by eclipse.
the class HtmlViewer method parse.
protected ParseResult parse(String htmlText) {
initPainter();
ParseResult result = new ParseResult();
result.textPresentation = new TextPresentation();
HtmlTextPresentationParser parser = new HtmlTextPresentationParser();
if (stylesheet != null) {
parser.setStylesheet(stylesheet);
}
if (displayImages) {
parser.setImageCache(imageCache);
parser.setEnableImages(displayImages);
}
parser.setPresentation(result.textPresentation);
parser.setDefaultFont(getTextWidget().getFont());
parser.setDefaultMonospaceFont(defaultMonospaceFont);
result.annotationModel = new AnnotationModel();
parser.setAnnotationModel(result.annotationModel);
GC gc = new GC(getTextWidget());
try {
parser.setGC(gc);
parser.parse(htmlText);
} catch (SAXException e) {
throw new IllegalStateException(e);
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
gc.dispose();
}
result.text = parser.getText();
return result;
}
use of org.eclipse.mylyn.internal.wikitext.ui.viewer.HtmlTextPresentationParser in project mylyn.docs by eclipse.
the class HtmlTextPresenter method updatePresentation.
public String updatePresentation(Drawable drawable, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight) {
if (hoverInfo == null || hoverInfo.length() == 0) {
return hoverInfo;
}
HtmlTextPresentationParser parser = new HtmlTextPresentationParser();
parser.setPresentation(presentation);
parser.setDefaultFont(JFaceResources.getFontRegistry().defaultFont());
String html = hoverInfo;
if (!HTML_OPEN_TAG_PATTERN.matcher(html).find()) {
// $NON-NLS-1$ //$NON-NLS-2$
html = "<html><body>" + html + "</body></html>";
}
GC gc = new GC(drawable);
try {
// $NON-NLS-1$ //$NON-NLS-2$
html = html.replaceAll("<br>", "<br/>");
parser.setMaxWidth(maxWidth);
parser.setGC(gc);
parser.parse(html);
return parser.getText();
} catch (Exception e) {
return exceptionToHoverInfo(hoverInfo, presentation, e);
} finally {
gc.dispose();
}
}
use of org.eclipse.mylyn.internal.wikitext.ui.viewer.HtmlTextPresentationParser in project mylyn.docs by eclipse.
the class MarkupViewerPreferencePage method updatePreview.
private void updatePreview() {
TextPresentation textPresentation = new TextPresentation();
HtmlTextPresentationParser parser = new HtmlTextPresentationParser();
parser.setDefaultFont(previewViewer.getTextWidget().getFont());
parser.setAnnotationModel(previewViewer.getAnnotationModel());
parser.setPresentation(textPresentation);
parser.setStylesheet(new CssParser().parse(sourceViewer.getDocument().get()));
GC gc = new GC(previewViewer.getTextWidget());
try {
parser.setGC(gc);
parser.parse(createPreviewHtml());
} catch (SAXException e) {
throw new IllegalStateException(e);
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
gc.dispose();
}
htmlViewerConfiguration.setTextPresentation(textPresentation);
previewViewer.changeTextPresentation(textPresentation, true);
}
Aggregations