fix(html): reduce inline images to alt text under markdownify 1.x (convert_as_inline → parent_tags)#2225
Open
lntutor wants to merge 1 commit into
Open
Conversation
markdownify >= 1.0 changed the convert_* calling convention: it passes parent_tags (containing the pseudo-tag '_inline' for headings/table cells) instead of the old positional convert_as_inline boolean. _CustomMarkdownify.convert_img still declared convert_as_inline and swallowed parent_tags into **kwargs, so convert_as_inline was always False and the alt-text reduction never fired. An image inside a heading or table cell therefore leaked full image markdown -- e.g. '<h1>Hello <img src=a.png alt=World></h1>' became '# Hello ' instead of '# Hello World', and a data: URI in a table cell could break the row. Switch the override to check '_inline' in parent_tags, matching base markdownify. Block (paragraph) images are unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N6RtoHuxrDqTUo9Mw9h4Cv
|
@lntutor please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
What's broken
markdownify ≥1.0 changed the
convert_*calling convention: it now invokes them asconvert_fn(node, text, parent_tags=<set>)(whereparent_tagscontains the pseudo-tag"_inline"for headings/table cells) instead of the old positionalconvert_as_inlineboolean._CustomMarkdownify.convert_imgstill declaresconvert_as_inlineand swallowsparent_tagsinto**kwargs, soconvert_as_inlineis alwaysFalseand the alt-text reduction never fires:An image in a table cell yields
|  | bob |, which with a long/data:URI can break the table row entirely. Basemarkdownify.convert_imghandles this correctly via"_inline" in parent_tags; the override defeated it.Fix
Switch the override to accept
parent_tagsand check"_inline" in parent_tags, matching base markdownify. Block (paragraph) images and thedata:URI truncation path are unaffected.Tests
Adds three cases to
test_module_misc.py: inline image in a heading and in a table cell reduce to alt text; a block image is still rendered. All pass. (convert_hn/convert_a/convert_inputcarry the same obsolete signature but produce no visible wrong result, so this stays a minimal single-bug fix.)