-
Notifications
You must be signed in to change notification settings - Fork 5
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
Lists with newlines between the items are malformed #65
Comments
Hey @tomkelsey, thanks for reporting this! Glad you find this package helpful 🙂. I think what’s happening here is that the filtering does not recognise this as a single list because of the newlines, but it might be easier to understand if you can share the Could you also clarify what you mean by "newline"? Whether it’s creating a new block in the editor, or whether it’s just inserting a line break ( |
Hey thanks for getting back to me :) I guess the easiest example I've just thought of is if you input:
Into an editor and run the filter the output will be:
When I guess I'd expect it to just be For my original example:
Is converted to:
Perhaps a solution (if possible) would be to check that the number in the first bullet point is 1 before converting to an ordered list? If greater than 1 leave as plain text? I guess that would cause my second example to still be wrong - the first item would be converted to a list but the subsequent items would be plain text. Perhaps you could also check that there is more than one item before converting to a list? That way my second example would all stay as plain text |
With your extra description I think it’s quite clear to me that what you are running against is intentional. Those blocks are converted to list items because they are prefixed with something the filters recognise as a list prefix, and that conversion is needed to retain ordered lists from Word, Google Docs and Dropbox Paper. It also makes sense that it’s creating list items all numbered "1.", since all the list items in the input are separated by unstyled blocks (not newlines). To solve your problem, I think the easiest you could do would be to redefine your own draftjs-filters/src/lib/filters/editor.js Lines 89 to 149 in 2f5294b
Everything in there is meant to be reusable and composable, except for Anyway, I’ll see if I can think of a good way to make this behavior configurable without resorting to defining your own |
The `filterEditorState` options now have an optional `blockTextRules` parameter, which allows users to use their own text-based block conversion rules, or entirely disable the conversions by passing an empty array. By default, `blockTextRules` is set to the filters’ built-in prefix rules for list items.
…#127) The `filterEditorState` options now have an optional `blockTextRules` parameter, which allows users to use their own text-based block conversion rules, or entirely disable the conversions by passing an empty array. By default, `blockTextRules` is set to the filters’ built-in prefix rules for list items.
The `filterEditorState` options now have an optional `blockTextRules` parameter, which allows users to use their own text-based block conversion rules, or entirely disable the conversions by passing an empty array. By default, `blockTextRules` is set to the filters’ built-in prefix rules for list items.
@tomkelsey I’ve just pushed a change which should be released shortly, and allow you to disable or customise this behavior, onFilter = () => {
const { filtered, extended } = this.props
const filters = {
blocks: Object.keys(extended ? BLOCKS_EXTENDED : BLOCKS),
styles: Object.keys(extended ? STYLES_EXTENDED : STYLES),
entities: ENTITIES,
maxNesting: extended ? MAX_NESTING_EXTENDED : MAX_NESTING,
whitespacedCharacters: ["\n", "\t", "📷"],
+ blockTextRules: [],
}
const filteredState = filterEditorState(filters, this.state.editorState)
this.setState({ editorState: filteredState })
} Note setting draftjs-filters/src/lib/filters/editor.js Lines 65 to 98 in 2850d72
I hope this helps! |
🎉 This issue is fixed in v2.3.0, available on npm: draftjs-filters@2.3.0. Generated by 📦🚀 semantic-release |
Many thanks @thibaudcolas :) Will have a look at this next week hopefully! |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Lists with newlines between the items are malformed
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. GIFs and screenshots are very helpful too.
On entering text such as (NB: copy/pasting from below didn't work - I had to type it)
With an explicit newline between each point and then running the filter the output is:
What is the expected behavior?
I think the output should be:
Either reformatted as a list or as plain text but still preserving the correct numbers.
Which versions of the filters or of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of the filters / Draft.js?
I cloned the repo and edited
FilterableEditor.js
to have a new on-demand filter button:With the filter as follows:
PS. Great stuff with this package - its super helpful :)
The text was updated successfully, but these errors were encountered: