Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by winshyon · project thread
Description
With
--docformat google, the section regex indocstrings.google()also ran over fenced code blocks, so a line likeABC:followed by indented lines inside a```block was turned into a###### ABC:heading plus a block quote.google()now applies the section conversion only to the text outside fenced code blocks. The fences are found with a simple line-by-line scan (no backtracking regex, so it stays linear on large docstrings). Only fences that start at the beginning of a line (```or~~~) are skipped, and, as in CommonMark, a block is closed by a fence of the same character that is at least as long as the opening one (so amdblock may contain``` ````). A fenced block that is indented as part of a section's contents (e.g. a code example underExamples:) stays part of that section, as before. An unterminated fence is treated as regular text, i.e. behaves as before.I kept this to the Google flavour reported in the issue; the NumPy flavour splits on
Heading\n----and could in principle be affected in a similar way, but I didn't want to widen the change without a report.Tests:
test_google_fenced_code_blockintest/test_docstrings.pywith the example from the issue (fails onmain), a fence between two regular sections, a longer outer fence, and an unterminated fence. All snapshot tests are unchanged.Motivation / disclosure: I had some spare AI-assistant quota (Claude Code) and am using it to try to help projects with open issues. The change was prepared with Claude Code and verified as listed below. If it doesn't fit, isn't up to your bar, or you'd simply rather not take it — please feel free to close it, no hard feelings at all 🙂
Related issue
Fixes #775
Checklist
uv run pytest --cov=pdoc -m "not slow": 155 passed,pdoc/docstrings.py100% covered; fulluv run pytest test/: 360 passed;ruff check .,ruff format --check .,mypy pdoc testcleanCHANGELOG.mdis updated🤖 Generated with Claude Code