Browse Source

implement syntax highlighting

master
Silberengel 1 week ago
parent
commit
27b3c7cab2
  1. 129
      package-lock.json
  2. 10
      package.json
  3. 33
      src/main.ts

129
package-lock.json generated

@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
"version": "0.1.0",
"license": "MIT",
"dependencies": {
"@codemirror/lang-yaml": "^6.1.2",
"codemirror-asciidoc": "^2.0.1",
"js-yaml": "^4.1.0",
"nostr-tools": "^2.20.0"
},
@ -24,6 +26,68 @@ @@ -24,6 +26,68 @@
"typescript": "5.3.3"
}
},
"node_modules/@codemirror/autocomplete": {
"version": "6.20.0",
"resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.20.0.tgz",
"integrity": "sha512-bOwvTOIJcG5FVo5gUUupiwYh8MioPLQ4UcqbcRf7UQ98X90tCa9E1kZ3Z7tqwpZxYyOvh1YTYbmZE9RTfTp5hg==",
"license": "MIT",
"dependencies": {
"@codemirror/language": "^6.0.0",
"@codemirror/state": "^6.0.0",
"@codemirror/view": "^6.17.0",
"@lezer/common": "^1.0.0"
}
},
"node_modules/@codemirror/lang-yaml": {
"version": "6.1.2",
"resolved": "https://registry.npmjs.org/@codemirror/lang-yaml/-/lang-yaml-6.1.2.tgz",
"integrity": "sha512-dxrfG8w5Ce/QbT7YID7mWZFKhdhsaTNOYjOkSIMt1qmC4VQnXSDSYVHHHn8k6kJUfIhtLo8t1JJgltlxWdsITw==",
"license": "MIT",
"dependencies": {
"@codemirror/autocomplete": "^6.0.0",
"@codemirror/language": "^6.0.0",
"@codemirror/state": "^6.0.0",
"@lezer/common": "^1.2.0",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.0.0",
"@lezer/yaml": "^1.0.0"
}
},
"node_modules/@codemirror/language": {
"version": "6.12.1",
"resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.12.1.tgz",
"integrity": "sha512-Fa6xkSiuGKc8XC8Cn96T+TQHYj4ZZ7RdFmXA3i9xe/3hLHfwPZdM+dqfX0Cp0zQklBKhVD8Yzc8LS45rkqcwpQ==",
"license": "MIT",
"dependencies": {
"@codemirror/state": "^6.0.0",
"@codemirror/view": "^6.23.0",
"@lezer/common": "^1.5.0",
"@lezer/highlight": "^1.0.0",
"@lezer/lr": "^1.0.0",
"style-mod": "^4.0.0"
}
},
"node_modules/@codemirror/state": {
"version": "6.5.4",
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.4.tgz",
"integrity": "sha512-8y7xqG/hpB53l25CIoit9/ngxdfoG+fx+V3SHBrinnhOtLvKHRyAJJuHzkWrR4YXXLX8eXBsejgAAxHUOdW1yw==",
"license": "MIT",
"dependencies": {
"@marijn/find-cluster-break": "^1.0.0"
}
},
"node_modules/@codemirror/view": {
"version": "6.39.11",
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.39.11.tgz",
"integrity": "sha512-bWdeR8gWM87l4DB/kYSF9A+dVackzDb/V56Tq7QVrQ7rn86W0rgZFtlL3g3pem6AeGcb9NQNoy3ao4WpW4h5tQ==",
"license": "MIT",
"dependencies": {
"@codemirror/state": "^6.5.0",
"crelt": "^1.0.6",
"style-mod": "^4.1.0",
"w3c-keyname": "^2.2.4"
}
},
"node_modules/@esbuild/android-arm": {
"version": "0.17.3",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.3.tgz",
@ -398,6 +462,47 @@ @@ -398,6 +462,47 @@
"node": ">=12"
}
},
"node_modules/@lezer/common": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.0.tgz",
"integrity": "sha512-PNGcolp9hr4PJdXR4ix7XtixDrClScvtSCYW3rQG106oVMOOI+jFb+0+J3mbeL/53g1Zd6s0kJzaw6Ri68GmAA==",
"license": "MIT"
},
"node_modules/@lezer/highlight": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.3.tgz",
"integrity": "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==",
"license": "MIT",
"dependencies": {
"@lezer/common": "^1.3.0"
}
},
"node_modules/@lezer/lr": {
"version": "1.4.8",
"resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.8.tgz",
"integrity": "sha512-bPWa0Pgx69ylNlMlPvBPryqeLYQjyJjqPx+Aupm5zydLIF3NE+6MMLT8Yi23Bd9cif9VS00aUebn+6fDIGBcDA==",
"license": "MIT",
"dependencies": {
"@lezer/common": "^1.0.0"
}
},
"node_modules/@lezer/yaml": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@lezer/yaml/-/yaml-1.0.3.tgz",
"integrity": "sha512-GuBLekbw9jDBDhGur82nuwkxKQ+a3W5H0GfaAthDXcAu+XdpS43VlnxA9E9hllkpSP5ellRDKjLLj7Lu9Wr6xA==",
"license": "MIT",
"dependencies": {
"@lezer/common": "^1.2.0",
"@lezer/highlight": "^1.0.0",
"@lezer/lr": "^1.4.0"
}
},
"node_modules/@marijn/find-cluster-break": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz",
"integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==",
"license": "MIT"
},
"node_modules/@noble/ciphers": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.5.3.tgz",
@ -817,6 +922,18 @@ @@ -817,6 +922,18 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/codemirror-asciidoc": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/codemirror-asciidoc/-/codemirror-asciidoc-2.0.1.tgz",
"integrity": "sha512-h6Xhj+ZsWh/DTNE3xMfRv9edufchsVVwPED7wSGMeEdoYk/UtCZmwRGH0ZZQkr43aNVF3tWGLZJGT+cAeYgUIg==",
"license": "BSD"
},
"node_modules/crelt": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz",
"integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==",
"license": "MIT"
},
"node_modules/debug": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
@ -1311,6 +1428,12 @@ @@ -1311,6 +1428,12 @@
"node": ">=8"
}
},
"node_modules/style-mod": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.3.tgz",
"integrity": "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ==",
"license": "MIT"
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
@ -1374,6 +1497,12 @@ @@ -1374,6 +1497,12 @@
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
"dev": true,
"license": "MIT"
},
"node_modules/w3c-keyname": {
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
"integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==",
"license": "MIT"
}
}
}

