如何在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
相关产品推荐
相关产品推荐

