react-markdown icon indicating copy to clipboard operation
react-markdown copied to clipboard

Support for <sub> and <sup>

Open srikanthbhamidipalli opened this issue 6 years ago • 7 comments

srikanthbhamidipalli avatar Mar 25 '20 12:03 srikanthbhamidipalli

is there any progress on this?

ellismarte avatar Apr 23 '20 00:04 ellismarte

There is a remark plugin to support this https://github.com/zestedesavoir/zmarkdown/tree/master/packages/remark-sub-super

Which may work already, if not https://github.com/rexxars/react-markdown/pull/428 would allow for it to work.

ChristianMurphy avatar May 17 '20 22:05 ChristianMurphy

@ChristianMurphy this plugin doesn't work. I am sorry but I am very confused trying to track down the issues/pull-requests regarding this feature. Is there someone who knows what we need to do to get a sub/sup tag working?

gtsop avatar Nov 30 '20 10:11 gtsop

If you are using an HTML tag to add sub/sup, then yes: that’s HTML and it’s dangerous.

If you want a markdown-like “construct”, remark-sub-sup hasn’t been updates for the latest parser, which is tracked here: https://github.com/zestedesavoir/zmarkdown/issues/416.

wooorm avatar Nov 30 '20 11:11 wooorm

If you are using an HTML tag to add sub/sup, then yes: that’s HTML and it’s dangerous.

If you want a markdown-like “construct”, remark-sub-sup hasn’t been updates for the latest parser, which is tracked here: zestedesavoir/zmarkdown#416.

I would like to use anything available really, markdown syntax preferable ofcourse to be more user friendly. Seems like the dangerous html route is the only way to get this working as of right now. I am personally ok with this because my input is very controlled by an admin, but I assume not everyone will be covered as I.

gtsop avatar Nov 30 '20 14:11 gtsop

We’re working on making the HTML better, such as sanitizing it by default (see @ChristianMurphy’s PR above), but we’re splitting it over several majors to not break too many things at once

wooorm avatar Nov 30 '20 14:11 wooorm

The way I solved this and other may find useful is as per below with use of components:

<ReactMarkdown remarkPlugins={[gfm]} children={props.content} components={{ em: ({ node, ...props }) => { if ( props.children[0] && typeof props.children[0] === 'string' && props.children[0].startsWith('^')) { return <sup>{props.children[0].substring(1)}</sup> } if ( props.children[0] && typeof props.children[0] === 'string' && props.children[0].startsWith('~')) { return <sub>{props.children[0].substring(1)}</sub> } return <i {...props} /> }, }}

with above code i can use ^® or ^th for superscripts and ~1 for subscripts.

hope above is useful.

ankurpiparsania avatar Apr 29 '21 09:04 ankurpiparsania