Skip to content

Commit

Permalink
Merge 955bba2 into 9f5e9c6
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Dec 3, 2023
2 parents 9f5e9c6 + 955bba2 commit 4e610c9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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.
Expand Down
23 changes: 17 additions & 6 deletions lib/renderer.mjs
Expand Up @@ -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
}
}

Expand Down
18 changes: 17 additions & 1 deletion test/fixtures/markdown-it/commonmark_extras.txt
Expand Up @@ -682,11 +682,27 @@ Issue #772. Header rule should not interfere with html tags.
</pre>
.

Newline in image description
Softbreak in image description
.
There is a newline in this image ![here
it is](https://github.com/executablebooks/)
.
<p>There is a newline in this image <img src="https://github.com/executablebooks/" alt="here
it is"></p>
.

Hardbreak in image description
.
There is a newline in this image ![here\
it is](https://github.com/executablebooks/)
.
<p>There is a newline in this image <img src="https://github.com/executablebooks/" alt="here
it is"></p>
.

Html in image description
.
![text <textarea> text](image.png)
.
<p><img src="image.png" alt="text &lt;textarea&gt; text"></p>
.

0 comments on commit 4e610c9

Please sign in to comment.