Started
This commit is contained in:
parent
f85d2b74b5
commit
17c28d33b4
19
main.ts
19
main.ts
|
@ -17,7 +17,7 @@ export default class MyPlugin extends Plugin {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
|
|
||||||
// This creates an icon in the left ribbon.
|
// This creates an icon in the left ribbon.
|
||||||
const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => {
|
const ribbonIconEl = this.addRibbonIcon('dice', 'Coders Plugin', (evt: MouseEvent) => {
|
||||||
// Called when the user clicks the icon.
|
// Called when the user clicks the icon.
|
||||||
new Notice('This is a notice!');
|
new Notice('This is a notice!');
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,7 @@ export default class MyPlugin extends Plugin {
|
||||||
|
|
||||||
// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
|
// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
|
||||||
const statusBarItemEl = this.addStatusBarItem();
|
const statusBarItemEl = this.addStatusBarItem();
|
||||||
statusBarItemEl.setText('Status Bar Text');
|
statusBarItemEl.setText('Nisse!');
|
||||||
|
|
||||||
// This adds a simple command that can be triggered anywhere
|
// This adds a simple command that can be triggered anywhere
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
|
@ -38,11 +38,20 @@ export default class MyPlugin extends Plugin {
|
||||||
});
|
});
|
||||||
// This adds an editor command that can perform some operation on the current editor instance
|
// This adds an editor command that can perform some operation on the current editor instance
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
id: 'sample-editor-command',
|
id: 'Code block',
|
||||||
name: 'Sample editor command',
|
name: 'Sample editor command',
|
||||||
editorCallback: (editor: Editor, view: MarkdownView) => {
|
editorCallback: (editor: Editor, view: MarkdownView) => {
|
||||||
console.log(editor.getSelection());
|
const selection = editor.getSelection();
|
||||||
editor.replaceSelection('Sample Editor Command');
|
const hljs = require('highlight.js/lib/common');
|
||||||
|
console.log(hljs);
|
||||||
|
const highlight = hljs.highlightAuto(selection, ["java", "javascript", "sql", "kotlin", "python", "groovy", "xml", "html", "yaml", "typescript"]);
|
||||||
|
const language = highlight.language;
|
||||||
|
console.log(highlight);
|
||||||
|
const sel = selection.length == 0 ? '\n' : selection;
|
||||||
|
const lang = selection.length == 0 || language == undefined ? '' : language;
|
||||||
|
console.log(sel);
|
||||||
|
|
||||||
|
editor.replaceSelection('```' + lang + '\n' + sel + '\n```' + '\n');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// This adds a complex command that can check whether the current state of the app allows execution of the command
|
// This adds a complex command that can check whether the current state of the app allows execution of the command
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,6 +17,7 @@
|
||||||
"@typescript-eslint/parser": "^5.2.0",
|
"@typescript-eslint/parser": "^5.2.0",
|
||||||
"builtin-modules": "^3.2.0",
|
"builtin-modules": "^3.2.0",
|
||||||
"esbuild": "0.13.12",
|
"esbuild": "0.13.12",
|
||||||
|
"highlight.js": "^11.5.1",
|
||||||
"obsidian": "latest",
|
"obsidian": "latest",
|
||||||
"tslib": "2.3.1",
|
"tslib": "2.3.1",
|
||||||
"typescript": "4.4.4"
|
"typescript": "4.4.4"
|
||||||
|
|
Loading…
Reference in New Issue