Skip to content

Commit

Permalink
2.1.0 (#8)
Browse files Browse the repository at this point in the history
- Added new "Code Block" mode (resolves #3)
- Mode names now have spaces and capitalization (vs. hyphens and lowercase)
- Corrected typo in URL (resolves #7)
  • Loading branch information
jglev authored Jan 19, 2022
1 parent a34931d commit 7567f54
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
31 changes: 23 additions & 8 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
App,
Editor,
EditorChange,
EditorTransaction,
FuzzySuggestModal,
htmlToMarkdown,
Expand All @@ -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<number> {
Expand Down Expand Up @@ -75,7 +75,7 @@ interface PastetoIndentationPluginSettings {
const DEFAULT_SETTINGS: PastetoIndentationPluginSettings = {
blockquotePrefix: "> ",
mode: Mode.Markdown,
apiVersion: 1,
apiVersion: 2,
};

export default class PastetoIndentationPlugin extends Plugin {
Expand Down Expand Up @@ -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");
}

Expand All @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 7567f54

Please sign in to comment.