👌 IMPROVE: Explicitly parse block attributes#50
Open
brunobeltran wants to merge 1 commit intoexecutablebooks:masterfrom
Open
👌 IMPROVE: Explicitly parse block attributes#50brunobeltran wants to merge 1 commit intoexecutablebooks:masterfrom
brunobeltran wants to merge 1 commit intoexecutablebooks:masterfrom
Conversation
KyleKing
approved these changes
Jan 6, 2026
Collaborator
KyleKing
left a comment
There was a problem hiding this comment.
You'll need to apply the format change to fix pre-commit, but otherwise looks good to me!
|
|
||
| import re | ||
| import textwrap | ||
| from typing import Dict |
Collaborator
There was a problem hiding this comment.
Suggested change
| from typing import Dict |
| token.attrs = dict(sorted(token.attrs.items())) | ||
|
|
||
|
|
||
| def _reconstruct_attrs(attrs: Dict[str, str | int | float]) -> str: |
Collaborator
There was a problem hiding this comment.
__future__.annotations is used, so we don't need Dict
Suggested change
| def _reconstruct_attrs(attrs: Dict[str, str | int | float]) -> str: | |
| def _reconstruct_attrs(attrs: dict[str, str | int | float]) -> str: |
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.
The approach taken here is to use post-processing hooks to re-create block attrs. This is because (AFAICT) mdit_py_parsers.attrs machinery does not create nodes when parsing, but instead directly attaches the information to the
attrsof the associated node.Quite hacky workaround to ensure that our final result compares equal according to
mdformat'sis_md_equalfunction, but no more hacky than any of our other existing (e.g. fence-specific) code.Fixes: #25