use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class MarkupEditor method updateSourceTabLabel.
private void updateSourceTabLabel() {
if (sourceTab != null) {
// bug 270215 carbon shows tooltip in source editing area.
boolean isCarbon = Platform.WS_CARBON.equals(Platform.getWS());
MarkupLanguage markupLanguage = getMarkupLanguage();
if (markupLanguage == null) {
sourceTab.setText(Messages.MarkupEditor_markupSource);
if (!isCarbon) {
sourceTab.setToolTipText(Messages.MarkupEditor_markupSource_tooltip);
}
} else {
sourceTab.setText(NLS.bind(Messages.MarkupEditor_markupSource_named, new Object[] { markupLanguage.getName() }));
if (!isCarbon) {
sourceTab.setToolTipText(NLS.bind(Messages.MarkupEditor_markupSource_tooltip_named, new Object[] { markupLanguage.getName() }));
}
}
}
}
use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class MarkupEditor method updatePreview.
/**
* updates the preview and optionally reveal the section that corresponds to the given outline item.
*
* @param outlineItem
* the outline item, or null
*/
private void updatePreview(final OutlineItem outlineItem) {
if (previewDirty && browser != null) {
Object result = null;
try {
result = browser.evaluate(JAVASCRIPT_GETSCROLLTOP);
} catch (SWTException e) {
// bug 517281 javascript fails for some Linux configurations
logPreviewScrollingFailure(e);
}
final int verticalScrollbarPos = result != null ? ((Number) result).intValue() : 0;
String xhtml = null;
if (document == null) {
// $NON-NLS-1$
xhtml = "<?xml version=\"1.0\" ?><html xmlns=\"http://www.w3.org/1999/xhtml\"><body></body></html>";
} else {
try {
IFile file = getFile();
// $NON-NLS-1$
String title = file == null ? "" : file.getName();
if (title.lastIndexOf('.') != -1) {
title = title.substring(0, title.lastIndexOf('.'));
}
StringWriter writer = new StringWriter();
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer) {
@Override
protected void emitAnchorHref(String href) {
if (href != null && href.startsWith("#")) {
// $NON-NLS-1$
// $NON-NLS-1$
writer.writeAttribute(// $NON-NLS-1$
"onclick", // $NON-NLS-1$
String.format("javascript: window.location.hash = '%s'; return false;", href));
// $NON-NLS-1$//$NON-NLS-2$
writer.writeAttribute("href", "#");
} else {
super.emitAnchorHref(href);
}
}
@Override
public void beginHeading(int level, Attributes attributes) {
attributes.appendCssClass(CSS_CLASS_EDITOR_PREVIEW);
super.beginHeading(level, attributes);
}
@Override
public void beginBlock(BlockType type, Attributes attributes) {
attributes.appendCssClass(CSS_CLASS_EDITOR_PREVIEW);
super.beginBlock(type, attributes);
}
};
builder.setTitle(title);
IPath location = file == null ? null : file.getLocation();
if (location != null) {
builder.setBaseInHead(true);
builder.setBase(location.removeLastSegments(1).toFile().toURI());
}
String css = WikiTextUiPlugin.getDefault().getPreferences().getMarkupViewerCss();
if (css != null && css.length() > 0) {
builder.addCssStylesheet(new HtmlDocumentBuilder.Stylesheet(new StringReader(css)));
}
MarkupLanguage markupLanguage = getMarkupLanguage();
if (markupLanguage != null) {
markupLanguage = markupLanguage.clone();
if (markupLanguage instanceof AbstractMarkupLanguage) {
((AbstractMarkupLanguage) markupLanguage).setEnableMacros(true);
}
if (markupLanguage instanceof AbstractMarkupLanguage) {
AbstractMarkupLanguage language = (AbstractMarkupLanguage) markupLanguage;
language.setFilterGenerativeContents(false);
language.setBlocksOnly(false);
}
MarkupParser markupParser = new MarkupParser();
markupParser.setBuilder(builder);
markupParser.setMarkupLanguage(markupLanguage);
markupParser.parse(document.get());
} else {
builder.beginDocument();
builder.beginBlock(BlockType.PREFORMATTED, new Attributes());
builder.characters(document.get());
builder.endBlock();
builder.endDocument();
}
xhtml = writer.toString();
} catch (Exception e) {
StringWriter stackTrace = new StringWriter();
PrintWriter writer = new PrintWriter(stackTrace);
e.printStackTrace(writer);
writer.close();
StringWriter documentWriter = new StringWriter();
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(documentWriter);
builder.beginDocument();
builder.beginBlock(BlockType.PREFORMATTED, new Attributes());
builder.characters(stackTrace.toString());
builder.endBlock();
builder.endDocument();
xhtml = documentWriter.toString();
}
}
browser.addProgressListener(new ProgressAdapter() {
@Override
public void completed(ProgressEvent event) {
browser.removeProgressListener(this);
if (outlineItem != null) {
revealInBrowser(outlineItem);
} else {
// $NON-NLS-1$
browser.execute(String.format("window.scrollTo(0,%d);", verticalScrollbarPos));
}
}
});
browser.setText(xhtml);
previewDirty = false;
} else if (outlineItem != null && browser != null) {
revealInBrowser(outlineItem);
}
}
use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class ServiceLocatorTest method assertKnownMarkupLanguage.
protected void assertKnownMarkupLanguage() {
MarkupLanguage markupLanguage = locator.getMarkupLanguage(MockMarkupLanguage.class.getSimpleName());
assertNotNull(markupLanguage);
assertEquals(new MockMarkupLanguage().getName(), markupLanguage.getName());
}
use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class OsgiServiceLocatorTest method assertLoadsMarkupLanguageFromServicesPath.
void assertLoadsMarkupLanguageFromServicesPath(String servicesFolder) {
OsgiServiceLocator serviceLocator = createOsgiServiceLocator(createBundleWithLanguage(servicesFolder, MockMarkupLanguage.class));
MarkupLanguage markupLanguage = serviceLocator.getMarkupLanguage(MockMarkupLanguage.class.getSimpleName());
assertNotNull(markupLanguage);
}
use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class MarkupLanguageProviderTest method getMarkupLanguagesNull.
@Test
public void getMarkupLanguagesNull() {
MarkupLanguageProvider provider = new MarkupLanguageProvider() {
@Override
protected Set<MarkupLanguage> loadMarkupLanguages() {
return null;
}
};
thrown.expect(NullPointerException.class);
thrown.expectMessage("loadMarkupLanguages() must not return null");
provider.getMarkupLanguages();
}
Aggregations