跳转至

Abbreviations

Technical documentation often incurs the usage of many acronyms, which may need additional explanation, especially for new user of your project. For these matters, Material for MkDocs uses a combination of Markdown extensions to enable site-wide glossaries.

Configuration

This configuration enables abbreviations and allows to build a simple project-wide glossary, sourcing definitions from a central location. Add the following line to mkdocs.yml:

markdown_extensions:
  - abbr
  - attr_list
  - pymdownx.snippets

See additional configuration options:

Improved tooltips

Sponsors only · insiders-4.15.0 · Experimental

When improved tooltips are enabled, Material for MkDocs replaces the browser's rendering logic for title attribute with beautiful little tooltips. Add the following lines to mkdocs.yml:

theme:
  features:
    - content.tooltips

Now, tooltips will be rendered for the following elements:

  • Content – elements with a title, permalinks and copy-to-clipboard button
  • Header – home button, header title, color palette switch and repository link
  • Navigation – links that are shortened with ellipsis, i.e. ...

Usage

Adding tooltips

The Markdown syntax allows to specify a title for each link, which will render as a beautiful tooltip when improved tooltips are enabled. Add a tooltip to a link with the following lines:

Link with tooltip, inline syntax
[Hover me](https://example.com "I'm a tooltip!")

Tooltips can also be added to link references:

Link with tooltip, reference syntax
[Hover me][example]

[example]: https://example.com "I'm a tooltip!"

For all other elements, a title can be added by using the Attribute Lists extension:

Icon with tooltip
:material-information-outline:{ title="Important information" }

Adding abbreviations

Abbreviations can be defined by using a special syntax similar to URLs and footnotes, starting with a * and immediately followed by the term or acronym to be associated in square brackets:

Text with abbreviations
The HTML specification is maintained by the W3C.

_[HTML]: Hyper Text Markup Language
_[W3C]: World Wide Web Consortium

The HTML specification is maintained by the W3C.

_[HTML]: Hyper Text Markup Language _[W3C]: World Wide Web Consortium

Adding a glossary

Snippets扩展可以通过移动专用文件1中的所有缩略语来实现一个简单的术语表,并auto-append该文件到具有以下配置的所有页面:

*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
markdown_extensions:
  - pymdownx.snippets:
      auto_append:
        - includes/abbreviations.md

  1. 强烈建议将包含缩写的 Markdown 文件放在docs 文件夹之外(这里使用了一个名为includes的文件夹),否则 MkDocs 可能会抱怨未引用的文件。