Parsedown, add sub/superscript

元气小坏坏 提交于 2019-12-11 08:12:24

问题


I am trying to add sub/superscript to Parsedown.

Parsedown's functions seem like a jungle to me. I've been trying to understand it but have been unable to decipher it.

Turning ~text~ into <sub>text</sub> seems to be more of a challenge than I'd thought.

Wrapping my head around the structure of his code, is just something that I can't and any help would be extremely appreciated.


回答1:


This is a very simple regex.

Use:

\~(.*)\~|\^\((.*)\)

With the substitution <sub>\1\2</sub>

There are two groups in the regex. The key thing here is that the groups won't match at the same time, this is why you can use \1\2

DEMO

Try to understand it and improve if you need something more sophisticated.



来源:https://stackoverflow.com/questions/25868146/parsedown-add-sub-superscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!