obsidian#MarkdownPreviewView TypeScript Examples
The following examples show how to use
obsidian#MarkdownPreviewView.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 5 votes |
async onloadImpl() {
await this.loadSettings();
this.registerView(VIEW_TYPE_PDF_ANNOTATOR, leaf => new AnnotatorView(leaf, this));
await this.loadResources();
this.codeMirrorInstances = new Set();
this.PdfAnnotation = definePdfAnnotation({
vault: this.app.vault,
plugin: this
});
this.EpubAnnotation = defineEpubAnnotation({
vault: this.app.vault,
plugin: this
});
this.VideoAnnotation = defineVideoAnnotation({
vault: this.app.vault,
plugin: this
});
this.WebAnnotation = defineWebAnnotation({
vault: this.app.vault,
plugin: this
});
this.addMarkdownPostProcessor();
this.registerMonkeyPatches();
this.registerSettingsTab();
this.codeMirrorDropHandler = (editor: CodeMirror.Editor, ev: DragEvent) => {
if (this.dragData !== null && ev.dataTransfer.getData('text/plain') == 'drag-event::hypothesis-highlight') {
ev.preventDefault();
const el = editor.getWrapperElement();
const targetFilePath = this.app.workspace
.getLeavesOfType('markdown')
.filter(x => (x as WorkspaceLeaf & (MarkdownPreviewView | null))?.containerEl?.contains(el))?.[0]
?.getViewState().state.file;
const annotationFile = this.app.vault.getAbstractFileByPath(this.dragData.annotationFilePath);
const targetFile = this.app.vault.getAbstractFileByPath(targetFilePath);
const doc = editor.getDoc();
editor.focus();
editor.setCursor(editor.coordsChar({ left: ev.pageX, top: ev.pageY }));
const newpos = editor.getCursor();
if (annotationFile instanceof TFile && targetFile instanceof TFile) {
const linkString = this.app.fileManager.generateMarkdownLink(
annotationFile,
targetFile.path,
`#^${this.dragData.annotationId}`,
this.dragData.annotationText
);
doc.replaceRange(linkString, newpos);
}
this.dragData = null;
}
};
this.registerCodeMirror(cm => {
this.codeMirrorInstances.add(new WeakRef(cm));
cm.on('drop', this.codeMirrorDropHandler);
});
try {
const ext = this.getDropExtension();
this.registerEditorExtension(ext);
} catch (e) {}
this.addCommand({
id: 'toggle-annotation-mode',
name: 'Toggle Annotation/Markdown Mode',
mobileOnly: false,
callback: () => {
const annotatorView = this.app.workspace.getActiveViewOfType(AnnotatorView);
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (annotatorView != null) {
this.pdfAnnotatorFileModes[(annotatorView.leaf as any).id || annotatorView.file.path] = 'markdown'; // eslint-disable-line
this.setMarkdownView(annotatorView.leaf);
} else if (markdownView != null) {
this.pdfAnnotatorFileModes[(markdownView.leaf as any).id || markdownView.file.path] = // eslint-disable-line
VIEW_TYPE_PDF_ANNOTATOR;
this.setAnnotatorView(markdownView.leaf);
}
}
});
}