From 360032f8407b6fa186a82705044326c0a3867ed3 Mon Sep 17 00:00:00 2001 From: chuenchen309 <48723787+chuenchen309@users.noreply.github.com> Date: Sun, 19 Jul 2026 18:36:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20render=20hardbreak=20and?= =?UTF-8?q?=20inline=20HTML=20in=20image=20alt=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `RendererHTML.renderInlineAsText`, used to build image `alt` attributes, only handled `text`, `image` and `softbreak` tokens and silently dropped `hardbreak`, `html_inline` and `html_block`. The upstream markdown-it JS reference this port targets (v14.1.0) handles all of these, and `softbreak`/`hardbreak` are treated as a pair everywhere else in the codebase, so a hard line break or inline HTML in an image description was lost from the alt text (e.g. `![foo\bar](/url)` produced `alt="foobar"` instead of `alt="foo\nbar"`). Co-Authored-By: Claude Opus 4.8 Signed-off-by: chuenchen309 <48723787+chuenchen309@users.noreply.github.com> --- markdown_it/renderer.py | 4 +++- tests/test_port/fixtures/commonmark_extras.md | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/markdown_it/renderer.py b/markdown_it/renderer.py index f690b091..73dbde15 100644 --- a/markdown_it/renderer.py +++ b/markdown_it/renderer.py @@ -202,7 +202,9 @@ def renderInlineAsText( elif token.type == "image": if token.children: result += self.renderInlineAsText(token.children, options, env) - elif token.type == "softbreak": + elif token.type in ("html_inline", "html_block"): + result += token.content + elif token.type in ("softbreak", "hardbreak"): result += "\n" return result diff --git a/tests/test_port/fixtures/commonmark_extras.md b/tests/test_port/fixtures/commonmark_extras.md index f0b31dbd..2de75e5d 100644 --- a/tests/test_port/fixtures/commonmark_extras.md +++ b/tests/test_port/fixtures/commonmark_extras.md @@ -749,3 +749,19 @@ Issue #204. Combination of blockquotes, list and newlines causes an IndexError . + +Hardbreak in image description +. +![foo\ +bar](/url) +. +

foo
+bar

+. + +Inline HTML in image description +. +![ac](/url) +. +

a<b>c

+.