Javascript 使用editor.md将多个标记文档呈现为HTML

Javascript 使用editor.md将多个标记文档呈现为HTML,javascript,markdown,Javascript,Markdown,我有这样一个模板 <div class="post-text"> <div id='article-editormd-view'> <textarea style="display:none;"> {{ article.content }} </textarea> </div> </div> 文章编辑器MD视图是ID 当我尝试在for循环中呈现多个注释时,如下所示: {% f

我有这样一个模板

<div class="post-text">
    <div id='article-editormd-view'>
        <textarea style="display:none;">
{{ article.content }}
        </textarea>
    </div>
</div>
文章编辑器MD视图
是ID

当我尝试在for循环中呈现多个注释时,如下所示:

{% for comment in page.object_list %}
<div class='comment-editormd-view'>
    <textarea style="display:none;">
 {{ comment.body }}
    </textarea>
 </div>
{% endfor %}


editormd.markdownToHTML("comment-editormd-view", {
htmlDecode      : "style,script,iframe",  // you can filter tags decode
emoji           : true,
taskList        : true,
lineNumbers     : false,
{%用于page.object_list%中的注释]
{{comment.body}}
{%endfor%}
markdownToHTML(“注释编辑器视图”{
htmlDecode:“样式、脚本、iframe”//您可以对标记进行筛选和解码
表情符号:没错,
任务列表:对,
行号:false,
它不起作用了


我通读了官方文档,但没有找到解决方案。

comment Editor MD view应该是元素的ID。因此,您的第一个单一文本框示例是有效的,因为您已将其设置为元素的ID

但是,当您尝试使用for循环执行此操作时,您将其设置为元素的类。因此,editor.md尝试使用选择器
#comment editormd view
,而不是使用选择器
。comment editormd view
在单个元素上发挥其魔力

一种可能的解决方案是使用一个计数器,每个div有一个不同的ID,并使用一个脚本为每个div创建一个文本框。类似这样的内容(代码未测试):

var计数=0
{page.object_list%}中的注释为%
计数++
{{comment.body}}
editormd.markdownToHTML('comment-editormd-view'+count{
htmlDecode:“样式、脚本、iframe”,
表情符号:没错,
任务列表:对,
行号:false
});
{%endfor%}
HTML元素ID:


HTML元素类:

对于那些仅仅因为editor.md示例稀少而在这个问题上结结巴巴的人:我没有让JS代码呈现任何东西,因为我将
id
分配给
元素,而不是它的父元素
。有一次我将父元素
div
id
传递给
editormd。markdownToHTML()
,按预期呈现。
{% for comment in page.object_list %}
<div class='comment-editormd-view'>
    <textarea style="display:none;">
 {{ comment.body }}
    </textarea>
 </div>
{% endfor %}


editormd.markdownToHTML("comment-editormd-view", {
htmlDecode      : "style,script,iframe",  // you can filter tags decode
emoji           : true,
taskList        : true,
lineNumbers     : false,
<script> var count = 0 </script>

{% for comment in page.object_list %}
  <script> count++ </script>

  <div id={{'comment-editormd-view' + count}}>
    <textarea style="display: none">
      {{ comment.body }}
    </textarea>
  </div>

  <script>
    editormd.markdownToHTML('comment-editormd-view' + count, {
      htmlDecode : 'style, script, iframe',
      emoji : true,
      taskList : true,
      lineNumbers : false
    });
  </script>

{% endfor %}