xryul_gremlins/README.md

4.1 KiB
Raw Permalink Blame History

https://github.com/user-attachments/assets/809503f0-1a39-4567-91f3-258359d5f146

Gremlins for Obsidian

Gremlins reveal invisible characters (inluding curly quations marks and em dashes).

Lightweight and loads under 1ms on most systems.
Can sit in the background - just load and forget.
If you ever paste something that has many unicodes, Gremlins flag them. To replace every flagged character on a line, simply squash the Gremlin by clicking its gutter icon.

Gremlins highlighting mixed indentation and invisible Unicode characters in Obsidian

Features

  • Flags invisible or unusual Unicode characters, mixed indentation, malformed list indentation when enabled, and optionally typographic punctuation (curly quotation marks, en dashes, and em dashes). See details below.
  • Shows an icon beside every visible line containing a gremlin (optionally, you can click the icon to fix the character immediatly)
  • Works in Source mode and Live Preview.

The plugin checks four groups of rules.

1. Invisible or potentially dangerous Unicode - enabled by default

Unicode Character Fix when explicitly requested
U+0003 End of text control Delete
U+000B Line tabulation/vertical tab Newline
U+00A0 Non-breaking space Ordinary space
U+00AD Soft hyphen Delete
U+180E Mongolian vowel separator Delete
U+2007 Figure space Ordinary space
U+200B Zero-width space Delete
U+200C Zero-width non-joiner Delete
U+200E Left-to-right mark Delete
U+200F Right-to-left mark Delete
U+2028 Unicode line separator Newline
U+2029 Unicode paragraph separator Blank line
U+202AU+202E Bidirectional embedding/override controls Delete
U+202F Narrow non-breaking space Ordinary space
U+2060 Word joiner Delete
U+2066U+2069 Bidirectional isolate controls Delete
U+FEFF Zero-width no-break space/BOM Delete
U+FFFC Object replacement character Delete

Bidirectional controls and invisible characters are highlighted because they can make text appear different from its actual stored order or produce confusing Markdown, searches, and diffs.

2. Mixed indentation - enabled by default

It detects indentation at the beginning of a line containing both tabs and spaces.

When fixed, indentation made from tabs followed by stray spaces keeps its tabs and removes the trailing spaces. Other mixed indentation becomes spaces while preserving its visual width using Obsidian's current indent visual width.

It does not flag indentation made entirely from tabs or entirely from spaces.

3. List indentation - disabled by default

It detects space-indented Markdown list items whose indentation is not a multiple of Obsidian's current Indent visual width setting. Unordered, ordered, and task list items are supported; indented prose and code are ignored.

When fixed, indentation is rounded to the nearest level, with ties rounded to the deeper level. For a four-space indent width, one space becomes no indentation, two or three spaces become four, five spaces becomes four, and six or seven spaces become eight.

Fixes preserve the line's indentation style: space-indented list items remain spaces, while tab-led mixed indentation keeps its tabs.

4. Typographic punctuation - disabled by default

Unicode Character Optional replacement
U+2013 En dash Hyphen -
U+2014 Em dash Hyphen -
U+2018 / U+2019 Curly single quotes Straight apostrophe '
U+201C / U+201D Curly double quotes “ ” Straight quote "

Important

The plugin does not automatically replace anything:

  • Click gutter icons to fix is disabled by default.
  • Without it, Gremlins only highlights and explains characters.

Inspiration

This plugin is independently implemented for Obsidian and inspired by Gremlins tracker for Visual Studio Code, released under the MIT License by Nicolas Hoizey.