Marked.js 在HTML 中解析显示 Markdown

技术分享
1389 1

Marked.js 是一个 Markdown 解析和编译器,可以在 JavaScript 中将 Markdown 转为 HTML。
结合 HTML DOM,可以实现在 HTML 中直接解析显示 Markdown。

<textarea> 中编写 Markdown:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
 
  <title>Marked.js</title>
</head>
<body>
  <div id="$m" class="markdown-body"></div>
  <textarea id="$t" style="display:none">
*Write* your **Markdown** here.
  </textarea>
  <script>$m.innerHTML = marked.parse($t.value);</script>
</body>
</html>

github-markdown-css:仿 GitHub Markdown 样式:


<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width initial-scale=1">
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown-light.min.css">
  <style>
@media (max-width: 767px) { body { padding: 15px; } }
body { box-sizing: border-box;
       min-width: 200px;
       max-width: 980px;
       margin: 0 auto;
       padding: 45px; }
  </style>
  <title>Marked.js</title>
</head>
<body>
  <div id="$m" class="markdown-body"></div>
  <textarea id="$t" style="display:none">
# Hello World
*Write* `your` **Markdown** here.
  </textarea>
  <script>$m.innerHTML = marked.parse($t.value);</script>
</body>
</html>
https://www.76fx.com/169.html
最后更新 2023-02-22
评论 ( 1 )
问:肆 + 壹 = ?
OωO
隐私评论
  1. xfbfj

    小学初中
    K3034 绝版收藏:小学语文课本(8090后回忆杀)
    https://www.aliyundrive.com/s/t3PGWHmRW3X

    K3035 超级速读记忆训练软件电脑版手机版
    https://www.aliyundrive.com/s/jiFXxVN6nFG

    1思维导图(小初高全科)
    https://www.aliyundrive.com/s/sCw1ChLJEmy

    K3033 小学语文写作技巧宝典班
    https://www.aliyundrive.com/s/Vn7MxVNtjBf

    K3032 洋葱语文初中
    https://www.aliyundrive.com/s/tQCFfjWDbMr

    K3031 乐乐课堂:初中英语语法
    https://www.aliyundrive.com/s/1WfdcTbCL9T

    K3030 洋葱英语初中
    https://www.aliyundrive.com/s/Mu8BTMgCfDH

    K3029 洋葱化学初中全套
    https://www.aliyundrive.com/s/KFPJbV5qMKJ

    K3028 洋葱物理初中全套
    https://www.aliyundrive.com/s/KbiSAtnxDXU

    K3027 秒懂百科:初中数学全套227节
    https://www.aliyundrive.com/s/9y8EkWMqJCD

    网校名师课堂:语数英全科1年级
    https://www.aliyundrive.com/s/WCiqp9FdDxP

    网校名师课堂:语数英全科2年级
    https://www.aliyundrive.com/s/WYZTCvb9RqT

    网校名师课堂:语数英全科3年级
    https://www.aliyundrive.com/s/CqfV9FYDXXk

    网校名师课堂:语数英全科4年级
    https://www.aliyundrive.com/s/97FYjpsGSDh

    网校名师课堂:语数英全科5年级
    https://www.aliyundrive.com/s/zS2DRYgBaH5

    网校名师课堂:语数英全科6年级
    https://www.aliyundrive.com/s/8d43SuHXvbr

    K3025 小学初中作文辅导课
    https://www.aliyundrive.com/s/JvWo4CDfv2P

    特级教师视频课:人教版初中化学
    https://www.aliyundrive.com/s/Rvfaoxne492

    特级教师视频课:初中数学7-9年级
    https://www.aliyundrive.com/s/sf42G35sJM9

    特级教师视频课:初中物理
    https://www.aliyundrive.com/s/G3H77Lc9gmr

    特级教师视频课:初中语文人教版
    https://www.aliyundrive.com/s/5Aa38GmYmUt

    特级教师视频课:新目标初中英语
    https://www.aliyundrive.com/s/fcUCJUoKA8u

    特级教师视频课:小学英语3至6年级新人教版
    https://www.aliyundrive.com/s/fSbpWGZwrbk

    特级教师视频课:PEP小学英语全套
    https://www.aliyundrive.com/s/TyouGs3h32B

    特级教师视频课:小学语文4至6年级
    https://www.aliyundrive.com/s/kyWqguRyBBu

    特级教师视频课:小学语文1至3年级
    https://www.aliyundrive.com/s/dcUspUqVHja

    特级教师视频课:小学数学1-6年级
    https://www.aliyundrive.com/s/3G7mkPff4Uo

    特级教师视频课:小学数学北师大版
    https://www.aliyundrive.com/s/xBD7SXHmFKK

    K3021 初中英语语法
    https://www.aliyundrive.com/s/sNkcEyeJKVp

    巨人数学5年级数学(76)
    https://www.aliyundrive.com/s/6dhttqD9rfM

    巨人数学3年级数学(72)
    https://www.aliyundrive.com/s/xNWs64weqHV

    巨人数学1年级数学
    https://www.aliyundrive.com/s/1LCQX7b65Bn

    K3019 100节动画课带孩子穿越唐诗大世界
    https://www.aliyundrive.com/s/9KNyDzAWus6

    K3018 小灯塔学习系列
    https://www.aliyundrive.com/s/MhKp3Gpbt4Q

    K3016 学而思1-9年级最全英语语法教学视频
    https://www.aliyundrive.com/s/7WSk8ywNdoa

    K3015 初中语文课辅导
    https://www.aliyundrive.com/s/kRe4ZC5Ysrp

    K3014 初中人教版电子课本
    https://www.aliyundrive.com/s/BeDpzNYw4gX

    K3013 中考状元笔记全科
    https://www.aliyundrive.com/s/8p8mPkDMMph

    K3012 乐学英语:四年级年卡50讲
    https://www.aliyundrive.com/s/E43za4DTP4n

    K3011 中考满分笔记
    https://www.aliyundrive.com/s/1L3ojgsuv4z

    K3010 黄冈360小升初超级卷语数英
    https://www.aliyundrive.com/s/3G9cUSsnMr8

    K3009 赢在小考小升初 语数英套装6本
    https://www.aliyundrive.com/s/k1HGPyQqS5u

    K3008 《乐乐课堂》小升初锦囊语文动画视频(27章全)
    https://www.aliyundrive.com/s/GHcJCJ9Rz3J

    K3007 唐诗三百首微电影314集全
    https://www.aliyundrive.com/s/7SqknDbs9VR

    K3006 1~12年级奥数教程
    https://www.aliyundrive.com/s/Us7ipJTuZhR

    K3005 初中英语单词速记
    https://www.aliyundrive.com/s/APuTFjjXuxE

    K3005 小学英语单词速记
    https://www.aliyundrive.com/s/8o9ANsCXpbJ

    K3004 小学阅读
    https://www.aliyundrive.com/s/CYBQFS8X63s

    小学作文训练合集
    10.400节小学语文特级教师优质课公开课视频
    https://www.aliyundrive.com/s/CzdNzcdG66Q

    09.小学语文知识大全——小学写作技巧宝典班
    https://www.aliyundrive.com/s/nkdjEmHVApU

    08.非常作文训练营
    https://www.aliyundrive.com/s/8BiNwLkUDNx

    07.探秘图画王国—看图作文全攻略
    https://www.aliyundrive.com/s/PYUybsfh369

    06.黄保余小学作文训练营和阅读训练营【视频课】
    https://www.aliyundrive.com/s/YH7U9feTvDG

    05.超懂学生的作文提分课,告别死记硬背
    https://www.aliyundrive.com/s/YBwPoS46pRT

    04.黄金格作文《词句导引作文训练法》小学版
    https://www.aliyundrive.com/s/YH1iCgQVari

    03.曾曦.小学语文作文独创方法
    https://www.aliyundrive.com/s/391jcBVwCFS

    01.袁氏作文小学版
    https://www.aliyundrive.com/s/TnRe2NAAJsW

    小学生作文
    https://www.aliyundrive.com/s/uK6yGNhV52i

    小学作文语文素材库
    https://www.aliyundrive.com/s/1NvNEdXKsWD

    K2024 专为5-12岁小朋友打造美术综合课
    https://www.aliyundrive.com/s/v3G15kJ34Ld

    K3002 初中学霸笔记
    https://www.aliyundrive.com/s/kdHCHoQmELL

    K3001 小学学霸笔记
    https://www.aliyundrive.com/s/nBKMYxrSUGR

    2023-08-15 16:03:02安徽省合肥市 电信回复