I am using markdown-it, but when I try to use text with multiple lines, I get this error:
Uncaught SyntaxError: Invalid or unexpected token
Here is the code
Anything without multiple lines works
Any ideas? Any help appreciated
At the end of the
var content line can you try adding a ;?
Didn’t change it
However, I found that if I put the text into a textarea with an id of content and then using:
var result = md.render(document.getElementById('content').value);
works but I would rather find out why this isn’t working
Can you try putting all of the items of var content on the same line? Replace the line breaks with
I was wondering if I needed to change all line breaks to \n
Not sure if markdown handles that, I just know
That’s not the point though as it’s supposed to be written in markdown not html
I don’t think markdown supports \n
After lots of searching, I can fix it with this:
<script> var md = window.markdownit(); var content = "<%=JSON.stringify(topicfound.content)%>" var contentnew = content.replace(/"/g, ""); var result = md.render(contentnew); document.getElementById('test').innerHTML = result; </script>
Markdown It and all other markdown engines out there does support small HTML such as
According to the screenshot you have provided and judging from the syntax highlighting, you can use single quotes for a single line only and not for multiple lines.
let str = 'This is a string across various lines'
This will not work (although synatx highlighting of Discourse looks good to me ) but if you need to use a string with multiple lines, use a backtick which ES6 supports.
let str = `hi there string`
This also works and solves the issue, but my line breaks now don’t work I’ll just stick to the JSON stringify method, but thanks for the help. I will know know that in the future
Try using Marked.js. It’s more browser friendly, has 22.7K stars which is more than Markdown It and supports small-scale HTML. You can use https://markme.glitch.me if you want to try Marked.js, MarkMe uses Marked.js.
The Bootstrap Markdown editor I am using uses markdown-it and I want to keep the Markdown shown the same as when the person edits it, but I will have a look at Marked.js