« Back to Search  |  Reader Mode  |  Switch to Full Retro Site View Links: Stay in Reader  |  Retro Mode: ON  |  Original »
GitHub · Extracted in 1262 ms

🐛 Keep code span text in image alt text (#460) · executablebooks/markdown-it-py@2787da1

Source: https://github.com/executablebooks/markdown-it-py/commit/2787da18ed25292da1b44f03385c4fbba159c35a

Repository navigation

Commit 2787da1


Browse files
jayhemnani9910 authored 🐛 Keep code span text in image alt text (#460 ) `renderInlineAsText` now keeps `code_inline` content, so `` ![a `code` b](x.png) `` gives `alt="a code b"`, not `alt="a b"`. The text is escaped in the attribute as usual. Ported from markdown-it 15.0.0 (54289c4 / markdown-it#1142), with its fixture.
1 parent 01d077a commit 2787da1

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎markdown_it/renderer.py‎

Lines changed: 1 addition & 1 deletion
Original file line number Diff line number Diff line change
@@ -208,7 +208,7 @@ def renderInlineAsText(
208 208 result = ""
209 209
210 210 for token in tokens or []:
211 - if token.type == "text":
211 + if token.type in ("text", "code_inline"):
212 212 result += token.content
213 213 elif token.type == "image":
214 214 if token.children:

‎tests/test_port/fixtures/commonmark_extras.md‎

Lines changed: 7 additions & 0 deletions
Original file line number Diff line number Diff line change
@@ -765,3 +765,10 @@ Inline HTML in image description
765 765 .
766 766 <p><img src="/url" alt="a&lt;b&gt;c" /></p>
767 767 .
768 +
769 +Code in image description (markdown-it#1142)
770 +.
771 +![foo *bar* `baz` bla](image.png)
772 +.
773 +<p><img src="image.png" alt="foo bar baz bla" /></p>
774 +.

‎tests/test_port/fixtures/issue-fixes.md‎

Lines changed: 21 additions & 0 deletions
Original file line number Diff line number Diff line change
@@ -87,3 +87,24 @@ Fix parsing of incorrect numeric character references
87 87 .
88 88 <p><img src="y" alt="a b c d" /></p>
89 89 .
90 +
91 +Keep the text of a code span in image alt text
92 +.
93 +![a `code` b](x.png)
94 +.
95 +<p><img src="x.png" alt="a code b" /></p>
96 +.
97 +
98 +Code span text in image alt is HTML-escaped, as in markdown-it 15.0.3
99 +.
100 +![a `c<d` e](/u)
101 +.
102 +<p><img src="/u" alt="a c&lt;d e" /></p>
103 +.
104 +
105 +Image alt keeps escapes, entities and code span text together
106 +.
107 +![a \* `c<d` &amp; e](/u)
108 +.
109 +<p><img src="/u" alt="a * c&lt;d &amp; e" /></p>
110 +.