Indeed, this is just to handle an edge case where it’s ambiguous whether you’re going to type a header or a hashtag, you can ignore it for the purposes of what you’re trying to do.
Yes, this code handles rendering of markdown with live preview, so indeed in templates and query renderings for instance. It’s one of the places where you’d want to make your change.
Yes, you cannot really make styling changes here. In style.ts on line 52, you see:
{ tag: ct.HashtagTag, class: "sb-hashtag" },
But unfortunately you cannot add content-based styling this way, just additional fixed style attributes.
To do what you want to do, you unfortunately would have to create a codemirror plugin along the lines of web/cm_plugins/link.ts
(which replaces the rendering a link with a custom <a href>
element). What you can do is create a copy of this plugin, load that in clean.ts
, but let it act on “Hashtag” nodes instead of “Link” nodes, and work from there. Basically you’d want it to render as a custom span
tag, and attach the data attributes there.
Hopefully this is enough of a pointer to help, I could dive deeper but quickly I’d end up giving you the actual implementation, which would be cheating