mattcoleanderson / obsidian-dynamic-text-concealer

Obsidian.md Plugin to conceal or replace user configured text patterns in Live Preview and Read Mode.
MIT License
7 stars 0 forks source link

Formatting within match is not preserved #25

Closed mattcoleanderson closed 7 months ago

mattcoleanderson commented 7 months ago

Markdown in live preview and read mode is converted to HTML elements. The result is a string in markdown like the following:

A **Bit** is the _most_ basic [[Unit of Information]].

Would be transformed into the following HTML (more or less):

<p>
  "A "
  <strong>Bit</strong>
  " is the "
  <em>most</em>
  " basic "
  <a href="Unit of Information">Unit of Information</a>
  "."
<\p>

The current implementation replaces the whole match with the first capture group. Essentially replacing the transformed html elements with the Markdown flavoring.

A solution could be to stop using CodeMirror Replace Decorators in favor of CodeMirror Mark Decorators. This would wrap the text we wish to conceal with an element of a specific class name, then use css styling to hide all instances of that class.

This would change the way regex expressions need to be written. Instead of making a single capture group for the content you wish to be displayed, you would create multiple capture groups for the content you don't wish to be displayed.