3

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?

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

As has already been mentioned the syntax was not quite correct for having the return of the pipe be the actual inner HTML.

I would also recommend using a library for markdown to HTML conversion rather than try and do this yourself. Save yourself the time :)

All you need to do is pass the argument of the pipe to the library entry point and return the HTML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.