1

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.

Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201
Jesper Jacobsen
  • 151
  • 2
  • 13
  • I have looked through the source, tried to find heads and tails in it, but wasn't really able to. I also tried to learn Regex some months ago, but it seemed quite overwhelming and I ended up postponing it until the coming christmas holiday. I know it's not just for doing my work, but I really have no idea what to do about it right now. – Jesper Jacobsen Sep 16 '14 at 12:06

1 Answers1

2

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.

Oscar Hermosilla
  • 480
  • 5
  • 21