Toggle "Show Invisibles"? #4120
|
Is it possible to toggle "Show Invisibles" on and off on a per-use (on for some |
Replies: 1 comment
|
There's no per-element option for Show Invisibles like there is for Line Numbers, but you can get the same result with CSS alone. The plugin works in two parts (
Because the display is pure CSS, you can make it opt-in per block by switching the pseudo-elements off everywhere except where you add a class: pre:not(.show-invisibles) .token.tab:not(:empty)::before,
pre:not(.show-invisibles) .token.cr::before,
pre:not(.show-invisibles) .token.lf::before,
pre:not(.show-invisibles) .token.crlf::before,
pre:not(.show-invisibles) .token.space::before {
content: none;
}<pre class="language-js show-invisibles"><code>...</code></pre> <!-- shows invisibles -->
<pre class="language-js"><code>...</code></pre> <!-- doesn't -->These selectors are more specific than the plugin's (for example Since it's only a class, you can also toggle it live without re-highlighting: button.addEventListener('click', () => pre.classList.toggle('show-invisibles'))Copy and paste isn't affected either way, because the glyphs are generated content and not part of the text. |
There's no per-element option for Show Invisibles like there is for Line Numbers, but you can get the same result with CSS alone.
The plugin works in two parts (
plugins/show-invisibles/onmaster, released as 1.30.0):before-highlighthook addstab,cr,lf,crlfandspacetokens to the grammar. The grammar is mutated once and shared, so every block in that language gets those<span class="token space">etc. There's no per-element check in the JS.·,⇥,␊…) are only::beforepseudo-elements on those spans. The actual whitespace characters are untouched.Because the display is pure CSS, you can make it opt-in per block by switching the pseudo-elements off ev…