Replies: 5 comments
-
This follows the CommonMark spec:
If you put a blank like between the <p>
fdsfsd **test** sdfsdfs
</p> Result:
fdsfsd test sdfsdfs Or you can continue using HTML <p>fdsfsd <strong>test</strong> sdfsdfs</p> |
Beta Was this translation helpful? Give feedback.
-
@UziTech I see, thanks. Would be nice to have an option to force parse markdown inside html tags. It will solve lots of issues with markdown in WYSIWYG editors. |
Beta Was this translation helpful? Give feedback.
-
You could create a renderer for that. Something like: const marked = require('marked');
// Override html renderer
const renderer = {
html(html) {
// pull out inner markdown
const match = html.match(/^(<[^>]+>)(.*)(<[^>]+>)$/);
// run markdown through marked again
return match[1] + marked(match[2]) + match[3];
}
};
marked.use({ renderer });
console.log(marked('<p>asdf **test** asdf</p>'));
// <p><p>asdf <strong>test</strong> asdf</p></p> |
Beta Was this translation helpful? Give feedback.
-
@UziTech I'm trying to create a render like you mentioned, but can't figure it out. Consider the following input: <div>
<h1>Content</h1>
like, *markdown*;
or, [links](//example.com)
</div> The first iteration of your modified renderer runs fine and strips away the <h1>Content</h1>
like, *markdown*;
or, [links](//example.com)
gets passed into the HTML renderer override — and can't be matched since it's a mix of HTML and markdown and there is no wrapping HTML tag. I would have thought the tokenizer takes care of this? Any hints? The last version where HTML can be mixed seamlessly with markdown seems to be 0.3.1, so I'll have to downgrade for now. |
Beta Was this translation helpful? Give feedback.
-
@neopostmodern my code above is just a proof of concept, you will have to change it to work with your use case. There are a lot of edge cases that need to be thought of to make it work with any markdown. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Markdown inside
<p></p>
is not parsedTo Reproduce
Steps to reproduce the behavior:
Expected behavior
Should parse markdown inside html
<p>
tag.Beta Was this translation helpful? Give feedback.
All reactions