Hello,
I’m trying to parse HTML headings with simple ProseMirror schema that should add attributes whenever specific heading is present.
Whenever I add
{
tag: 'h2[class]',
getAttrs: d => {
const type = d.getAttribute('class');
return availableClasses.indexOf(type) > -1
? {
class: type
}
: false;
}
},
to parseDOM
the output is without proper heading level.
[
{
"type": "paragraph",
"content": [
{
"type": "text",
"marks": [
{
"type": "styled",
"attrs": {
"class": "headline2"
}
}
],
"text": "Here text from heading"
},
{
"type": "text",
"text": "Here text from paragraph "
}
]
}
]
but when it’s not present everything is parsed fine without attributes
[
{
"type": "heading",
"attrs": {
"level": 2
},
"content": [
{
"type": "text",
"text": "Here text from heading"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Here text from paragraph"
}
]
}
]
What I need to have though is
[
{
"type": "heading",
"attrs": {
"level": 2
},
"content": [
{
"marks": [
{
"type": "styled",
"attrs": {
"class": "headline2"
}
}
],
"type": "text",
"text": "Here text from heading"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Here text from paragraph"
}
]
}
]
From docs ProseMirror Reference manual it looks like everything should be fine and this getAttrs
only add custom attributes. I’m following example from ProseMirror dino example but in it I don’t see anything about HTML parsing.
Am I doing something wrong here?
My codepen can be found here
Any suggestion would help. Thanks in advance!