假设我在 github 存储库中有一个 README.md
文件。然后,我将制作一个关于我将使用 gh-pages
托管的存储库的网站。
我想要的是让我的 index.html
文件的一部分从我的 README.md
文件中获取其内容。这样,只需要更新一个文件。
我想markdown文件首先需要转换为html,然后可以将html放入另一个html文件中。
我调查了HTML5 Imports , 但它们目前仅在 Chrome 中受支持。将单独的 .js
文件与 document.write()
一起使用可能会有用,但有没有一种简单、干净的方法?
最佳答案
我正在使用 < zero-md > 网络组件。
<!-- Lightweight client-side loader that feature-detects and load polyfills only when necessary -->
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script>
<!-- Load the element definition -->
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script>
<!-- Simply set the `src` attribute to your MD file and win -->
<zero-md src="README.md"></zero-md>
关于javascript - 如何在 html 文件中包含 markdown (.md) 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37770620/