问题
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