jglev / obsidian-paste-mode

Obsidian Notes plugin for pasting text and blockquotes to the cursor's current level of indentation.
Other
48 stars 2 forks source link

Obsidian Paste Mode

An Obsidian plugin to paste and manage text, including block quotes, that are indented. This plugin helps especially with embedding code, quotes, and other content within lists.

_(This plugin was formerly titled "Paste to Current Indentation".)

"Paste modes"

Paste Mode takes over the paste functionality within Obsidian. It has eight "paste modes," which determine what happens when one pastes text within a file in Obsidian. All of the below will honor the cursor's current indentation when pasting, except for "Passthrough" mode, which uses Obsidian's default paste functionality.

Demonstration of paste modes

  1. "Text" mode: Paste the clipboard text.
  2. "Text Blockquote" mode: Paste the clipboard text as a blockquote (prepended with the prefix from the plugin's Settings menu -- by default, ">").
  3. "Markdown" mode: Convert any HTML to markdown before pasting.
  4. "Markdown Blockquote" mode: Convert any HTML to Markdown before pasting. Then, paste the result as a blockquote (prepended with the prefix from the plugin's Settings menu -- by default, ">").
  5. "Code Block" mode: Paste the clipboard text within "```" code block fences.
  6. "Code Block Blockquote" mode: Paste the clipboard text within "```" code block fences as a blockquote.
  7. "Passthrough" mode: Use Obsidian's default paste functionality.

The current paste mode is displayed in Obsidian's Status Bar:

Status bar showing current paste mode

Switching paste mode

There are multiple ways to switch paste modes:

  1. Clicking the status bar paste mode display will bring up a searchable menu with which you can select a new mode.
  2. Open the Command Palette and search for Paste Mode: Cycle Paste Mode. This command is equivalent to clicking the satus bar.
  3. Open the Command Palette and search for Paste Mode: Set Paste Mode. One command per paste mode is provided.
    • These commands could be used, e.g., with the Obsidian Quick Add plugin to assign a keyboard command for switching to a given mode and then pasting.
  4. Open the Command Palette and search for Paste Mode: Cycle Paste Mode. This command will cycle through the different paste modes (i.e., from Text mode to Text Blockquote mode, to Markdown mode, to Markdown Blockquote mode, to Passthrough mode, back to Text mode, etc.)
  5. Within the plugin's Settings page.

Limitations of Paste Modes

Additional commands

Toggle blockquote command

Block quote markers are customizable via the plugin's Settings page (e.g., if you prefer to use spaces instead of >).

Additional features

Dynamic attachment saving

Downloading local copies of linked attachments

Automatic character escaping in Markdown

Characters that might cause display issues in Markdown (such as ==, <, etc.) can be automatically escaped when pasting.

Roadmap

I consider this plugin feature-complete for now.

Todo:

Developing for this plugin

The documentation below is retained from the Obsidian Sample Plugin.

Quickstart guide for development

Developing for mobile

Mobile development can be facilitated using the following workflow:

  1. Install the Mobile Hot Reload plugin
  2. Run yarn dev with files set to sync to mobile via, e.g., Syncthing or Dropbox.
  3. Follow the advice in this post:

    How to test plugins on Android I think you need to have ADB on your computer installed (I always had that installed; if the following directions don’t work without it, install it); on your android phone you have to enable ADB (it’s under developer settings [tap the build number three times to get these settings]); then connect the phone to your computer over USB; open chrome (or chromium based browser should also work) and type chrome://inspect in the browser. Open obsidian on your phone, then it should appear in the browser. You will have the console and the inspector like you have for desktop Obsidian

Releasing new releases

Manually installing the plugin

Obsidian API documentation

See https://github.com/obsidianmd/obsidian-api