To add tooltips to block text for glossary terms I want to hook into the rendering of text blocks. I want to insert per matching word a Semantic-UI Popup component or something similar as an abbr node.
A block transformer (IBlockFieldSerializationTransformer) on backend side would be handsome but is not appropriate as it changes the block content permanently. I want the block text / value to be untouched.
you could do both a block serialization transformer and a deserialization transformer, so that the change is removed on deserialization
you could wrap the Slate block TextBlockView in your own block and mutate the value that's passed to the slate block renderer. Basically something like:
The difficulty will be implementing that mutateValue() function, as you'll want to mark some of the text as a "mark" or an "inline element", then implement the appropriate slate element component.
another option that I see would be to implement the above text block view component replacement trick, but instead of mutating the slate value, you use reactdom and render to an html string, then you're dealing with a plain HTML value which might be something that can be handled by some glossary libraries.
Thanks for your detailed answer. That confirms the way I took.
In an already customized TextBlockView for other purposes I use a customized serializeNodes method to parse the text and replace glossary term matches with Popup components. No extra slate element component but splitting the text and yielding span or Popup inside of <Leaf path={path} leaf={node} text={node} mode="view" key={path}>{node.text}</Leaf>
As for making it per-site section... special cases are always ugly and I don't have a good suggestion. Worst case scenario, make a "condition function" that is configurable and executed by each leaf... I think the performance would be fine, I wouldn't worry about that, but it feels suboptimal.