Search in sources :

Example 1 with HtmlTextPresentationParser

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;
}
Also used : HtmlTextPresentationParser(org.eclipse.mylyn.internal.wikitext.ui.viewer.HtmlTextPresentationParser) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IOException(java.io.IOException) GC(org.eclipse.swt.graphics.GC) TextPresentation(org.eclipse.jface.text.TextPresentation) SAXException(org.xml.sax.SAXException)

Example 2 with HtmlTextPresentationParser

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();
    }
}
Also used : HtmlTextPresentationParser(org.eclipse.mylyn.internal.wikitext.ui.viewer.HtmlTextPresentationParser) GC(org.eclipse.swt.graphics.GC)

Example 3 with HtmlTextPresentationParser

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);
}
Also used : HtmlTextPresentationParser(org.eclipse.mylyn.internal.wikitext.ui.viewer.HtmlTextPresentationParser) IOException(java.io.IOException) GC(org.eclipse.swt.graphics.GC) TextPresentation(org.eclipse.jface.text.TextPresentation) CssParser(org.eclipse.mylyn.wikitext.parser.css.CssParser) SAXException(org.xml.sax.SAXException)

Aggregations

HtmlTextPresentationParser (org.eclipse.mylyn.internal.wikitext.ui.viewer.HtmlTextPresentationParser)3 GC (org.eclipse.swt.graphics.GC)3 IOException (java.io.IOException)2 TextPresentation (org.eclipse.jface.text.TextPresentation)2 SAXException (org.xml.sax.SAXException)2 AnnotationModel (org.eclipse.jface.text.source.AnnotationModel)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 CssParser (org.eclipse.mylyn.wikitext.parser.css.CssParser)1