diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cdde46..893f5b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [14.0.0] - WIP +### Fixed +- Html tokens inside img alt are now rendered as their original text, #896. +- Hardbreaks inside img alt are now rendered as newlines. + + ## [13.0.2] - 2023-09-26 ### Security - Fixed crash/infinite loop caused by linkify inline rule, #957. diff --git a/lib/renderer.mjs b/lib/renderer.mjs index da4bc87..3e0200f 100644 --- a/lib/renderer.mjs +++ b/lib/renderer.mjs @@ -268,12 +268,23 @@ Renderer.prototype.renderInlineAsText = function (tokens, options, env) { let result = '' for (let i = 0, len = tokens.length; i < len; i++) { - if (tokens[i].type === 'text') { - result += tokens[i].content - } else if (tokens[i].type === 'image') { - result += this.renderInlineAsText(tokens[i].children, options, env) - } else if (tokens[i].type === 'softbreak') { - result += '\n' + switch (tokens[i].type) { + case 'text': + result += tokens[i].content + break + case 'image': + result += this.renderInlineAsText(tokens[i].children, options, env) + break + case 'html_inline': + case 'html_block': + result += tokens[i].content + break + case 'softbreak': + case 'hardbreak': + result += '\n' + break + default: + // all other tokens are skipped } } diff --git a/test/fixtures/markdown-it/commonmark_extras.txt b/test/fixtures/markdown-it/commonmark_extras.txt index 37d3618..d504d1f 100644 --- a/test/fixtures/markdown-it/commonmark_extras.txt +++ b/test/fixtures/markdown-it/commonmark_extras.txt @@ -682,7 +682,7 @@ Issue #772. Header rule should not interfere with html tags. . -Newline in image description +Softbreak in image description . There is a newline in this image ![here it is](https://github.com/executablebooks/) @@ -690,3 +690,19 @@ it is](https://github.com/executablebooks/)

There is a newline in this image here
 it is

. + +Hardbreak in image description +. +There is a newline in this image ![here\ +it is](https://github.com/executablebooks/) +. +

There is a newline in this image here
+it is

+. + +Html in image description +. +![text