| .gitignore | ||
| esbuild.config.mjs | ||
| image.png | ||
| LICENSE | ||
| main.ts | ||
| manifest.json | ||
| package.json | ||
| README.md | ||
| styles.css | ||
| test.html | ||
| tsconfig.json | ||
| version-bump.mjs | ||
| versions.json | ||
Paste Reformatter
A plugin for Obsidian that reformats pasted HTML and plain text content, giving you precise control over how content is transformed when pasted into your notes.
Installation
From Obsidian Community Plugins
- Open Obsidian and go to Settings
- Navigate to Community plugins and disable Safe mode if it's enabled
- Click Browse and search for "Paste Reformatter"
- Click Install, then Enable to activate the plugin
Manual Installation
- Download the latest release from the GitHub releases page
- Extract the ZIP file to your Obsidian plugins folder:
<vault>/.obsidian/plugins/ - Reload Obsidian or restart the app
- Go to Settings > Community plugins and enable "Paste Reformatter"
Usage
The Paste Reformatter plugin automatically processes content when you paste it into your notes using Ctrl+V (or Cmd+V on macOS). The plugin:
- Detects whether the clipboard contains HTML or plain text
- For HTML content:
- Applies HTML transformations (optionally removing empty elements or hard line breaks, regex string replacement)
- Converts the HTML to Markdown
- For plain text:
- Treats it as already being in Markdown format
- Applies Markdown transformations (heading adjustments, line break handling, regex string replacement)
- Inserts the transformed content at the cursor position
A notification will appear briefly indicating whether HTML or plain text content was reformatted.
Configuration
The plugin settings are divided into two main categories that mirror the transformation pipeline:
HTML Transformations
These settings control how HTML content is processed before being converted to Markdown.
Remove Empty Elements
When enabled, this setting removes empty elements (such as empty paragraphs, divs, spans) from the pasted HTML. This helps clean up content that might contain unnecessary structural elements.
Elements with meaningful content (including images, horizontal rules, etc.) are preserved even when empty.
Strip Hard Line Breaks
When enabled, this setting removes <br> tags from the HTML, resulting in paragraph-style text flow. When disabled, line breaks are preserved in the resulting Markdown.
HTML Regex Replacements
This feature allows you to define custom regular expression patterns and replacements to apply to the HTML content before it's converted to Markdown.
Each replacement consists of:
- Pattern: A regular expression to match in the HTML
- Replacement: The text to replace the matched pattern with
You can use capture groups in your patterns and reference them in the replacement using $1, $2, etc.
Markdown Transformations
These settings control how the Markdown content is processed after HTML conversion (or directly for plain text).
Max Heading Level
This setting controls the maximum heading level that will be applied to pasted headings.
The value is an integer between 1 and 6, where:
- H1 (level 1) is treated as disabled (no heading adjustments)
- H2-H6 (levels 2-6) will enforce that heading level as the minimum
When set to a value other than H1 (disabled), headings that are shallower than the specified level will be increased to that level.
Cascade Heading Levels
When enabled, this option preserves the heading hierarchy by cascading levels based on the Max Heading Level setting.
For example, if Max Heading Level is set to H2:
- H1 (#) becomes H2 (##)
- H2 (##) becomes H3 (###)
- H3 (###) becomes H4 (####)
- H4 (####) becomes H5 (#####)
- H5 (#####) becomes H6 (######)
- H6 (######) remains H6 (######) (capped at H6)
This preserves the relative structure of your headings while ensuring they fit within your document's hierarchy.
This setting is only available when Max Heading Level is set to something other than H1 (disabled).
Contextual Cascade
When enabled, this option adjusts heading levels based on the current context in your document. The plugin detects the heading level at your cursor position and cascades pasted headings relative to that context.
For example, if your cursor is positioned in a section with an H2 heading:
- Pasted H1 headings will become H3 (one level deeper than the context)
- Pasted H2 headings will become H4
- Pasted H3 headings will become H5
- And so on (capped at H6)
This is particularly useful when pasting content into different sections of your document and wanting the heading structure to fit naturally within the current section's hierarchy.
When used together with Cascade Heading Levels, the relative hierarchy of headings in the pasted content will be preserved.
Remove Empty Lines
When enabled, this setting removes blank lines from the Markdown output, resulting in more compact content. When disabled, empty lines are preserved, maintaining the original spacing.
Markdown Regex Replacements
Similar to HTML Regex Replacements, this feature allows you to define custom regular expression patterns and replacements to apply to the Markdown content after conversion.
This is useful for:
- Standardizing formatting
- Removing unwanted patterns
- Transforming specific content structures
- Adding custom Obsidian-specific syntax
Examples
Example 1: Cleaning Up Web Content
When copying content from websites, you often get unwanted elements. With these settings:
- Remove Empty Elements: Enabled
- Strip Hard Line Breaks: Enabled
- Max Heading Level: H2
- Cascade Heading Levels: Enabled
A complex web article with various heading levels and formatting will be transformed into clean, hierarchical Markdown with H2 as the top-level heading.
Example 2: Preserving Document Structure
When copying content from a document with specific formatting:
- Remove Empty Elements: Disabled
- Strip Hard Line Breaks: Disabled
- Max Heading Level: H1 (Disabled)
- Contextual Cascade: Enabled
The content will maintain its original structure, but headings will be adjusted to fit within the current document's hierarchy based on your cursor position.
HTML Regex Replacement Examples
- Remove image width/height attributes
- Pattern:
(<img[^>]*)(width|height)="[^"]*" - Replacement:
$1 - Description: Removes width and height attributes from image tags, allowing them to be sized by CSS instead
- Pattern:
- Convert Google Docs span styles to semantic elements
- Pattern:
<span style="font-weight:\s*bold[^"]*">(.*?)</span> - Replacement:
<strong>$1</strong> - Description: Converts Google Docs styled spans to proper HTML elements
- Pattern:
- Fix Microsoft Word's special quotes
- Pattern:
(“|”) - Replacement:
" - Description: Replaces curly quotes with straight quotes for better compatibility
- Pattern:
- Remove class attributes
- Pattern:
\s*class="[^"]*" - Replacement: ``
- Description: Strips class attributes that might contain website-specific styling
- Pattern:
- Convert div tags to paragraphs
- Pattern:
<div([^>]*)>(.*?)</div> - Replacement:
<p$1>$2</p> - Description: Converts div elements to paragraph elements for cleaner Markdown conversion
- Pattern:
Markdown Regex Replacement Examples
- Add callouts to blockquotes starting with Note:
- Pattern:
> Note:(.*?)(\n\n|\n$) - Replacement:
> [!note]$1$2 - Description: Converts simple note blockquotes to Obsidian callouts
- Pattern:
- Convert URL references to Obsidian wiki links
- Pattern:
\[([^\]]+)\]\(https://en.wikipedia.org/wiki/([^\)]+)\) - Replacement:
[[$2|$1]] - Description: Transforms Wikipedia links to Obsidian wiki links
- Pattern:
- Add tags to headings with specific keywords
- Pattern:
^(#+\s*.*?)(TODO|REVIEW|IMPORTANT)(.*)$ - Replacement:
$1$2$3 #task - Description: Adds a task tag to headings containing action keywords
- Pattern:
- Format dates consistently
- Pattern:
(\d{1,2})/(\d{1,2})/(\d{4}) - Replacement:
$3-$1-$2 - Description: Converts MM/DD/YYYY dates to YYYY-MM-DD format
- Pattern:
- Convert asterisk lists to dash lists
- Pattern:
^(\s*)\* - Replacement:
$1- - Description: Standardizes list formatting to use dashes instead of asterisks
- Pattern:
License
This project is licensed under the BSD Zero Clause License - see the LICENSE file for details.
