Closed dGilli closed 3 years ago
{{ dump(node.rawNode) }}
:
array(3) {
["type"]=>
string(7) "heading"
["attrs"]=>
array(2) {
["textAlign"]=>
string(5) "start"
["level"]=>
int(1)
}
["content"]=>
array(1) {
[0]=>
array(2) {
["type"]=>
string(4) "text"
["text"]=>
string(28) "..."
}
}
}
{{ dump(node.rawNode.content) }}
:
Key "content" for array with keys "type, attrs" does not exist.
I think the issue here is your use of node.getContent()[0]
because this returns a Text
node, which indeed doesn't have a tagName
.
To get the tagName
of the heading node, it's node.tagName
. Not the inner content (which is a Text node).
{{ dump(node.tagName) }}
would output h1
or the respective heading you've picked.
Using node.text
on a heading node is also technically correctly null
. I'm pretty sure this comes down to how Prosemirror handles a heading node's content, because a heading's child content can be marks or text, so it needs to be structured like that.
You could do {{ node.content[0].text }}
to get the heading text - but be warned that as I've mentioned above, if there are nested marks (say, a portion of the heading has bold/italic, or nested nodes like Link nodes, this won't be a great way to get content, because it'll just be getting the first node of content.
I hope that makes sense - ProseMirror's schema is a little to get your head around. We'll be looking to make this a bit more developer friendly as Vizy grows.
Description I am trying to add the text of headings as their Id.
node.tagName
andnode.text
both return NULL.Steps to reproduce
node.tagName
andnode.text
return NULL.Additional info
Additional context I am able to get the tag through
node.getTag()[0].tag
butnode.getText()
also returns NULL. When I try to get at the text vianode.getContent()
it cleary returns an array but then errors withKey "0" does not exist as the array is empty.
when trying to getnode.getContent()[0].text
: