I'm currently working on a online text editing system that works with markdown files. The editor works fine (markdown input is parsed with marked.min.js for the preview while the user edits the file), but I found a weird hiccup when implementing a page for display-only purposes.
I want to use the same markdown parser, so the file has to be parsed at the side of the client with marked.min.js
I wanted to pass the markdown code within <pre>
-tags, such that if the js fails for some reason, the markdown file is displayed as it would be in a normal text-editor (the best readable format). To parse and replace the text with the formatted text I just use the following:
window.onload=function(){
document.getElementById('markdown-description').innerHTML =
marked(document.getElementById('markdown-raw').innerHTML);
}
However I see that somehow all quotes are not parsed all, while it does work in the editor. I can see all >
marks when I disable the parser and view the markdown file inbetween the <pre>
tags.
Even the following works:
window.onload=function(){
document.getElementById('markdown-description').innerHTML =
marked('# This\n\This is a HTML5 Markdown editor.\n\n> The overriding design goal for Markdown\'s\n> formatting syntax is to make it as readable\n> as possible.\n\nThis text you see here ');
}
Can someone explain why this is going wrong?
My HTML code:
<div class="description" id="markdown-description"><pre id="markdown-raw"> # Dillinger
Dillinger is a cloud-enabled, mobile-ready, offline-storage, AngularJS powered HTML5 Markdown editor.
- Type some Markdown on the left
- See HTML in the right
- Magic
Markdown is a lightweight markup language based on the formatting conventions that people naturally use in email. As [John Gruber] writes on the [Markdown site][df1]
> The overriding design goal for Markdown's
> formatting syntax is to make it as readable
> as possible. The idea is that a
> Markdown-formatted document should be
> publishable as-is, as plain text, without
> looking like it's been marked up with tags
> or formatting instructions.
This text you see here </pre></div>