Poem node (custom whitespace rules)

I’m considering some rather involved solutions to a challenge my team is having at the moment (Poem text entry) and wanted some feedback on how feasible this seemed before prototyping anything.

I’m thinking about adding a custom node in our schema that would support different whitespace rules vs a regular paragraph. I’m assuming I’ll at minimum need a custom nodeview that sets different whitespace rules for display, but I’m also wondering if I’ll need to override DOMParser’s preserveWhitespace options somehow to allow things like pasting in a formatted poem from another text editor.

I’d be much obliged if anyone has done something similar and wants to throw me a “go for it”, or “here be dragons”.

There’s a least one dragon: if you set CSS white-space to anything other than pre-wrap, browsers will behave badly when you enter multiple spaces in a row (which happens even during normal text entry when you want to start a word before a space)—Firefox will collapse your two spaces, Chrome will turn one of them into a non-breaking space.

You could consider just making all spaces inside poem nodes non-breaking to work around this (either through capturing input, including pasted input, and transforming it, or with an appendTransaction plugin that fixes this up in a separate transaction). Enabling preserveWhitespace in your parse rule for that node, to prevent the parser from collapsing spaces, would probably be a good idea.