DOM render depending on context

Hey, for citations there is at times a difference of how they appear based on what other citations come before or after it.

For example, a citation style could look like this:

The man came from the dark ages [S. Hamilton 1935: “The wise words”], but that doesn’t mean that he cannot learn [Hamilton 35: p. 123].

If one replaces the first citation, it may end for example like this:

The man came from the dark ages [P. Tillow 2001: “Fingerplay”], but that doesn’t mean that he cannot learn [S. Hamilton 1935: “The wise words” P. 123].

The dom serializer doesn’t seem to know about the rest of the document, so the way I solved it was to simply serialize to an empty span with all relevant information in data attributes, and then run a citation generator that looks for empty citation nodes, and if it finds any, recalculates all citations in the document.

This works well for adding citations. But how can I get it to recalculate the citations when one has been deleted? I assume you will tell me that I should add a range that crosses such nodes and then listen to the remove on that one, right? But wouldn’t I then have to look through the entire document for new citation nodes whenever the user has pasted something or in any other way could have added citations? Wouldn’t that be more costly than simply monitor the number of citations and check whether the number decreases/increases and just check for that about every second?

Any other way to do this that is more in line with ProseMirror’s philosophy?

ProseMirror does not support context-dependent rendering. The recommended approach is to render these uniformly in the editor view, and have your own serializer do the clever things you want to do when exporting this to HTML.

Ok, that’s fine. We can live with that.