如何在 使用 Marked.js 或 任何其他客户端 Markdown 库 解析降价文件客户端时显示 GitHub Gist 的内容?下面的代码呈现 Markdown 文件除了 Gist.
fetch("https://raw.githubusercontent.com/Ayanmullick/test/master/ScriptTagTest.md")
.then(response => response.blob()) // Unwrap to a blob...
.then(blob => blob.text()) // ...then to raw text...
.then(markdown => { // .pass raw text into marked.parse
document.getElementById("content").innerHTML=marked.parse(markdown)
})
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<div id="content"></div>
但是,Gist 在禁用
Markdown content preview settings
后在 Visual Studio Code 中呈现 OK:Disable preview security warning in this workspace
.
这可能是因为 Marked.js 没有执行解析的 markdown 文件中的脚本。我不确定哪些库允许您执行此操作,但根据此您可以在 Docsify-JS 中执行此操作 https://gist.github.com/MichaelCurrin/c2bece08f27c4277001f123898d16a7c
您需要启用此 executescript:true 才能运行内联脚本 https://docsify.js.org/#/configuration?id=executescript