unwrapDisallowed still removes numbers from numeric list #921
-
Hello! <ReactMarkdown
plugins={[remarkGfm]}
allowedElements={['em', 'text', 'strong', 'code', 'a', 'span', 'p', 'br']}
unwrapDisallowed={true}>{content}</ReactMarkdown> Still removes the numbers (1.) from the text, after input:
When trying to use this solution, it throws an TypeError:
Are there any options for solving this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Disabling constructs changed with the arrival of micromark https://github.com/micromark/micromark#case-turn-off-constructs The list construct is named Put all that together you get something like https://codesandbox.io/s/disable-list-tokenizer-7poch code exampleimport React from "react";
import Markdown from "react-markdown";
import remarkGfm from "remark-gfm";
const markdownSource = `
# heading
* list
* items
1. list
2. items
`;
function remarkDisableLists() {
const data = this.data();
function add(field, value) {
const list = data[field] ? data[field] : (data[field] = []);
list.push(value);
}
add("micromarkExtensions", { disable: { null: ["list"] } });
}
const App = () => (
<Markdown
unwrapDisallowed
allowedElements={["em", "text", "strong", "code", "a", "span", "p", "br"]}
remarkPlugins={[[remarkGfm], [remarkDisableLists]]}
>
{markdownSource}
</Markdown>
);
export default App; |
Beta Was this translation helpful? Give feedback.
Disabling constructs changed with the arrival of micromark https://github.com/micromark/micromark#case-turn-off-constructs
The list construct is named
list
https://github.com/micromark/micromark/blob/893a8d6b0e5c7a681a0faed3cd55cdbeafabe2d7/packages/micromark-core-commonmark/dev/lib/list.js#L24-L26Applying a micromark extension in a remark plugin looks like https://github.com/remarkjs/remark-directive/blob/2cfea20ae7d29038cb91e01bb9731ffbc0a1d052/index.js#L16-L19
Put all that together you get something like https://codesandbox.io/s/disable-list-tokenizer-7poch
code example