Markdown-it with multiple lines error

Hey there!
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 :slight_smile:

At the end of the var content line can you try adding a ;?

Didn’t change it :frowning:
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 <br>

I was wondering if I needed to change all line breaks to \n

Not sure if markdown handles that, I just know <br> works.

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:

  var md = window.markdownit();
    var content = "<%=JSON.stringify(topicfound[0].content)%>"
    var contentnew = content.replace(/&#34;/g, "");
var result = md.render(contentnew);
    document.getElementById('test').innerHTML = result;
1 Like

Markdown It and all other markdown engines out there does support small HTML such as <br> and <kbd>.

1 Like

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 :joy:) but if you need to use a string with multiple lines, use a backtick which ES6 supports.

let str = `hi

This also works and solves the issue, but my line breaks now don’t work :joy: I’ll just stick to the JSON stringify method, but thanks for the help. I will know know that in the future :slight_smile:

1 Like

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 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 :slight_smile:

1 Like