我目前正在开发一个处理降价文件的在线文本编辑系统。编辑器工作正常(当用户编辑文件时,markdown 输入使用marked.min.js 进行解析以进行预览),但是在实现仅用于显示目的的页面时,我发现了一个奇怪的打嗝。
我想使用相同的降价解析器,所以必须在客户端用marked.min.js解析文件我想在<pre>
-tags中传递降价代码,这样如果js由于某种原因失败, markdown 文件会像在普通文本编辑器中一样显示(最好的可读格式)。要使用格式化文本解析和替换文本,我只需使用以下内容:
window.onload=function(){
document.getElementById('markdown-description').innerHTML =
marked(document.getElementById('markdown-raw').innerHTML);
}
但是,我发现所有引号都没有全部解析,而它在编辑器中确实有效。>
当我禁用解析器并查看标记之间的降价文件时,我可以看到所有标记<pre>
。甚至以下工作:
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 ');
}
有人可以解释为什么会出错吗?
我的 HTML 代码:
<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>