diff --git a/main.ts b/main.ts index 0152778..cd7c3bd 100644 --- a/main.ts +++ b/main.ts @@ -1,7 +1,6 @@ import { App, Editor, - EditorChange, EditorTransaction, FuzzySuggestModal, htmlToMarkdown, @@ -15,11 +14,12 @@ import { import { toggleQuote, toggleQuoteInEditor } from "./src/toggle-quote"; enum Mode { - Text = "text", - TextBlockquote = "text-blockquote", - Markdown = "markdown", - MarkdownBlockquote = "markdown-blockquote", - Passthrough = "passthrough", + Text = "Text", + TextBlockquote = "Text (Blockquote)", + Markdown = "Markdown", + MarkdownBlockquote = "Markdown (Blockquote)", + CodeBlock = "Code Block", + Passthrough = "Passthrough", } class PasteModeModal extends FuzzySuggestModal { @@ -75,7 +75,7 @@ interface PastetoIndentationPluginSettings { const DEFAULT_SETTINGS: PastetoIndentationPluginSettings = { blockquotePrefix: "> ", mode: Mode.Markdown, - apiVersion: 1, + apiVersion: 2, }; export default class PastetoIndentationPlugin extends Plugin { @@ -134,7 +134,11 @@ export default class PastetoIndentationPlugin extends Plugin { } } - if (mode === Mode.Text || mode === Mode.TextBlockquote) { + if ( + mode === Mode.Text || + mode === Mode.TextBlockquote || + mode === Mode.CodeBlock + ) { clipboardContents = evt.clipboardData.getData("text"); } @@ -155,6 +159,12 @@ export default class PastetoIndentationPlugin extends Plugin { output = input.join("\n"); } + if (mode === Mode.CodeBlock) { + output = `\`\`\`\n${leadingWhitespace}${input.join( + "\n" + )}\n${leadingWhitespace}\`\`\``; + } + if (mode === Mode.TextBlockquote || mode === Mode.MarkdownBlockquote) { const toggledText = await toggleQuote( // We will remove leadingWhitespace from line 0 at the end. @@ -262,6 +272,11 @@ export default class PastetoIndentationPlugin extends Plugin { async loadSettings() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); + + if (!Object.values(Mode).includes(this.settings.mode)) { + this.settings.mode = Object.values(Mode)[0]; + this.saveSettings(); + } } async saveSettings() { diff --git a/manifest.json b/manifest.json index d67c544..e86043c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { "id": "obsidian-paste-to-current-indentation", "name": "Paste to Current Indentation", - "version": "2.0.1", + "version": "2.1.0", "minAppVersion": "0.13.9", "description": "This plugin allows pasting and marking text as block-quotes at any level of indentation.", "author": "Jacob Levernier", - "authorUrl": "https://https://github.com/publicus/obsidian-paste-to-current-indentation", + "authorUrl": "https://github.com/jglev/obsidian-paste-to-current-indentation", "isDesktopOnly": false } diff --git a/package.json b/package.json index de71833..bd7cb6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-paste-to-current-indentation", - "version": "2.0.1", + "version": "2.1.0", "description": "This plugin allows pasting and marking text as block-quotes at any level of indentation.", "main": "main.js", "scripts": { diff --git a/versions.json b/versions.json index 3a13c0e..92b7605 100644 --- a/versions.json +++ b/versions.json @@ -2,5 +2,6 @@ "1.0.0": "0.12.10", "1.1.0": "0.12.10", "2.0.0": "0.13.9", - "2.0.1": "0.13.9" + "2.0.1": "0.13.9", + "2.1.0": "0.13.9" }