Skip to content

Commit 6abf937

Browse files
authored
PRO-8130: default node parseHTML now detects whether an element has the relevant class, or lack of one, before classifying it as a default node (#5017)
1 parent da1331c commit 6abf937

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Let the `@apostrophecms/page:unpark` task unpark all parked pages with the given slug, not just the first one.
1818
* Exclude unknown page types from the page manager.
1919
* Resolved an issue affecting `withRelationships` with two or more steps. This issue could cause a document to appear to be related to the same document more than once.
20-
20+
* Fixed a regression that prevented multiple variations of `p` with different classes from being recognized again when reopening the rich text editor, even if they are all on the style menu. This was caused by knock-on effects of upstream changes in tiptap and prosemirror and our previous efforts to mitigate these. Those upstream changes were correct, but they did have certain side effects in ApostropheCMS. By more fully specifying the desired behavior, we have now fully corrected the issue at the ApostropheCMS level.
2121

2222
### Security
2323

modules/@apostrophecms/rich-text-widget/ui/apos/tiptap-extensions/Default.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ export default (options) => {
4444
HTMLAttributes: attrs,
4545
levels: def.options.level ? [ def.options.level ] : null
4646
};
47+
},
48+
parseHTML() {
49+
return [
50+
{
51+
tag: 'p',
52+
getAttrs: el => {
53+
// We must make sure the DefaultNode is only
54+
// returned for the subset of elements that actually
55+
// match its class, or lack of one. Otherwise it will
56+
// hoover up all elements sharing its element name,
57+
// breaking the ability to have alternates with classes
58+
// listed in "styles" in the toolbar "stick" when you
59+
// open the editor again -Tom
60+
if (def.options.class) {
61+
return el.getAttribute('class') === def.options.class;
62+
} else {
63+
return !el.hasAttribute('class');
64+
}
65+
}
66+
}
67+
];
4768
}
4869
});
4970
}

0 commit comments

Comments
 (0)