Skip to content

Conversation

@brunobeltran
Copy link

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 attrs of the associated node.

Quite hacky workaround to ensure that our final result compares equal according to mdformat's is_md_equal function, but no more hacky than any of our other existing (e.g. fence-specific) code.

Fixes: #25

Copy link
Collaborator

@KyleKing KyleKing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from typing import Dict

token.attrs = dict(sorted(token.attrs.items()))


def _reconstruct_attrs(attrs: Dict[str, str | int | float]) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block attributes formatting introduce extra empty line

2 participants