-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(rich-text-editor): allow any block inside list item #157
Conversation
✅ Deploy Preview for nifty-lalande-39c157 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
@@ -169,7 +169,7 @@ const nodes: { | |||
}, | |||
|
|||
list_item: { | |||
content: "paragraph block*", | |||
content: "block+", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only change to allow blockquotes in list items, is from forcing the content to have the first child be a paragraph with 0 or more block decadents, to having one or more of any block level element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double checked the commonmark spec for absolute correctness™, and it seems that list items allow basically any block element that isn't a horizontal rule, so this is good to go.
src/rich-text/commands/index.ts
Outdated
@@ -37,7 +37,7 @@ import { _t } from "../../shared/localization"; | |||
export * from "./tables"; | |||
|
|||
//TODO | |||
function toggleWrapIn(nodeType: NodeType) { | |||
export function toggleWrapIn(nodeType: NodeType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed to test blockquote command which is generated via this method. Other commands (like toggleHeadingLevel
) are exported from here as well, so no over-arching reason to keep private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you expose this method, you need to write documentation and unit tests for it 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, in a sense, this is actually the system under test when testing blockquotes can be inserted into lists. What we want to check is a) can we execute this command and b) does it apply the right transform. So there's a single existing test for it, but I added some more test cases for some basic coverage of toggling back and forth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems appropriate to me. You'll need to add new tests and documentation for the newly exported function though.
src/rich-text/commands/index.ts
Outdated
@@ -37,7 +37,7 @@ import { _t } from "../../shared/localization"; | |||
export * from "./tables"; | |||
|
|||
//TODO | |||
function toggleWrapIn(nodeType: NodeType) { | |||
export function toggleWrapIn(nodeType: NodeType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you expose this method, you need to write documentation and unit tests for it 😉
@b-kelly - should be all set - added node tree string to custom matchers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to add some parsing/serialization tests here as well. I'll do this later today before merge. Otherwise, I think this all looks good
@KyleMit I've added some markdown parsing and serializing tests - can you look into the failing one for me? |
@b-kelly, biggest gap was that there was a |
@KyleMit 🤦 Wow, that was a dumb mistake on my part! I knew the test should be working, but I guess I was too braindead at the time to realize it was that simple. I'll give this one last pass today and merge. |
Closes #63
Describe your changes
Schemas dictate which elements are allowed to appear under each node. The previous schema for list item content was
paragraph block*
, meaning the first child must be a paragraph then 0 or more blocks under that.If we want to allow blockquotes directly inside a list item, we'll have to open up and just allow
block+
, meaning one or more of any of the block level elements that we've allowed - including paragraphs, as well as blockquotes, codeblocks, etc.PR Checklist
/** ... */
docs (no changes to top level functions)bug
/enhancement
and other labels as appropriateAdditional context
Change is a somewhat simple one here. One thing I wanted to investigate in making this change is how other rich text editors handle this in the UI / Action.
So support for this specific feature elsewhere is not widespread. We already do allow someone to create a new line within a list item and insert a blockquote on it's own line.
That said, if our goal is to ever have parity between markdown editor and rich text editor, any content restrictions will hurt our ability to do that. In markdown, you are certainly allowed to type
* > blockquote list item
- so anyone starting from markdown can get themselves into a situation that our Rich Text schema would consider "invalid" if we have strict schema policies. So it's probably better to relax them, even if it leads to some odd (but perfectly valid) markup