Hey man, have you heard of JsTranformer's [1] they're a standard way of parsing strings in and out of different formats. Markdown-it [2] seems to do this too.
[1] https://www.npmjs.com/package/jstransformer
[2] https://github.com/jstransformers/jstransformer-markdown-it