Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a markdown string to html code

Tags:

angular

I'm trying to parse a string which contains some Markdown code (like bold or italic), and I want it to be parsed and shown as HTML code.

I created a pipe which detects some Markdown tags (bold and italic only at the moment), so it car convert it into html tags like this:

<span>{{ line | markdown }}</span>

Imagine the following string this is *italic* and this is **bold**.

The parsing is working, so it returns this line:
this is <em>italic</em> and this is <strong>bold</strong>.
The problem is the page doesn't interpret the String as html code, but a plain text.


So I tried to ad [innerHTML] tag like this:

<span [innerHTML]=line>{{ line | markdown }}</span>

Now, the page shows this :
this is *italic* and this is bold


Why does it parse the bold but ignores italic, and how can I get what I want?

like image 390
vanR Avatar asked Jan 28 '26 01:01

vanR


1 Answers

it should be <span [innerHtml]="line | markdown"></span>. it this case output of a pipe will be passed as innerHtml to a span

like image 161
Andrei Avatar answered Jan 29 '26 20:01

Andrei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!