Markdocs - 使用Markdown的Python文档
项目描述
从Python源文件注释中提取Markdown,并生成结构化文档和README文件。
Python文档
我喜欢使用Markdown在Rustlang中编写功能文档,所以我将进行实验以在Python中实现相同的功能。看看rustdoc和这里一个示例,这是一个使用Markdown注释生成的Rust crate的文档网站。
信息是通过使用python -m tokenize file.py https://docs.pythonlang.cn/3.5/library/tokenize.html#examples
如何工作
注意:这只是一个初步的想法,尚未实现!如果喜欢,请评论。
Markdocs从所有.py文件中提取文档,并输出到一个有组织的文档html网站,可以使用mkdocs.org来暴露和部署。
markdocs /path/to/project
如果您不想生成完整的文档,您可以轻松地为您的仓库生成一个README文件。
markdocs /path/project --readme README.md -k 'filter-oly-some-files-and-objects'
使用上述方法,将生成一个包含仅过滤文件和对象文档的README.md,但您也可以为整个项目生成单个README。
该文件夹中的所有.py文件都将被解析以查找文档块,这些块是以!开始的Python多行注释。
注意:如果您不喜欢将代码和文档混合,可以使用 mymodule.md 来记录 mymodule.py,且.md 文件应位于同一文件夹或项目的 mdocs 文件夹中。您也可以像 mymodule.myclass.mymethod.md 这样编写单独的对象文件,它只会链接到 MyClass 的 mymethod。
"""!
# this is a documentation written in markdown
As it has only one `!` at the top, it is considered the module documentation
I can include module documentation along the file and will be merged in to the top level documentation
"""
from foo import bar
"""!!
# This is an object documentation, can be used for any object but most for functions and classes
It is defined before the object and not on the `__doc__` docstring, as markdocs does not conflicts with it.
## What are the advantages
- Markdown is easy to learn
- More people will contribute to documentation because they already know the format
- With simple commands like `markdocs /path --readme README.md` the readme for your repo is generated from markdocs
- Markdocs will generate the output for https://mkdocs.pythonlang.cn/
- You can write bare `.md` files in a `mdocs` folder and they will be added to you documentation as well
[[params
# X is the single param of this function
x: int | default 0
# The return is a string with the x interpolated.
]] result: str
"""
def a_function(x=0):
"""This regular docstring does not conflicts with the above markdoc"""
return f'Hello {x}'
"""!!
# This is a class documentation
We can also define runnable and highlighted blocks of code.
```run
obj = MyClass()
```
"""
class MyClass:
"""the class docstring is not affected"""
attr = 'foo'
"""!!!
# this is a method documentation
[[params
x: str
]]
"""
def method(self, x):
"""This is the regular docstring for method"""
a = x
"""!!!!
## Here we increase the nesting level
Markdown is amazing!
"""
def inner_function(..):
pass
如您所见,!! 也可以使用,实际上您可以使用尽可能多的 !!!!! 来定义嵌套。
解析选项有
网站输出格式
mkdocs.org
更多内容请参阅 https://gist.github.com/rochacbruno/1689c849f3ef54086772c410d77a82de
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码分布
构建分布
markdocs-0.0.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 8c23f6f77a33d34ad24fe7ed3964cb0701cfbc6185961f680ce55b837de4fbe8 |
|
MD5 | 1119bdc6fc7809ef9826f9adc1ec0b44 |
|
BLAKE2b-256 | 4b9b9246911cf2d1c06718e3c56149cea8cdad7f42f05d314bc90190d7dfbc59 |
markdocs-0.0.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 64fda59814e39cb096cfbb3572694dd17445a0039d0fcce3e486e2190d72e68a |
|
MD5 | 063972f6e1c17cc8c7beb2b20302478c |
|
BLAKE2b-256 | 359e8f70a52c4516b7e20f5ef14d61e2440d8cb248bf748ec08cb5c200839c4a |