-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add inputTags as an option to blockerRenderMap config
#584
Conversation
Allow user to specify `inputTags` as an array of tag names that will
get mapped to draft js block types. If `inputTags` are not specified,
fall back to `element`.
Change default blockRenderMap to support `p` and `div` as unstyled blocks.
For example, a blockRenderMap of
```
{
'header-one': {
element: 'h1',
inputTags: ['h2, 'h3'],
},
header-two': {
element: 'h2',
inputTags: ['h1'],
},
}
```
will map
```
<h2>Hello world!</h2>
```
and
```
<h3>Hello world!</h3>
```
to a `header-one` block, and will map
```
<h1>Hello world!</h1>
```
to a `header-two` block.
| .valueSeq() | ||
| .flatMap((config) => getInputTags(config)) | ||
| .toSet() | ||
| .filter((tag) => tag && tag !== unstyledElement) |
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 wasn't sure why we were specifically filtering out unstyled blocks. Adding this filter back fixes the failing test, but it breaks the intended functionality of allowing p tags to be mapped to an unstyled block.
|
Thanks for looking into this, I am unable to contribute to Draft until after the October 15th |
|
Does anyone have any context as to what it must NOT treat divs as Ps when we pave Ps is testing? That's the one failing test in this PR -- everything else seems to be working correctly. |
|
I dug into this a bit, and it looks like the failing test is converting html that looks like the following: My changes will generate a blockmap that looks like that looks like whereas the current behavior will generate a blockmap that looks like and looks like which seems like a reasonable change. |
|
@mitermayer who needs to sign off to get this merged? |
|
I thinks this PR should resolve #395 #465 #523 #738 . Also it has related opening PR #571 . Our project is using a patched DraftJS based on version 0.9.1 with this PR merged. And it has been online for 1 month without any related bug report. So if anyone could check the failing test and accept this PR, that would helps a lot! |
|
@hellendag can you help here? |
|
Hi @howardjing, thanks for working on this issue, closing this since it has already been fixed on #828 |
|
@mitermayer cool! Thanks for closing this out. |


This PR addresses the same concerns as #488 and #571. I saw a suggestion to add an
inputTagsoption toblockRenderMap, but it didn't look like anybody had gotten around to implementing it.This commit also introduces a failing test
I wasn't sure of the background behind this test so I left it failing for now.
Summary
Allow user to specify
inputTagsas an array of tag names that willget mapped to draft js block types. If
inputTagsare not specified,fall back to
element.Change default blockRenderMap to support
panddivas unstyled blocks.For example, a blockRenderMap of
will map
and
to a
header-oneblock, and will mapto a
header-twoblock.Test Plan
<p>tags into draft js editor. Each paragraph should be split up into a separate block.