Keydown/paste listener for a panel plugin

Hey there

I am working on a simple plugin to visually show hidden characters inside the panel (forum post, GitHub).

While it was relatively easy to replace whitespaces with characters from a custom font, I’m a little clueless how to visualize soft hyphens and <br> linebreaks. One idea is to wrap them in a span tag and using a css pseudo element to visually show the character/element afterwards. Later on they could be replaced with a regular expression hook to not show up in the frontend. – Even though I don’t know whether this is a good idea at all.

I had a look into the Writer Marks plugin from @johannschopplich, since it extends the writer field similar as needed. It feels a little dirty to create a mark without a button to get the spans rendered, but it works for preformatted content.

Now to my question: Would it be possible to extend Kirby with listeners to wrap elements in a span on keydown or paste? Is there a good starting point or another plugin to have a look at?

All the best
Jakob