如何使用django-mdeditor在前端呈现markdown内容?

时间:2019-11-16 15:11:01

标签: django markdown

我在我的项目中使用django-mdeditorhttps://github.com/pylixm/django-mdeditor)。我已将编辑器集成到管理面板中。如何在前端呈现已保存的降价内容?

django-mdeditor必须使用某些函数在其编辑器中生成实时预览。我的问题的解决方案将是找到该特定功能。然后,我可以使用相同的功能在前端呈现内容。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

我提出了一个问题-https://github.com/pylixm/django-mdeditor/issues/67,存储库所有者的回复解决了我的问题。

简而言之,遵循此template-https://github.com/pylixm/django-mdeditor/blob/master/mdeditor_demo_app/templates/show.html的内容。

包含-

<link href="{% static 'mdeditor/css/editormd.min.css' %}" rel="stylesheet">
<link href="{% static 'mdeditor/css/editormd.preview.css' %}" rel="stylesheet">

位于模板的<head></head>上。

,并包含-

<script src="{% static 'mdeditor/js/jquery.min.js' %}"></script>
<script src="{% static 'mdeditor/js/editormd.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/marked.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/prettify.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/raphael.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/underscore.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/sequence-diagram.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/flowchart.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/jquery.flowchart.min.js' %}"></script>
<script>
  $(function () {
      // content is the id of the <tag> you want to be render.
      // Refer to the link of the template shared with this answer.
      editormd.markdownToHTML("content", {
          emoji           : true,
          taskList        : true,
          tex             : true,  
          flowChart       : true,  
          sequenceDiagram : true,  
      });
  })

</script>

模板<body>的末尾。

就这样:D