在 Blogger 的内容中使用 markdown
群里有人讨论如何在 blogger 中使用 markdown
思路
在 blogger 新建博文时, 切换到 HTML 视图.
把 markdown 文本粘进去. 举例如下,
- 演示视频https://www.youtube.com/watch?v=DZcXqyIm_R0- 演示站https://journal.crazypeace.workers.dev/journaljournal- Githubhttps://github.com/crazypeace/url-Shorten-Worker/- 搭建过程https://www.nodeseek.com/post-58723-1最后把这几行改一下就行. 第3 行定义了操作页面. 第 7 行定义了保存 key-value 时, 是否检验已经存在 key. 第 11 行定义了一些系统的行为. 对了, Markdown 要用到图床, 可以用这个 https://www.nodeseek.com/post-60815-1
发布为正式博文.
然后查看此页面的源码, 发现正文的 html 部分有 class 为 post-body entry-content
class='post-body entry-content'
在 blogger 的 主题背景 - 修改 HTML
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script><script>document.addEventListener('DOMContentLoaded', function() {// 获取所有具有 "post-body" 类的元素的第1 个, 也就是博文的正文 const blogContent = document.getElementsByClassName("post-body")[0];// 获得markdown 文本 const markdownContent = blogContent.textContent;// 转换为html 再放到博文正文内容 blogContent.innerHTML = marked.parse(markdownContent);});</script>
========
完
放到了 Github
你可以这样使用
<script src='https://cdn.jsdelivr.net/npm/marked/marked.min.js'/><script src='https://crazypeace.github.io/blogger-replace-markdown-text-html/blogger-replace-markdown-text-html.js'/>
========
后记
我的博客并不是纯
所以我建了一个演示站
评论
发表评论