mirror of
https://github.com/cberane/obsidian-material-symbols.git
synced 2026-07-22 07:20:26 +00:00
- configured manifest.json - changed README.md to give relevant information about the basic usage - added webfont to styles.css with additional classes
39 lines
1 KiB
TypeScript
39 lines
1 KiB
TypeScript
import {Editor, MarkdownView, Plugin} from 'obsidian';
|
|
|
|
export default class MaterialSymbolsPlugin extends Plugin {
|
|
async onload() {
|
|
this.addCommand({
|
|
id: 'add-symbol',
|
|
name: 'Add symbol',
|
|
editorCallback: (editor: Editor, view: MarkdownView) => {
|
|
let position = editor.getCursor('from')
|
|
// add icon
|
|
editor.replaceSelection('<span class="mso"></span>');
|
|
// move cursor into the tag
|
|
editor.setCursor({
|
|
line: position.line,
|
|
ch: position.ch + 18 // opening tag has 18 characters
|
|
});
|
|
}
|
|
});
|
|
|
|
this.addCommand({
|
|
id: 'add-symbol-single-quotes',
|
|
name: 'Add symbol (class single-quoted)',
|
|
editorCallback: (editor: Editor, view: MarkdownView) => {
|
|
let preInsertPosition = editor.getCursor('from')
|
|
// add icon
|
|
editor.replaceSelection("<span class='mso'></span>");
|
|
// move cursor into the tag
|
|
editor.setCursor({
|
|
line: preInsertPosition.line,
|
|
ch: preInsertPosition.ch + 18 // opening tag has 18 characters
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
onunload() {
|
|
// do nothing
|
|
}
|
|
}
|