parseDOM: "attrs" is a matcher or not?

Hi, I fail to fully understand the behaviour of “attrs” in a “parseDOM”, here are 2 examples:

  1. parseDOM: [{tag: "span", attrs: {"class":"foobar"}]: here, all “span” elements will be matched, and their class will become “foobar”.
  2. parseDOM: [{ attrs: { "class": "foobar" }}]: here only elements with the class “foobar” will be matched

Do I understand correctly?

It seems to me that “attrs” does not behave as a matcher if there is already another matcher like “tag” (case 1). Instead, you should use getAttrs to both filter the elements you want, so only “span” with the “foobar” class), + select the attributes you want if the element matches.

However, it does behave as a matcher if its alone (case 2).

Is there something I am missing?

Side-question: in 1), what’s the effect of setting {“class”: “foobar”} specifically? It means we forget the element class and replace it by “foobar”?

Reference: ProseMirror Reference manual (it’s quite terse on “attrs”, “getAttrs” is clearer though)

No. attrs just provides the attributes to add to the ProseMirror node. It is never matched against the DOM, and does not relate to DOM attributes.

Thanks I think I got it better, previously I thought that parseDOM was needed to correctly identify that node in all scenarios, but (as the name suggest) it’s only when we actually want to parse the DOM.

A use case is for instance allowing to paste some HTML and correctly identify some known prosemirror node types within this HTML. And in this case getAttrs should be used, not attrs.

But when we load a prosemirror schema, it’s not needed, as node types are already stored in the schema.