Use of 'span' by ProseMirror


I can probably create an isolated example to reproduce the issue, but taking a chance that it may be easy to identified without one.

I have a custom node type extending Inline and producing a ‘span’ as its DOM. I wish to have arbitrarily deep span trees essentially because my "prose’ will have a lot of structure. So instead of having a plain paragraph containing a text node, I end up with two intermediary nodes generating two nested span DOM elements like this:

  <p pm-container="true" pm-offset="0" pm-size="40">
    <span pm-container="true" pm-offset="0" pm-size="38">
      <span pm-offset="0" pm-size="36">This is the beginning of our story. </span>

As a result, that line of text becomes inaccessible - I can’t position the cursor inside it and type something. The whole thing seems to be treated as a read-only block and some blue rectangle appears drawn around it.

Any clues?

Thanks! Boris

Only text represented as actual text nodes in your document is going to be editable. Just rendering a node as containing text won’t have that effect, it’ll be treated as an inline leaf node that can only be selected as a unit.

(Issue #114 may be relevant for you)

I do have actual text nodes inside my custom nodes. My custom nodes are there just to group together and annotate pieces of text with some extra attributes that I want to put in. Issue #114 might be relevant, I guess because if it worked it could maybe solve my problem. I also tried extending “Block” which didn’t work either because “Invalid content for node paragraph”. So if paragraphs can only have inline content, I need some sort of inline internal node.

Maybe there is an alternative way to accomplish my goal? Suppose I want to annotate a sentence with a grammatical parse:

Joe ate the apple.


 <p><span><span category="subject">Joe</span> <span category="verb">ate</span> etc.. </p>

It’s something like this I’m trying to achieve. I’m fine if my internal nodes don’t translate to HTML and are in fact invisible, that would be better actually, but not sure what the implications are to the editing transforms: I want the same piece of text to keep its annotations without me having to keep track of positions.

Is that achievable?

Thanks! Boris

Using marks on the pieces of text might work.

Thanks, I’ll try that. I really wanted attributes :slight_smile:

Actually scratch that, it’s not attributes vs. marks, but the structure of the document that I’d like to feed ProseMirror. I can create a custom node type extending Text and have custom attributes. That works. What I don’t know how to do is group textual bits in a hierarchical way. In the above example where I just assign part of speech to each word in a sentence, the sequence is still linear so having a Fragment of several consecutive Text nodes will work. But what if I wanted to represent the deeper syntax structure marking a noun phrase, a clause in more complex sentence etc. The only option I can think of is to keep that structure outside ProseMirror and keep the two structures (ProseMirror’s model and mine) and sync.

If there is no ProseMirror-based solution with the current version, could you tell me if the architecture of the library would allow such a solution to be developed in the future?

Probably not. The flat structure of text content is a well-considered part of the design (some very early versions had DOM-style nested inline content, and it was impractical to work with).

Makes sense, ok. Yes, I remember reading about that design decision somewhere in your docs. It sounds like a good decision, it’s already complicated enough and maintaining the deeper structure separately and independently is probably better anyway. Now I have to see if there is a good enough event mechanism in ProseMirror that would allow me to synch its document model with mine :slight_smile: (I now of your Subscription module and I’m using - great work too!, but I don’t know yet what types of events ProseMirror exposes as part of a public API)

Thanks! Boris

Hi Boris. Did you come to any solution?


Yes and no: it’s as I mentioned in my last post on that thread, I had to maintain a separate structure and synchronize with ProseMirror. So that’s what I’m doing. It’s a real pain though. I have two independent models of the text and I have lots of code dealing with them being in sync. And overtime I’ve started to doubt the utility of ProseMirror to begin with, but for the moment I’m stuck with it.