You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a docstring's first line uses a reference, and that reference is declared in the body, then current summary features will not be able to render the reference.
Describe the solution you'd like
The only way to be more robust is to actually render a concatenation of all text sections found in the docstring, to then retrieve the first HTML paragraph.
Concatenation: "\n\n".join(section.value for section in sections if section.kind is DocstringSectionKind.text)
Retrieval of first paragraph: use standard lib's HTML parser, feed the result to it, record only first p element and break
Describe alternatives you've considered
Documenting this as a limitation. Afterall, there are clear semantics for Python docstrings, where the summary is the first line only, separated from the body by a blank line. If the first line depends on the body to be rendered correctly, we could consider it a user error.
Another alternative would be to parse the docstring as Markdown (just parse, not convert) to collect references and footnotes (any other similar item?), to append them back to any summary or text section when rendering.
Additional context
I thought about doing this (first suggestion) for text sections too, when rendering them. However, if we concatenate from the current section down to the last, I don't think it's possible to robustly retrieve just the content of the current section from the resulting HTML. The "collect refs to append back" suggestion would work, though.
The text was updated successfully, but these errors were encountered:
frommistletoeimportDocumentfrommistletoe.ast_rendererimportASTRenderermarkdown="""This line uses a [link][].[link]: https://example.com"""withASTRenderer() asrenderer:
print(renderer.render(Document(markdown)))
Is your change request related to a problem? Please describe.
Context: Python-Markdown/markdown#1495.
If a docstring's first line uses a reference, and that reference is declared in the body, then current summary features will not be able to render the reference.
Describe the solution you'd like
The only way to be more robust is to actually render a concatenation of all text sections found in the docstring, to then retrieve the first HTML paragraph.
"\n\n".join(section.value for section in sections if section.kind is DocstringSectionKind.text)
p
element and breakDescribe alternatives you've considered
Documenting this as a limitation. Afterall, there are clear semantics for Python docstrings, where the summary is the first line only, separated from the body by a blank line. If the first line depends on the body to be rendered correctly, we could consider it a user error.
Another alternative would be to parse the docstring as Markdown (just parse, not convert) to collect references and footnotes (any other similar item?), to append them back to any summary or text section when rendering.
Additional context
I thought about doing this (first suggestion) for text sections too, when rendering them. However, if we concatenate from the current section down to the last, I don't think it's possible to robustly retrieve just the content of the current section from the resulting HTML. The "collect refs to append back" suggestion would work, though.
The text was updated successfully, but these errors were encountered: