From 0df416565293bdeb15e85b6b4e68dc0d235a99c1 Mon Sep 17 00:00:00 2001 From: Gavin Rigsby Date: Mon, 15 Jul 2024 14:16:12 -0700 Subject: [PATCH] feat: Added more code files & function filtering --- data.json | 14 - esbuild.config.mjs | 1 - package-lock.json | 1140 ++++++++++++++++++++++++++++++++++- src/codeFilesSettingsTab.ts | 11 - src/constants.ts | 256 +++++++- src/createCodeFileModal.ts | 6 +- src/main.ts | 57 +- src/mountCodeEditor.ts | 1 - src/settings.ts | 6 - src/utils.ts | 3 +- 10 files changed, 1401 insertions(+), 94 deletions(-) diff --git a/data.json b/data.json index ede9599..c1445e1 100644 --- a/data.json +++ b/data.json @@ -1,18 +1,4 @@ { - "extensions": [ - "ts", - "js", - "py", - "css", - "c", - "cpp", - "go", - "rs", - "java", - "lua", - "php", - "sh" - ], "folding": true, "allowAllFiletypes": false, "lineNumbers": true, diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 054196c..71934f3 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -19,7 +19,6 @@ let renamePlugin = { const mainData = fs.readFileSync('main.css', 'utf8'); const combinedData = mystyleData + '\n' + mainData; fs.writeFileSync('styles.css', combinedData, 'utf8'); - console.log('styles.css create success.'); }) }, } diff --git a/package-lock.json b/package-lock.json index ec26555..0486a04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,7 @@ { "name": "obsidian-embed-and-edit-code", "version": "1.0.0", - "lockfileVersion": 3, + "lockfileVersion": 2, "requires": true, "packages": { "": { @@ -41,21 +41,6 @@ "w3c-keyname": "^2.2.4" } }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.17.3", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@eslint/eslintrc": { "version": "1.3.0", "dev": true, @@ -491,11 +476,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, - "license": "MIT", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -940,9 +926,10 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, - "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -1156,8 +1143,9 @@ }, "node_modules/is-number": { "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true, - "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -1650,8 +1638,9 @@ }, "node_modules/to-regex-range": { "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, - "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, @@ -1787,5 +1776,1110 @@ "url": "https://github.com/sponsors/sindresorhus" } } + }, + "dependencies": { + "@codemirror/state": { + "version": "6.1.1", + "dev": true, + "peer": true + }, + "@codemirror/view": { + "version": "6.2.0", + "dev": true, + "peer": true, + "requires": { + "@codemirror/state": "^6.0.0", + "style-mod": "^4.0.0", + "w3c-keyname": "^2.2.4" + } + }, + "@eslint/eslintrc": { + "version": "1.3.0", + "dev": true, + "peer": true, + "requires": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^9.3.2", + "globals": "^13.15.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + } + }, + "@humanwhocodes/config-array": { + "version": "0.10.4", + "dev": true, + "peer": true, + "requires": { + "@humanwhocodes/object-schema": "^1.2.1", + "debug": "^4.1.1", + "minimatch": "^3.0.4" + } + }, + "@humanwhocodes/gitignore-to-minimatch": { + "version": "1.0.2", + "dev": true, + "peer": true + }, + "@humanwhocodes/object-schema": { + "version": "1.2.1", + "dev": true, + "peer": true + }, + "@jridgewell/gen-mapping": { + "version": "0.3.3", + "dev": true, + "requires": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/resolve-uri": { + "version": "3.1.1", + "dev": true + }, + "@jridgewell/set-array": { + "version": "1.1.2", + "dev": true + }, + "@jridgewell/source-map": { + "version": "0.3.5", + "dev": true, + "requires": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.20", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "@nodelib/fs.scandir": { + "version": "2.1.5", + "dev": true, + "requires": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + } + }, + "@nodelib/fs.stat": { + "version": "2.0.5", + "dev": true + }, + "@nodelib/fs.walk": { + "version": "1.2.8", + "dev": true, + "requires": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + } + }, + "@types/codemirror": { + "version": "5.60.8", + "resolved": "https://registry.npmjs.org/@types/codemirror/-/codemirror-5.60.8.tgz", + "integrity": "sha512-VjFgDF/eB+Aklcy15TtOTLQeMjTo07k7KAjql8OK5Dirr7a6sJY4T1uVBDuTVG9VEmn1uUsohOpYnVfgC6/jyw==", + "dev": true, + "requires": { + "@types/tern": "*" + } + }, + "@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true + }, + "@types/json-schema": { + "version": "7.0.11", + "dev": true + }, + "@types/node": { + "version": "16.18.68", + "dev": true + }, + "@types/tern": { + "version": "0.23.9", + "resolved": "https://registry.npmjs.org/@types/tern/-/tern-0.23.9.tgz", + "integrity": "sha512-ypzHFE/wBzh+BlH6rrBgS5I/Z7RD21pGhZ2rltb/+ZrVM1awdZwjx7hE5XfuYgHWk9uvV5HLZN3SloevCAp3Bw==", + "dev": true, + "requires": { + "@types/estree": "*" + } + }, + "@typescript-eslint/eslint-plugin": { + "version": "5.29.0", + "dev": true, + "requires": { + "@typescript-eslint/scope-manager": "5.29.0", + "@typescript-eslint/type-utils": "5.29.0", + "@typescript-eslint/utils": "5.29.0", + "debug": "^4.3.4", + "functional-red-black-tree": "^1.0.1", + "ignore": "^5.2.0", + "regexpp": "^3.2.0", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + } + }, + "@typescript-eslint/parser": { + "version": "5.29.0", + "dev": true, + "requires": { + "@typescript-eslint/scope-manager": "5.29.0", + "@typescript-eslint/types": "5.29.0", + "@typescript-eslint/typescript-estree": "5.29.0", + "debug": "^4.3.4" + } + }, + "@typescript-eslint/scope-manager": { + "version": "5.29.0", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.29.0", + "@typescript-eslint/visitor-keys": "5.29.0" + } + }, + "@typescript-eslint/type-utils": { + "version": "5.29.0", + "dev": true, + "requires": { + "@typescript-eslint/utils": "5.29.0", + "debug": "^4.3.4", + "tsutils": "^3.21.0" + } + }, + "@typescript-eslint/types": { + "version": "5.29.0", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "5.29.0", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.29.0", + "@typescript-eslint/visitor-keys": "5.29.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + } + }, + "@typescript-eslint/utils": { + "version": "5.29.0", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.9", + "@typescript-eslint/scope-manager": "5.29.0", + "@typescript-eslint/types": "5.29.0", + "@typescript-eslint/typescript-estree": "5.29.0", + "eslint-scope": "^5.1.1", + "eslint-utils": "^3.0.0" + } + }, + "@typescript-eslint/visitor-keys": { + "version": "5.29.0", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.29.0", + "eslint-visitor-keys": "^3.3.0" + } + }, + "acorn": { + "version": "8.11.2", + "dev": true + }, + "acorn-jsx": { + "version": "5.3.2", + "dev": true, + "peer": true, + "requires": {} + }, + "ajv": { + "version": "6.12.6", + "dev": true, + "peer": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "ansi-regex": { + "version": "5.0.1", + "dev": true, + "peer": true + }, + "ansi-styles": { + "version": "4.3.0", + "dev": true, + "peer": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "argparse": { + "version": "2.0.1", + "dev": true, + "peer": true + }, + "array-union": { + "version": "2.1.0", + "dev": true + }, + "balanced-match": { + "version": "1.0.2", + "dev": true, + "peer": true + }, + "brace-expansion": { + "version": "1.1.11", + "dev": true, + "peer": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "requires": { + "fill-range": "^7.1.1" + } + }, + "buffer-from": { + "version": "1.1.2", + "dev": true + }, + "builtin-modules": { + "version": "3.3.0", + "dev": true + }, + "callsites": { + "version": "3.1.0", + "dev": true, + "peer": true + }, + "chalk": { + "version": "4.1.2", + "dev": true, + "peer": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "dev": true, + "peer": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "dev": true, + "peer": true + }, + "commander": { + "version": "2.20.3", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "dev": true, + "peer": true + }, + "cross-spawn": { + "version": "7.0.3", + "dev": true, + "peer": true, + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, + "debug": { + "version": "4.3.4", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "deep-is": { + "version": "0.1.4", + "dev": true, + "peer": true + }, + "dir-glob": { + "version": "3.0.1", + "dev": true, + "requires": { + "path-type": "^4.0.0" + } + }, + "doctrine": { + "version": "3.0.0", + "dev": true, + "peer": true, + "requires": { + "esutils": "^2.0.2" + } + }, + "esbuild": { + "version": "0.17.3", + "dev": true, + "requires": { + "@esbuild/android-arm": "0.17.3", + "@esbuild/android-arm64": "0.17.3", + "@esbuild/android-x64": "0.17.3", + "@esbuild/darwin-arm64": "0.17.3", + "@esbuild/darwin-x64": "0.17.3", + "@esbuild/freebsd-arm64": "0.17.3", + "@esbuild/freebsd-x64": "0.17.3", + "@esbuild/linux-arm": "0.17.3", + "@esbuild/linux-arm64": "0.17.3", + "@esbuild/linux-ia32": "0.17.3", + "@esbuild/linux-loong64": "0.17.3", + "@esbuild/linux-mips64el": "0.17.3", + "@esbuild/linux-ppc64": "0.17.3", + "@esbuild/linux-riscv64": "0.17.3", + "@esbuild/linux-s390x": "0.17.3", + "@esbuild/linux-x64": "0.17.3", + "@esbuild/netbsd-x64": "0.17.3", + "@esbuild/openbsd-x64": "0.17.3", + "@esbuild/sunos-x64": "0.17.3", + "@esbuild/win32-arm64": "0.17.3", + "@esbuild/win32-ia32": "0.17.3", + "@esbuild/win32-x64": "0.17.3" + } + }, + "escape-string-regexp": { + "version": "4.0.0", + "dev": true, + "peer": true + }, + "eslint": { + "version": "8.22.0", + "dev": true, + "peer": true, + "requires": { + "@eslint/eslintrc": "^1.3.0", + "@humanwhocodes/config-array": "^0.10.4", + "@humanwhocodes/gitignore-to-minimatch": "^1.0.2", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "doctrine": "^3.0.0", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^7.1.1", + "eslint-utils": "^3.0.0", + "eslint-visitor-keys": "^3.3.0", + "espree": "^9.3.3", + "esquery": "^1.4.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "find-up": "^5.0.0", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^6.0.1", + "globals": "^13.15.0", + "globby": "^11.1.0", + "grapheme-splitter": "^1.0.4", + "ignore": "^5.2.0", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "js-yaml": "^4.1.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "regexpp": "^3.2.0", + "strip-ansi": "^6.0.1", + "strip-json-comments": "^3.1.0", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "dependencies": { + "eslint-scope": { + "version": "7.1.1", + "dev": true, + "peer": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + } + }, + "estraverse": { + "version": "5.3.0", + "dev": true, + "peer": true + } + } + }, + "eslint-scope": { + "version": "5.1.1", + "dev": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "3.0.0", + "dev": true, + "requires": { + "eslint-visitor-keys": "^2.0.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "2.1.0", + "dev": true + } + } + }, + "eslint-visitor-keys": { + "version": "3.3.0", + "dev": true + }, + "espree": { + "version": "9.3.3", + "dev": true, + "peer": true, + "requires": { + "acorn": "^8.8.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.3.0" + } + }, + "esquery": { + "version": "1.4.0", + "dev": true, + "peer": true, + "requires": { + "estraverse": "^5.1.0" + }, + "dependencies": { + "estraverse": { + "version": "5.3.0", + "dev": true, + "peer": true + } + } + }, + "esrecurse": { + "version": "4.3.0", + "dev": true, + "requires": { + "estraverse": "^5.2.0" + }, + "dependencies": { + "estraverse": { + "version": "5.3.0", + "dev": true + } + } + }, + "estraverse": { + "version": "4.3.0", + "dev": true + }, + "esutils": { + "version": "2.0.3", + "dev": true, + "peer": true + }, + "fast-deep-equal": { + "version": "3.1.3", + "dev": true, + "peer": true + }, + "fast-glob": { + "version": "3.2.11", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "dependencies": { + "glob-parent": { + "version": "5.1.2", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + } + } + }, + "fast-json-stable-stringify": { + "version": "2.1.0", + "dev": true, + "peer": true + }, + "fast-levenshtein": { + "version": "2.0.6", + "dev": true, + "peer": true + }, + "fastq": { + "version": "1.13.0", + "dev": true, + "requires": { + "reusify": "^1.0.4" + } + }, + "file-entry-cache": { + "version": "6.0.1", + "dev": true, + "peer": true, + "requires": { + "flat-cache": "^3.0.4" + } + }, + "fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "find-up": { + "version": "5.0.0", + "dev": true, + "peer": true, + "requires": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + } + }, + "flat-cache": { + "version": "3.0.4", + "dev": true, + "peer": true, + "requires": { + "flatted": "^3.1.0", + "rimraf": "^3.0.2" + } + }, + "flatted": { + "version": "3.2.7", + "dev": true, + "peer": true + }, + "fs.realpath": { + "version": "1.0.0", + "dev": true, + "peer": true + }, + "functional-red-black-tree": { + "version": "1.0.1", + "dev": true + }, + "glob": { + "version": "7.2.3", + "dev": true, + "peer": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "glob-parent": { + "version": "6.0.2", + "dev": true, + "peer": true, + "requires": { + "is-glob": "^4.0.3" + } + }, + "globals": { + "version": "13.17.0", + "dev": true, + "peer": true, + "requires": { + "type-fest": "^0.20.2" + } + }, + "globby": { + "version": "11.1.0", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + } + }, + "grapheme-splitter": { + "version": "1.0.4", + "dev": true, + "peer": true + }, + "has-flag": { + "version": "4.0.0", + "dev": true, + "peer": true + }, + "highlight.js": { + "version": "11.9.0", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.9.0.tgz", + "integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==", + "dev": true + }, + "ignore": { + "version": "5.2.0", + "dev": true + }, + "import-fresh": { + "version": "3.3.0", + "dev": true, + "peer": true, + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + } + }, + "imurmurhash": { + "version": "0.1.4", + "dev": true, + "peer": true + }, + "inflight": { + "version": "1.0.6", + "dev": true, + "peer": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "dev": true, + "peer": true + }, + "is-extglob": { + "version": "2.1.1", + "dev": true + }, + "is-glob": { + "version": "4.0.3", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "isexe": { + "version": "2.0.0", + "dev": true, + "peer": true + }, + "js-yaml": { + "version": "4.1.0", + "dev": true, + "peer": true, + "requires": { + "argparse": "^2.0.1" + } + }, + "json-schema-traverse": { + "version": "0.4.1", + "dev": true, + "peer": true + }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "dev": true, + "peer": true + }, + "levn": { + "version": "0.4.1", + "dev": true, + "peer": true, + "requires": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + } + }, + "locate-path": { + "version": "6.0.0", + "dev": true, + "peer": true, + "requires": { + "p-locate": "^5.0.0" + } + }, + "lodash.merge": { + "version": "4.6.2", + "dev": true, + "peer": true + }, + "lru-cache": { + "version": "6.0.0", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "merge2": { + "version": "1.4.1", + "dev": true + }, + "micromatch": { + "version": "4.0.5", + "dev": true, + "requires": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + } + }, + "minimatch": { + "version": "3.1.2", + "dev": true, + "peer": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "moment": { + "version": "2.29.4", + "dev": true + }, + "monaco-editor": { + "version": "0.43.0" + }, + "ms": { + "version": "2.1.2", + "dev": true + }, + "natural-compare": { + "version": "1.4.0", + "dev": true, + "peer": true + }, + "obsidian": { + "version": "1.4.11", + "resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.4.11.tgz", + "integrity": "sha512-BCVYTvaXxElJMl6MMbDdY/CGK+aq18SdtDY/7vH8v6BxCBQ6KF4kKxL0vG9UZ0o5qh139KpUoJHNm+6O5dllKA==", + "dev": true, + "requires": { + "@types/codemirror": "5.60.8", + "moment": "2.29.4" + } + }, + "once": { + "version": "1.4.0", + "dev": true, + "peer": true, + "requires": { + "wrappy": "1" + } + }, + "optionator": { + "version": "0.9.1", + "dev": true, + "peer": true, + "requires": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + } + }, + "p-limit": { + "version": "3.1.0", + "dev": true, + "peer": true, + "requires": { + "yocto-queue": "^0.1.0" + } + }, + "p-locate": { + "version": "5.0.0", + "dev": true, + "peer": true, + "requires": { + "p-limit": "^3.0.2" + } + }, + "parent-module": { + "version": "1.0.1", + "dev": true, + "peer": true, + "requires": { + "callsites": "^3.0.0" + } + }, + "path-exists": { + "version": "4.0.0", + "dev": true, + "peer": true + }, + "path-is-absolute": { + "version": "1.0.1", + "dev": true, + "peer": true + }, + "path-key": { + "version": "3.1.1", + "dev": true, + "peer": true + }, + "path-type": { + "version": "4.0.0", + "dev": true + }, + "picomatch": { + "version": "2.3.1", + "dev": true + }, + "prelude-ls": { + "version": "1.2.1", + "dev": true, + "peer": true + }, + "punycode": { + "version": "2.1.1", + "dev": true, + "peer": true + }, + "queue-microtask": { + "version": "1.2.3", + "dev": true + }, + "regexpp": { + "version": "3.2.0", + "dev": true + }, + "resolve-from": { + "version": "4.0.0", + "dev": true, + "peer": true + }, + "reusify": { + "version": "1.0.4", + "dev": true + }, + "rimraf": { + "version": "3.0.2", + "dev": true, + "peer": true, + "requires": { + "glob": "^7.1.3" + } + }, + "run-parallel": { + "version": "1.2.0", + "dev": true, + "requires": { + "queue-microtask": "^1.2.2" + } + }, + "semver": { + "version": "7.5.4", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "shebang-command": { + "version": "2.0.0", + "dev": true, + "peer": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "dev": true, + "peer": true + }, + "slash": { + "version": "3.0.0", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "dev": true + }, + "source-map-support": { + "version": "0.5.21", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "strip-ansi": { + "version": "6.0.1", + "dev": true, + "peer": true, + "requires": { + "ansi-regex": "^5.0.1" + } + }, + "strip-json-comments": { + "version": "3.1.1", + "dev": true, + "peer": true + }, + "style-mod": { + "version": "4.0.0", + "dev": true, + "peer": true + }, + "supports-color": { + "version": "7.2.0", + "dev": true, + "peer": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "terser": { + "version": "5.26.0", + "dev": true, + "requires": { + "@jridgewell/source-map": "^0.3.3", + "acorn": "^8.8.2", + "commander": "^2.20.0", + "source-map-support": "~0.5.20" + } + }, + "text-table": { + "version": "0.2.0", + "dev": true, + "peer": true + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + }, + "tslib": { + "version": "2.4.0", + "dev": true + }, + "tsutils": { + "version": "3.21.0", + "dev": true, + "requires": { + "tslib": "^1.8.1" + }, + "dependencies": { + "tslib": { + "version": "1.14.1", + "dev": true + } + } + }, + "type-check": { + "version": "0.4.0", + "dev": true, + "peer": true, + "requires": { + "prelude-ls": "^1.2.1" + } + }, + "type-fest": { + "version": "0.20.2", + "dev": true, + "peer": true + }, + "typescript": { + "version": "4.7.4", + "dev": true + }, + "uri-js": { + "version": "4.4.1", + "dev": true, + "peer": true, + "requires": { + "punycode": "^2.1.0" + } + }, + "v8-compile-cache": { + "version": "2.3.0", + "dev": true, + "peer": true + }, + "w3c-keyname": { + "version": "2.2.6", + "dev": true, + "peer": true + }, + "which": { + "version": "2.0.2", + "dev": true, + "peer": true, + "requires": { + "isexe": "^2.0.0" + } + }, + "word-wrap": { + "version": "1.2.5", + "dev": true, + "peer": true + }, + "wrappy": { + "version": "1.0.2", + "dev": true, + "peer": true + }, + "yallist": { + "version": "4.0.0", + "dev": true + }, + "yocto-queue": { + "version": "0.1.0", + "dev": true, + "peer": true + } } } diff --git a/src/codeFilesSettingsTab.ts b/src/codeFilesSettingsTab.ts index feee07b..998b4a5 100644 --- a/src/codeFilesSettingsTab.ts +++ b/src/codeFilesSettingsTab.ts @@ -56,17 +56,6 @@ export class CodeFilesSettingsTab extends PluginSettingTab { el.innerText = " " + this.plugin.settings.fontSize.toString(); }); - new Setting(containerEl) - .setName(t('FILE_EXTENSIONS')) - .setDesc(t('FILE_EXTENSIONS_DESC')) - .addTextArea(text => text - .setValue(this.plugin.settings.extensions.join(",")) - .onChange(async (value) => { - this.plugin.settings.extensions = value.split(","); - await this.plugin.saveSettings(); - })).setClass("setting_ext"); - - new Setting(containerEl) .setName(t('WORDWRAP')) .setDesc(t('WORDWRAP_DESC')) diff --git a/src/constants.ts b/src/constants.ts index 7b565de..720564e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,4 +2,258 @@ export const THEME_COLOR = { AUTO: 'AUTO', LIGHT: 'LIGHT', DARK: 'DARK', -}; \ No newline at end of file +}; + +export const extensions: string[] = [ + "aes", + "abap", + "ascx", + "asp", + "aspx", + "azcli", + "bat", + "batch", + "bicep", + "c", + "cake", + "cameligo", + "cc", + "clj", + "cljc", + "cljs", + "cls", + "clj", + "cljc", + "cljs", + "coffee", + "config", + "cpp", + "cpy", + "cs", + "cshtml", + "csproj", + "csx", + "csharp", + "cts", + "c++", + "dart", + "dax", + "dockerfile", + "dot", + "dtd", + "ecl", + "edn", + "elixir", + "erb", + "es6", + "ex", + "exs", + "freemarker2", + "fs", + "fsharp", + "fsi", + "fsx", + "ftl", + "ftlh", + "ftlx", + "gemspec", + "go", + "graphql", + "gql", + "groovy", + "grt", + "gtpl", + "gy", + "gyp", + "gypi", + "handlebars", + "hcl", + "h", + "hpp", + "html", + "htm", + "ini", + "jade", + "java", + "jav", + "javascript", + "javascriptreact", + "jinja", + "jl", + "json", + "js", + "jshtm", + "jsx", + "julia", + "kt", + "kts", + "latex", + "lex", + "liquid", + "lua", + "m", + "m3", + "mdoc", + "mdown", + "mdtxt", + "mdwn", + "mdx", + "mips", + "mkd", + "mkdn", + "ml", + "mli", + "mligo", + "mjs", + "mts", + "objc", + "objective-c", + "opf", + "pascal", + "perl", + "php", + "php4", + "php5", + "phtml", + "pla", + "plain", + "plaintext", + "pm", + "pug", + "powerquery", + "proto", + "py", + "pyu", + "qsharp", + "r", + "racket", + "rake", + "razor", + "rb", + "rbx", + "rbuild", + "redis", + "restructuredtext", + "rjs", + "rkt", + "rst", + "rs", + "rscript", + "ruby", + "rust", + "sb", + "scss", + "scheme", + "scm", + "sc", + "sbt", + "sdl", + "sg", + "sh", + "shell", + "smali", + "sol", + "sparkql", + "sparql", + "sql", + "ss", + "st", + "st", + "swift", + "swift", + "svgz", + "svh", + "systemverilog", + "tcl", + "tf", + "tfvars", + "twig", + "typescript", + "tsx", + "txt", + "vb", + "verilog", + "vh", + "vue", + "wgsl", + "xml", + "yaml", + "yml" +]; + +export const languages : string[] = [ + "abap", + "aes", + "apex", + "azcli", + "bat", + "bicep", + "cameligo", + "clojure", + "coffeescript", + "cpp", + "csharp", + "css", + "cypher", + "dart", + "dockerfile", + "ecl", + "elixir", + "flow9", + "freemarker2", + "fsharp", + "go", + "graphql", + "handlebars", + "hcl", + "html", + "ini", + "java", + "javascript", + "json", + "julia", + "kotlin", + "less", + "lexon", + "liquid", + "lua", + "markdown", + "mips", + "msdax", + "objective-c", + "pascal", + "pascaligo", + "perl", + "php", + "plaintext", + "pla", + "postiats", + "powerquery", + "proto", + "pug", + "python", + "qsharp", + "r", + "razor", + "redis", + "restructuredtext", + "ruby", + "rust", + "scala", + "scheme", + "scss", + "shell", + "sol", + "sparql", + "sql", + "st", + "swift", + "systemverilog", + "tcl", + "typescript", + "vb", + "verilog", + "wgsl", + "xml", + "yaml" +]; \ No newline at end of file diff --git a/src/createCodeFileModal.ts b/src/createCodeFileModal.ts index fb895d1..fb41f75 100644 --- a/src/createCodeFileModal.ts +++ b/src/createCodeFileModal.ts @@ -10,10 +10,11 @@ import { TFolder } from "obsidian"; import CodeFilesPlugin from "./main"; +import { extensions } from "./constants"; export class CreateCodeFileModal extends Modal { fileName = "My code file"; - fileExtension = this.plugin.settings.extensions[0]; + fileExtension = "txt"; parent: TAbstractFile; constructor(private plugin: CodeFilesPlugin, parentFile?: TAbstractFile) { @@ -36,7 +37,7 @@ export class CreateCodeFileModal extends Modal { const fileExtensionInput = new DropdownComponent(contentEl); fileExtensionInput.selectEl.addClass("modal_select"); - fileExtensionInput.addOptions(this.plugin.settings.extensions.reduce((acc, ext) => { + fileExtensionInput.addOptions(extensions.reduce((acc, ext) => { acc[ext] = ext; return acc; }, {} as any)); @@ -59,7 +60,6 @@ export class CreateCodeFileModal extends Modal { async complete() { this.close(); - console.log(this.parent); let parent = null; if (this.parent instanceof TFile){ diff --git a/src/main.ts b/src/main.ts index e8f57d2..757d5e1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ import { t } from 'src/lang/helpers'; import { FenceEditModal } from "./fenceEditModal"; import { FenceEditContext } from "./fenceEditContext"; import { mountCodeEditor } from "./mountCodeEditor"; -import { getLanguage } from './ObsidianUtils'; +import { languages, extensions } from './constants'; declare module "obsidian" { interface Workspace { @@ -50,6 +50,10 @@ const languageTemplates: LanguageTemplates = { startTemplate: 'def\\s+${func_name}', endDetectionMethod: 'indent', }, + javascript: { + startTemplate: '${func_name}\\([\\w, ]*\\)\\s*{', + endDetectionMethod: 'brackets', + }, // Add more languages and their templates as needed }; @@ -152,17 +156,22 @@ class EmbeddedCode{ } else if (endDetectionMethod === 'brackets') { // Example: Detect end by counting opening and closing brackets let bracketCount = 0; - for (let i = startLine - 1; i < lines.length; i++) { + for (let i = startLine; i < lines.length; i++) { const line = lines[i]; + bracketCount += (line.match(/\{/g) || []).length; bracketCount -= (line.match(/\}/g) || []).length; - if (bracketCount === 0) { + if (bracketCount == 0) { endLine = i + 1; // Found the line where the closing bracket is + break; } } - endLine = lines.length; + if (endLine == -1){ + endLine = lines.length; + } + } else { // Custom end detection method // Adjust this based on your specific requirements for each language @@ -255,6 +264,7 @@ class EmbeddedCode{ if (srcPath.startsWith("https://") || srcPath.startsWith("http://")) { try { let httpResp = await requestUrl({url: srcPath, method: "GET"}) + this.path = srcPath.replace(/^(http[s]?:\/\/)/,''); this.content = httpResp.text this.embedType = "web"; } catch(e) { @@ -272,8 +282,8 @@ class EmbeddedCode{ this.embedType = "file"; } else { - this.path = getLocalSource(this.context, this.path) - tFile = this.app.vault.getAbstractFileByPath(this.path) + this.path = getLocalSource(this.context, this.path); + tFile = this.app.vault.getAbstractFileByPath(this.path); if (tFile instanceof TFile) { this.createMetaInfo(); this.content = await this.app.vault.read(tFile); @@ -335,11 +345,8 @@ class EmbeddedCode{ new Notice(`Cannot locate Refresh Button`); } - console.log(this.container) let copyButton = this.container.querySelector('.copy-code-button') as HTMLButtonElement; - console.log(copyButton) if (copyButton){ - console.log(copyButton) setIcon(copyButton, 'clipboard'); copyButton.ariaLabel = "Copy to Clipboard"; } @@ -419,7 +426,6 @@ class EmbeddedCode{ if (currentFile){ this.tryRefresh(workspace, currentFile, tFile.path, 3000, 300000); }else{ - console.log("Cannot get current file"); } }else if (webFile){ @@ -430,13 +436,13 @@ class EmbeddedCode{ } openFile(path:string) { - let alreadyOpen = false; this.app.workspace.iterateAllLeaves((leaf: WorkspaceLeaf) => { if (alreadyOpen){ return } const viewState = leaf.getViewState(); if (viewState.state?.file == path){ + // file is already open in another leaf this.app.workspace.setActiveLeaf(leaf); alreadyOpen = true; @@ -524,9 +530,8 @@ export default class EmbedAndEditCode extends Plugin { `) - this.settings.extensions.forEach(e => { - let l = getLanguage(e) - this.registerRenderer(l) + languages.forEach(e => { + this.registerRenderer(e) }); if (this.app.workspace.getLeavesOfType(viewType).length < 1){ @@ -534,9 +539,11 @@ export default class EmbedAndEditCode extends Plugin { } try { - this.registerExtensions(this.settings.extensions, viewType); + this.registerExtensions(extensions, viewType); } catch (e) { + console.log("Register Extension Error: " + e) } + this.registerEvent( this.app.workspace.on("file-menu", (menu, file) => { menu.addItem((item) => { @@ -552,11 +559,7 @@ export default class EmbedAndEditCode extends Plugin { this.addRibbonIcon('file-json', t("CREATE_CODE"), async () => { let activeFile = this.app.workspace.getActiveFile() ?? undefined; - if (activeFile){ - console.log(`create file at ${activeFile?.path}`) - }else{ - console.log("Can't get active") - } + new CreateCodeFileModal(this, activeFile).open(); }); @@ -565,11 +568,6 @@ export default class EmbedAndEditCode extends Plugin { name: 'Create new code file', callback: async () => { let activeFile = this.app.workspace.getActiveFile() ?? undefined; - if (activeFile){ - console.log(`create file at ${activeFile?.path}`) - }else{ - console.log("Can't get active") - } new CreateCodeFileModal(this, activeFile).open(); } @@ -591,19 +589,14 @@ export default class EmbedAndEditCode extends Plugin { }) ); - //internal links this.observer = new MutationObserver(async (mutation) => { - if (mutation.length !== 1) return; - if (mutation[0].addedNodes.length !== 1) return; - if (this.hover.linkText === null) return; + if (mutation.length !== 1 || mutation[0].addedNodes.length !== 1 || this.hover.linkText === null) return; + //@ts-ignore if (mutation[0].addedNodes[0].className !== "popover hover-popover") return; const file = this.app.metadataCache.getFirstLinkpathDest(this.hover.linkText, this.hover.sourcePath); if (!file) return; - // check file.extension in this.settings.extensions array - let valid = this.settings.extensions.includes(file.extension); - if (valid === false) return; const fileContent = await this.app.vault.read(file); const node: Node = mutation[0].addedNodes[0]; diff --git a/src/mountCodeEditor.ts b/src/mountCodeEditor.ts index 35b27d9..0095456 100644 --- a/src/mountCodeEditor.ts +++ b/src/mountCodeEditor.ts @@ -14,7 +14,6 @@ export class mountCodeEditor { this.contentEl = contentEl; this.plugin = plugin; this.value = code; - let setting = genEditorSettings(this.plugin.settings, language, miniMap, wordWrap); this.monacoEditor = monaco.editor.create(this.contentEl, setting); this.monacoEditor.setValue(this.value); diff --git a/src/settings.ts b/src/settings.ts index 0980278..c7b8a48 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,9 +1,4 @@ -import EmbedCodeFile from './main'; - -import { PluginSettingTab, Setting, App } from 'obsidian'; - export interface EmbedAndEditSettings { - extensions: string[]; folding: boolean allowAllFiletypes: boolean; lineNumbers: boolean; @@ -16,7 +11,6 @@ export interface EmbedAndEditSettings { } export const DEFAULT_SETTINGS: EmbedAndEditSettings = { - extensions: ["ts", "js", "py", "css", "c", "cpp", "go", "rs", "java", "lua", "php"], folding: true, allowAllFiletypes: false, lineNumbers: true, diff --git a/src/utils.ts b/src/utils.ts index 0741440..971d251 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -35,8 +35,7 @@ export function getFileName(filePath: string): string{ export function getLocalSource(markdownContext: MarkdownPostProcessorContext, filePath: string): string{ const currentDirectory = path.dirname(markdownContext.sourcePath) - let srcPath = path.join(currentDirectory, filePath).replace(/\\/g, '/'); - return srcPath + return path.join(currentDirectory, filePath).replace(/\\/g, '/'); } export function extractSrcLines(fullSrc: string, srcLinesNum: number[]): string {