I want to make my own rules to a markdown parser
like the one here in StackOverflow.
That means, converting *italic*
into <span style="font-style:italic">italic</span>
.
I know there are a lot of Parsers out there, but i don't understand them. The question previously mentioned doesn't really give me a lot to go on, it just links to more parsers and doesn't explain how they work.
So I would like to know the basics, or the logic, of creating a whole markdown parser, and if you think explaining it to me it's not a pleasent task then don't. Thanks for understanding :)
A common way of doing this, is by using a RegExp expression, followed by the replace method.
This is one way you could do this:
"*This is italic*"
.replace(/\*(.*?)\*/gi, '<span style="font-style: italic">$1</span>');
What is happening here is that you are searching for any sequence of characters surrounded by the two asteriks and capturing those characters so then you can put them between the HTML tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With