Skip to content

Commit 4ad81e4

Browse files
authored
Merge pull request #401 from rdestefa/issue-398-alt-text-code
Fix Code Spans Being Dropped from Image Alt Text
2 parents 9926b76 + 77cadac commit 4ad81e4

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html),
77
with the exception that 0.x versions can break between minor versions.
88

9+
## Unreleased
10+
### Fixed
11+
12+
- Fix rendering of image alt text to include contents of code spans (`` `code` ``). (#398)
13+
914
## [0.25.1] - 2025-08-01
1015
### Fixed
1116
- footnotes: Fix parsing of footnote definitions containing multiple paragraphs

commonmark/src/main/java/org/commonmark/renderer/html/CoreHtmlNodeRenderer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ public void visit(Text text) {
311311
sb.append(text.getLiteral());
312312
}
313313

314+
@Override
315+
public void visit(Code code) {
316+
sb.append(code.getLiteral());
317+
}
318+
314319
@Override
315320
public void visit(SoftLineBreak softLineBreak) {
316321
sb.append('\n');

commonmark/src/test/java/org/commonmark/test/HtmlRendererTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ public void imageAltTextWithEntities() {
279279
assertThat(defaultRenderer().render(parse("![foo &auml;](/url)\n"))).isEqualTo("<p><img src=\"/url\" alt=\"foo \u00E4\" /></p>\n");
280280
}
281281

282+
@Test
283+
public void imageAltTextWithInlines() {
284+
assertThat(defaultRenderer().render(parse("![_foo_ **bar** [link](/url)](/url)\n"))).isEqualTo("<p><img src=\"/url\" alt=\"foo bar link\" /></p>\n");
285+
}
286+
287+
@Test
288+
public void imageAltTextWithCode() {
289+
assertThat(defaultRenderer().render(parse("![`foo` bar](/url)\n"))).isEqualTo("<p><img src=\"/url\" alt=\"foo bar\" /></p>\n");
290+
}
291+
282292
@Test
283293
public void canRenderContentsOfSingleParagraph() {
284294
Node paragraphs = parse("Here I have a test [link](http://www.google.com)");

0 commit comments

Comments
 (0)