美文网首页文章
资源 | 一个很好用的 js markdown 库

资源 | 一个很好用的 js markdown 库

作者: T_K_233 | 来源:发表于2018-09-17 07:48 被阅读0次

使用 CDN 加载 js 文件:

https://cdn.jsdelivr.net/npm/marked/marked.min.js

marked([markdown内容]) 可以将 Markdown 源码转换为 html

示例:

<!doctype html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>Marked in the browser</title>
  <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
  <style>
  .md_source{
    display: none
  }
  </style>
</head>
<body>
<pre class="md_source">
# Marked in the browser
Rendered by **marked**.
</pre>
<div class="md_render">
</div>
  <script>
    $('.md_render').html(marked($('.md_source').html()));
    //$('.markdown-container').html(marked('# Marked in the browser\n\nRendered by **marked**.'));
  </script>
</body>
</html>

相关文章

网友评论

    本文标题:资源 | 一个很好用的 js markdown 库

    本文链接:https://www.haomeiwen.com/subject/nzshnftx.html