将脚本标签添加到降价文件

Add script tag to markdown file

我正在使用 MKdocs 开发文档,需要将一些脚本文件加载到我的 markdown 文件中。如何在markdown中添加js函数和script标签?

您有两个选择:您可以在 Markdown 中包含原始 HTML <script> 标签,或者您可以使用 MkDocs 的 extra_javascript 设置指向您自己的 JavaScript 文件。

使用原始 HTML

作为 Markdown 文档 explains:

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags.

The only restrictions are that block-level HTML elements — e.g. <div>, <table>, <pre>, <p>, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.

当然,任何此类脚本对于包含它们的页面都是唯一的。

使用extra_javascript

如果您希望脚本在所有页面上都可用,MkDocs 提供了 extra_javascript 配置设置,这将导致指向指定文件的 script 被包含在每一页。只需确保该文件在您的 docs_dir.

中可用

例如,如果您创建一个文件 myscript.js,则将以下内容添加到您的 mkdocs.yml 配置文件中:

extra_javascript:
    myscript.js