use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class TWikiLanguageTest method testDiscoverable.
public void testDiscoverable() {
MarkupLanguage language = ServiceLocator.getInstance().getMarkupLanguage("TWiki");
assertNotNull(language);
assertTrue(language instanceof TWikiLanguage);
}
use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class HelpContent method getContent.
/**
* Get the help content, which may be formatted using HTML markup. If HTML markup is used, the content must be
* well-formed HTML.
*/
@SuppressWarnings("serial")
public String getContent() throws IOException {
try {
URL resource = getResource();
String content = Resources.toString(resource, StandardCharsets.UTF_8);
if (resourceContentLanguage == null || "html".equalsIgnoreCase(resourceContentLanguage)) {
// $NON-NLS-1$
return content;
}
MarkupLanguage markupLanguage = WikiText.getMarkupLanguage(resourceContentLanguage);
if (markupLanguage == null) {
throw new IOException(NLS.bind(Messages.HelpContent_noSuchMarkupLanguage, new Object[] { resourceContentLanguage }));
}
MarkupParser markupParser = new MarkupParser(markupLanguage);
return markupParser.parseToHtml(content);
} catch (final Exception e) {
throw new IOException(NLS.bind(Messages.HelpContent_cannotAccessContent, new Object[] { provider.getSymbolicName(), resourcePath, e.getMessage() })) {
@Override
public Throwable getCause() {
return e;
}
};
}
}
use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class AbstractMarkupResourceHandler method execute.
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = selection;
if (currentSelection == null) {
try {
currentSelection = computeSelection(event);
} catch (Exception e) {
// ignore
}
}
if (currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Iterator<Object> it = structuredSelection.iterator();
while (it.hasNext()) {
Object o = it.next();
IFile file = null;
if (o instanceof IAdaptable) {
file = ((IAdaptable) o).getAdapter(IFile.class);
}
if (file != null) {
String name = file.getName();
int idxOfDot = name.lastIndexOf('.');
if (idxOfDot != -1) {
name = name.substring(0, idxOfDot);
}
// use a temporary so that the setting does not stick even if the handler is reused.
MarkupLanguage prev = markupLanguage;
try {
if (markupLanguage == null) {
markupLanguage = MarkupEditor.loadMarkupLanguagePreference(file);
if (markupLanguage == null) {
markupLanguage = WikiText.getMarkupLanguageForFilename(file.getName());
}
if (markupLanguage == null) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.AbstractMarkupResourceHandler_unexpectedError, NLS.bind(Messages.AbstractMarkupResourceHandler_markupLanguageMappingFailed, new Object[] { file.getName() }));
return null;
}
}
handleFile(event, file, name);
} finally {
markupLanguage = prev;
}
}
}
}
return null;
}
use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class WikiTextSourceEditor method updateOutline.
private void updateOutline() {
if (!outlineDirty) {
return;
}
if (getSourceViewer().getTextWidget().isDisposed()) {
return;
}
// we maintain the outline even if the outline page is not in use, which allows us to use the outline for
// content assist and other things
MarkupLanguage markupLanguage = getMarkupLanguage();
if (markupLanguage == null) {
return;
}
final MarkupLanguage language = markupLanguage.clone();
final Display display = getSourceViewer().getTextWidget().getDisplay();
final String content = document.get();
final int contentGeneration;
synchronized (WikiTextSourceEditor.this) {
contentGeneration = documentGeneration;
initializeOutlineParser();
}
// we parse the outline in another thread so that the UI remains responsive
Job parseOutlineJob = new // $NON-NLS-1$
Job(// $NON-NLS-1$
WikiTextSourceEditor.class.getSimpleName() + "#updateOutline") {
@Override
protected IStatus run(IProgressMonitor monitor) {
outlineParser.setMarkupLanguage(language);
if (shouldCancel()) {
return Status.CANCEL_STATUS;
}
final OutlineItem rootItem = outlineParser.parse(content);
if (shouldCancel()) {
return Status.CANCEL_STATUS;
}
display.asyncExec(new Runnable() {
public void run() {
updateOutline(contentGeneration, rootItem);
}
});
return Status.OK_STATUS;
}
private boolean shouldCancel() {
synchronized (WikiTextSourceEditor.this) {
if (contentGeneration != documentGeneration) {
return true;
}
}
return false;
}
};
parseOutlineJob.setPriority(Job.INTERACTIVE);
parseOutlineJob.setSystem(true);
parseOutlineJob.schedule();
}
use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.
the class WikiTextSourceEditor method setMarkupLanguage.
/**
* set the markup language. If unspecified, it's assumed to be Textile.
*
* @since 3.0
*/
public void setMarkupLanguage(MarkupLanguage markupLanguage) {
this.markupLanguage = markupLanguage;
if (this.markupLanguage instanceof AbstractMarkupLanguage) {
((AbstractMarkupLanguage) this.markupLanguage).setEnableMacros(false);
}
sourceViewerConfiguration.setMarkupLanguage(markupLanguage);
IDocumentProvider documentProvider = getDocumentProvider();
if (documentProvider instanceof WikiTextDocumentProvider) {
((WikiTextDocumentProvider) documentProvider).setMarkupLanguage(markupLanguage);
}
if (getEditorInput() != null) {
IDocument document = documentProvider.getDocument(getEditorInput());
IDocumentPartitioner partitioner = document.getDocumentPartitioner();
if (partitioner instanceof FastMarkupPartitioner) {
final FastMarkupPartitioner fastMarkupPartitioner = (FastMarkupPartitioner) partitioner;
fastMarkupPartitioner.setMarkupLanguage(markupLanguage);
}
}
if (viewer != null) {
viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
}
if (getSourceViewer() != null) {
getSourceViewer().invalidateTextPresentation();
}
}
Aggregations