diff --git a/main.ts b/main.ts index 2a2fb67..c9a0afa 100644 --- a/main.ts +++ b/main.ts @@ -268,15 +268,17 @@ export default class PastetoIndentationPlugin extends Plugin { const files = evt.clipboardData.files; const fileLinks = []; const activeFile = this.app.workspace.getActiveFile(); + const activeFilePath = activeFile?.path; - let filesTargetLocation = this.settings.saveFilesLocation; + let filesTargetLocation = this.settings.saveFilesLocation.replace('{current}', activeFile.parent.path); let longestMatchingCursorFilePattern = 0; this.settings.saveFilesOverrideLocations.forEach((location) => { if ( - activeFile.path.startsWith(location.cursorFilePattern) && + activeFilePath && + activeFilePath.startsWith(location.cursorFilePattern) && location.cursorFilePattern.length > longestMatchingCursorFilePattern ) { - filesTargetLocation = location.targetLocation; + filesTargetLocation = location.targetLocation.replace('{current}', activeFile.parent.path); longestMatchingCursorFilePattern = location.cursorFilePattern.length; } @@ -308,7 +310,7 @@ export default class PastetoIndentationPlugin extends Plugin { const link = this.app.fileManager.generateMarkdownLink( tfileObject, - this.app.workspace.getActiveFile().path + activeFilePath ); fileLinks.push(link); @@ -319,6 +321,7 @@ export default class PastetoIndentationPlugin extends Plugin { const parser = new DOMParser(); const htmlDom = parser.parseFromString(clipboardHtml, "text/html"); + // Find all elements with a src attribute: const srcContainingElements = htmlDom.querySelectorAll("[src]"); @@ -354,10 +357,12 @@ export default class PastetoIndentationPlugin extends Plugin { // file: // !new RegExp("^([a-zA-Z])+://").test(src); if (srcIsLocalFile) { - let urlForDownloading = src; + let urlForDownloading = src.replace(/^file:\/{2}/, ""); - if (src.startsWith("file:///")) { - urlForDownloading = src.replace(/^file:\/\/\//, ""); + if (/^\/[A-Za-z]:/.test(urlForDownloading)) { + // We are likely in Windows, and need to remove an additional + // slash from the URL: + urlForDownloading = urlForDownloading.replace(/^\//, ''); } dataBlob = new Blob([ @@ -372,6 +377,10 @@ export default class PastetoIndentationPlugin extends Plugin { }); } + if (!(await app.vault.adapter.exists(filesTargetLocation))) { + await app.vault.createFolder(filesTargetLocation); + } + if (dataBlob) { const fileName = await createImageFileName( filesTargetLocation, @@ -769,12 +778,12 @@ class SettingTab extends PluginSettingTab { const noticeDiv = containerEl.createDiv(); noticeDiv .createEl("span", { text: "Notice: " }) - .addClass("paste-to-current-indentation-settings-notice"); + .addClass("paste-mode-settings-notice"); noticeDiv .createEl("span", { text: `The "Paste in Markdown Mode" and "Paste in Markdown (Blockquote) Mode" attachmentOverrideLocations have been disabled, because reading non-text data from the clipboad does not work with this version of Obsidian.`, }) - .addClass("paste-to-current-indentation-settings-notice-text"); + .addClass("paste-mode-settings-notice-text"); } new Setting(containerEl) @@ -878,8 +887,7 @@ class SettingTab extends PluginSettingTab { .setName("src attribute copy regex") .setDesc( `If set, when pasting in Markdown or Markdown (Blockquote) mode, watch for any HTML elements that contain a src attribute. If the src value matches this Regular Expression, copy the file being referenced into the Obsidian vault, and replace the src attribute with a reference to that now-local copy of the file.` - ) - .setDisabled(!this.plugin.settings.escapeCharactersInBlockquotes) + ) .addText((text) => { text .setValue( @@ -902,7 +910,7 @@ class SettingTab extends PluginSettingTab { new Setting(attachmentsEl) .setName("Default attachment folder path") .setDesc( - `When saving files from the clipboard, place them in this folder.` + `When saving files from the clipboard, place them in this folder. ("{current}" will insert the directory of the currently-open note.)` ) .addText((text) => { text @@ -953,7 +961,7 @@ class SettingTab extends PluginSettingTab { new Setting(attachmentLocationEl) .setName("Saved file target location") - .setDesc("...Save a pasted file into this directory:") + .setDesc('...Save a pasted file into this directory. ("{current}" will insert the directory of the currently-open note.)') .addText((text) => { text .setValue(attachmentLocation.targetLocation) @@ -970,7 +978,7 @@ class SettingTab extends PluginSettingTab { .addButton((button) => { button .setButtonText("Delete") - .setClass("paste-to-current-indentation-settings-delete-button") + .setClass("paste-mode-settings-delete-button") .setTooltip("Delete override location") .onClick(async () => { if (attachmentLocationDeletePrimerTimer) { diff --git a/manifest.json b/manifest.json index 04e243a..3ec4993 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "id": "obsidian-paste-to-current-indentation", "name": "Paste Mode", - "version": "5.0.0", - "minAppVersion": "1.0.0", + "version": "5.0.1", + "minAppVersion": "1.1.1", "description": "Paste content and mark block quotes at any level of indentation.", "author": "Jacob Levernier", "authorUrl": "https://github.com/jglev/obsidian-paste-to-current-indentation", diff --git a/package.json b/package.json index c23fa78..6dd0023 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-paste-to-current-indentation", - "version": "5.0.0", + "version": "5.0.1", "description": "This plugin allows pasting and marking text as block-quotes at any level of indentation.", "main": "main.js", "scripts": { @@ -17,7 +17,7 @@ "@types/node": "^14.14.37", "esbuild": "0.13.12", "eslint-config-next": "^12.1.5", - "obsidian": "^0.14.6", + "obsidian": "^1.1.1", "tslib": "^2.2.0", "tslint": "^6.1.3", "typescript": "^4.3.5", diff --git a/styles.css b/styles.css index 9ade3a5..ed76c95 100644 --- a/styles.css +++ b/styles.css @@ -1,13 +1,13 @@ -.paste-to-current-indentation-settings-notice { +.paste-mode-settings-notice { color: var(--text-error); font-weight: bold; } -.paste-to-current-indentation-settings-notice-text { +.paste-mode-settings-notice-text { font-style: italic; } -.primed .paste-to-current-indentation-settings-delete-button { +.primed .paste-mode-settings-delete-button { background: var(--text-error) !important; color: white !important; } diff --git a/versions.json b/versions.json index 5649ebc..da719a6 100644 --- a/versions.json +++ b/versions.json @@ -12,5 +12,6 @@ "3.0.2": "0.14.6", "3.1.0": "0.14.6", "4.0.0": "0.14.6", - "5.0.0": "1.0.0" + "5.0.0": "1.0.0", + "5.0.1": "1.1.1" } diff --git a/yarn.lock b/yarn.lock index 3d91018..5e348cf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -38,36 +38,6 @@ dependencies: regenerator-runtime "^0.13.4" -"@codemirror/rangeset@^0.19.5": - version "0.19.9" - resolved "https://registry.yarnpkg.com/@codemirror/rangeset/-/rangeset-0.19.9.tgz#e80895de93c39dc7899f5be31d368c9d88aa4efc" - integrity sha512-V8YUuOvK+ew87Xem+71nKcqu1SXd5QROMRLMS/ljT5/3MCxtgrRie1Cvild0G/Z2f1fpWxzX78V0U4jjXBorBQ== - dependencies: - "@codemirror/state" "^0.19.0" - -"@codemirror/state@^0.19.0", "@codemirror/state@^0.19.3", "@codemirror/state@^0.19.6": - version "0.19.9" - resolved "https://registry.yarnpkg.com/@codemirror/state/-/state-0.19.9.tgz#b797f9fbc204d6dc7975485e231693c09001b0dd" - integrity sha512-psOzDolKTZkx4CgUqhBQ8T8gBc0xN5z4gzed109aF6x7D7umpDRoimacI/O6d9UGuyl4eYuDCZmDFr2Rq7aGOw== - dependencies: - "@codemirror/text" "^0.19.0" - -"@codemirror/text@^0.19.0": - version "0.19.6" - resolved "https://registry.yarnpkg.com/@codemirror/text/-/text-0.19.6.tgz#9adcbd8137f69b75518eacd30ddb16fd67bbac45" - integrity sha512-T9jnREMIygx+TPC1bOuepz18maGq/92q2a+n4qTqObKwvNMg+8cMTslb8yxeEDEq7S3kpgGWxgO1UWbQRij0dA== - -"@codemirror/view@^0.19.31": - version "0.19.48" - resolved "https://registry.yarnpkg.com/@codemirror/view/-/view-0.19.48.tgz#1c657e2b0f8ed896ac6448d6e2215ab115e2a0fc" - integrity sha512-0eg7D2Nz4S8/caetCTz61rK0tkHI17V/d15Jy0kLOT8dTLGGNJUponDnW28h2B6bERmPlVHKh8MJIr5OCp1nGw== - dependencies: - "@codemirror/rangeset" "^0.19.5" - "@codemirror/state" "^0.19.3" - "@codemirror/text" "^0.19.0" - style-mod "^4.0.0" - w3c-keyname "^2.2.4" - "@jest/types@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/types/-/types-26.6.2.tgz#bef5a532030e1d88a2f5a6d933f84e97226ed48e" @@ -1153,10 +1123,10 @@ mkdirp@^0.5.3: dependencies: minimist "^1.2.6" -moment@2.29.2: - version "2.29.2" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.2.tgz#00910c60b20843bcba52d37d58c628b47b1f20e4" - integrity sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg== +moment@2.29.4: + version "2.29.4" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108" + integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w== moment@^2.29.3: version "2.29.3" @@ -1238,15 +1208,13 @@ object.values@^1.1.5: define-properties "^1.1.3" es-abstract "^1.19.1" -obsidian@^0.14.6: - version "0.14.6" - resolved "https://registry.yarnpkg.com/obsidian/-/obsidian-0.14.6.tgz#010e16da3a1a7725f5e91beb9f14ec8abd00c15d" - integrity sha512-oXPJ8Zt10WhN19bk5l4mZuXRZbbdT1QoMgxGGJ0bB7UcJa0bozDzugS5L/QiV9gDoujpUPxDWNVahEel6r0Fpw== +obsidian@^1.1.7: + version "1.1.1" + resolved "https://registry.yarnpkg.com/obsidian/-/obsidian-1.1.1.tgz#7cce6f19a6dd1cc5ec7e9f7dff8ea3ceacf2e2c3" + integrity sha512-GcxhsHNkPEkwHEjeyitfYNBcQuYGeAHFs1pEpZIv0CnzSfui8p8bPLm2YKLgcg20B764770B1sYGtxCvk9ptxg== dependencies: - "@codemirror/state" "^0.19.6" - "@codemirror/view" "^0.19.31" "@types/codemirror" "0.0.108" - moment "2.29.2" + moment "2.29.4" once@^1.3.0: version "1.4.0" @@ -1447,11 +1415,6 @@ strip-bom@^3.0.0: resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM= -style-mod@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/style-mod/-/style-mod-4.0.0.tgz#97e7c2d68b592975f2ca7a63d0dd6fcacfe35a01" - integrity sha512-OPhtyEjyyN9x3nhPsu76f52yUGXiZcgvsrFVtvTkyGRQJ0XK+GPc6ov1z+lRpbeabka+MYEQxOYRnt5nF30aMw== - supports-color@^5.3.0: version "5.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" @@ -1546,11 +1509,6 @@ unbox-primitive@^1.0.1: has-symbols "^1.0.2" which-boxed-primitive "^1.0.2" -w3c-keyname@^2.2.4: - version "2.2.4" - resolved "https://registry.yarnpkg.com/w3c-keyname/-/w3c-keyname-2.2.4.tgz#4ade6916f6290224cdbd1db8ac49eab03d0eef6b" - integrity sha512-tOhfEwEzFLJzf6d1ZPkYfGj+FWhIpBux9ppoP3rlclw3Z0BZv3N7b7030Z1kYth+6rDuAsXUFr+d0VE6Ed1ikw== - which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"