You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在MkDocs中借助mkdocstrings仅展示类摘要(属性表)并隐藏后续属性章节?

如何在MkDocs中借助mkdocstrings仅展示类摘要(属性表)并隐藏后续属性章节?

我太懂你这种折腾好几天找不到关键配置的郁闷了——你想用Zensical/Material for MkDocs搭配mkdocstrings,只展示类的属性摘要表,却不想让后面单独的属性章节显示出来,试了各种配置组合都没搞定对吧?

其实问题的关键就在一个你没注意到的参数上:你的配置里已经开启了summary: true来生成顶部的属性摘要表,但mkdocstrings默认会同时把属性单独拆分成一个章节展示。要实现你的需求,只需要在Python handler的配置选项里添加一行show_attributes: false即可。

修改后的完整配置如下:

plugins:
- mkdocstrings:
    handlers:
      python:
        inventories:
        - https://docs.python.org/3/objects.inv
        options:
          show_if_no_docstring: true
          docstring_section_style: list
          filters: ["!^_"]
          inherited_members: true
          root_members: false
          merge_init_into_class: true
          show_docstring_returns: false
          parameter_headings: true
          separate_signature: false
          show_root_full_path: false
          show_signature_annotations: true
          show_symbol_type_heading: true
          show_symbol_type_toc: true
          signature_crossrefs: true
          summary: true
          show_attributes: false  # 新增此参数,隐藏单独的属性章节

简单解释下:show_attributes参数专门控制是否在类文档中展示单独的属性章节,将其设为false后,就只会保留由summary: true生成的顶部属性摘要表,不会再显示后续的详细属性章节了,完美匹配你的需求。

备注:内容来源于stack exchange,提问作者Oleg Somov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 18:22:57