Someone Special
Someone Special

Reputation: 13588

React-Markdown disable parsing of underscore

I'm using react-markdown to render markdown strings.

However in my strings, I have underscore to indicate blank words to fill in

e.g My ____________ is awesome.

However it renders as "< strong >__< /strong >, even when i disable < strong > type, it renders only __ but i want it to be the original __________

Or is there another renderer which can do it?

Upvotes: 1

Views: 1487

Answers (1)

Sebastian B.
Sebastian B.

Reputation: 2201

Seems a hard task with official API. According to my tests, unwrapDisallowed doesn't help as it's an option to be even more restrictive (remove the strong markers with content altogether).

And depending on your codebase and the depth of integration of react-markdown, selecting another Markdown renderer may be a big task (polished styling, customizations, ...)

You could fork the lib and try to remove the strong parsing, but then you have the burden of building and re-integrating upstream patches as long as you're using the component. A modification that could be merged upstream would be a solution, but I can imagine that such a modification is no easy task, as most maintainers prefer generic solutions (in my experience).

My proposal is a workaround as a compromise:

You could replace all underscores with something similar looking before assigning the content to react-markdown. The parser wouldn't interpret this as "strong" markup. Possible candidate: e.g. '\uff3f' (https://www.fileformat.info/info/unicode/char/ff3f/index.htm) (caveat: wider than a regular underscore)

Upvotes: 2

Related Questions