10
package.json

@ -10,13 +10,13 @@ @@ -10,13 +10,13 @@
},
"keywords": [],
"author": "Silberengel",
"homepage": "https://gitcitadel.com",
"homepage": "https://gitcitadel.com",
"license": "MIT",
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"@types/js-yaml": "^4.0.9",
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"obsidian": "latest",
@ -24,7 +24,9 @@ @@ -24,7 +24,9 @@
"typescript": "5.3.3"
},
"dependencies": {
"nostr-tools": "^2.20.0",
"js-yaml": "^4.1.0"
"@codemirror/lang-yaml": "^6.1.2",
"codemirror-asciidoc": "^2.0.1",
"js-yaml": "^4.1.0",
"nostr-tools": "^2.20.0"
}
}

33
src/main.ts

@ -12,6 +12,13 @@ import { getWriteRelays } from "./relayManager"; @@ -12,6 +12,13 @@ import { getWriteRelays } from "./relayManager";
import { parseAsciiDocStructure, isAsciiDocDocument } from "./asciidocParser";
import { normalizeSecretKey, getPubkeyFromPrivkey } from "./nostr/eventBuilder";
import { safeConsoleError, safeConsoleLog, verifyEventSecurity } from "./utils/security";
// CodeMirror language packages for syntax highlighting
// These will be bundled with the plugin
import { yaml } from "@codemirror/lang-yaml";
import { asciidoc } from "codemirror-asciidoc";
import { StreamLanguage } from "@codemirror/language";
import { Extension } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
export default class ScriptoriumPlugin extends Plugin {
settings!: ScriptoriumSettings;
@ -20,6 +27,25 @@ export default class ScriptoriumPlugin extends Plugin { @@ -20,6 +27,25 @@ export default class ScriptoriumPlugin extends Plugin {
await this.loadSettings();
await this.loadPrivateKey();
// Register AsciiDoc file extensions so Obsidian can open them
// This tells Obsidian to treat .adoc and .asciidoc files as editable text files
// Using "text" view type so they open as plain text editors in Obsidian
this.registerExtensions(["adoc", "asciidoc"], "text");
// Register YAML file extensions so Obsidian can open metadata files
// This tells Obsidian to treat .yml and .yaml files as editable text files
this.registerExtensions(["yml", "yaml"], "text");
// Register editor extensions for syntax highlighting
// Apply YAML and AsciiDoc language modes
// Note: Markdown files (.md) use Obsidian's default "markdown" view type
// which has built-in syntax highlighting, so they won't be affected by these extensions
// These extensions only apply to files registered with "text" view type (.yml, .yaml, .adoc, .asciidoc)
this.registerEditorExtension([
yaml(),
StreamLanguage.define(asciidoc)
]);
// Add settings tab
this.addSettingTab(new ScriptoriumSettingTab(this.app, this));
@ -168,13 +194,6 @@ export default class ScriptoriumPlugin extends Plugin { @@ -168,13 +194,6 @@ export default class ScriptoriumPlugin extends Plugin {
await this.app.vault.createFolder(fullPath);
}
// Refresh file explorer to show new folders
// @ts-ignore - refresh file explorer
if (this.app.workspace.leftSplit) {
// @ts-ignore
this.app.workspace.leftSplit.refresh();
}
return fullPath;
}

Loading…
Cancel
Save