miyuchina / mistletoe

A fast, extensible and spec-compliant Markdown parser in pure Python.
MIT License
811 stars 113 forks source link

Modified the HTMLBlock token as described in #163, Inconsistencies in the block tokens #169

Closed anderskaplan closed 1 year ago

anderskaplan commented 1 year ago

Modified the HTMLBlock to store its content in a RawText child node, like all the other block tokens, instead of a content attribute. This makes it easier to iterate over the token tree, because all block tokens can be handled the same way.

Added a convenience wrapper to preserve backward compatibility.

pbodnar commented 1 year ago

Also fixed a bug in Token.repr which caused class attributes on the tokens to be included and not only instance attributes.

Good catch, although I can imagine having a separate PR for that. But I know it's tempting to avoid some bureaucracy around creating new branch and PR - I have done that recently myself on another project... ;)

anderskaplan commented 1 year ago

Yeah the main thing I wanted to address with this PR was the HTMLBlock content move. And that cannot be done cleanly, i.e. without failing unit tests, before the Token.repr bug is fixed. So that's why they got to go together. I did put the Token.repr bug fix in a separate commit though.

anderskaplan commented 1 year ago

Now this PR is really going out on a limb :)

Adding another small change related to the Token.repr issue, which is to unify how Token.repr and the AST renderer select the attributes to be included in their output. I think it makes sense that only "officially declared" attributes should appear in both of those cases, and I see no reason why they should differ in their selection of attributes.

anderskaplan commented 1 year ago

Btw, I've looked into the other part of issue/question #163 about inconsistent line endings and come to the conclusion that it's best to leave them as they are. So I consider this PR finished here.

anderskaplan commented 1 year ago

The changes not related to the HTMLBlock are now split out into a separate PR. I'll update this PR once those changes are in, because of dependencies.

coveralls commented 1 year ago

Coverage Status

Coverage: 89.174% (+0.04%) from 89.129% when pulling 2a68daa6bc47a8024324f64f226eb4ce5b7756d0 on anderskaplan:html-block-content into 0af667f17da028a497a0b22c575a1d1e56383097 on miyuchina:master.

pbodnar commented 1 year ago

Just some final tuning, I would squash-merge afterwards.

pbodnar commented 1 year ago

Squashed and merged. Thank you! :)