Repository navigation
Commit 2787da1
Browse files
jayhemnani9910
authored
🐛 Keep code span text in image alt text (
#460 )
`renderInlineAsText` now keeps `code_inline` content, so
``  `` 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
-
tests/test_port/fixtures
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:
|
|
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<b>c" /></p>
|
767 | 767 | .
|
| 768 | +
|
| 769 | +Code in image description (markdown-it#1142)
|
| 770 | +.
|
| 771 | +
|
| 772 | +.
|
| 773 | +<p><img src="image.png" alt="foo bar baz bla" /></p>
|
| 774 | +.
|
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 | +
|
| 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 | +
|
| 101 | +.
|
| 102 | +<p><img src="/u" alt="a c<d e" /></p>
|
| 103 | +.
|
| 104 | +
|
| 105 | +Image alt keeps escapes, entities and code span text together
|
| 106 | +.
|
| 107 | +
|
| 108 | +.
|
| 109 | +<p><img src="/u" alt="a * c<d & e" /></p>
|
| 110 | +.
|