Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with multiline alt in image #306

Closed
mikbur opened this issue Mar 4, 2020 · 1 comment · Fixed by #325
Closed

Problem with multiline alt in image #306

mikbur opened this issue Mar 4, 2020 · 1 comment · Fixed by #325

Comments

@mikbur
Copy link

mikbur commented Mar 4, 2020

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAABdCAYAAACBx8lpAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOx" alt="A close up of a sign

Description automatically generated"> 

generates

![A close up of a sign

Description automatically generated](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAABdCAYAAACBx8lpAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOx)

My solution is unable to parse this to an image so I modified the rule to this

turndownService.addRule('image', {
    filter: 'img',

    replacement: function (content, node) {
      var alt = node.alt || ''
      // Added row to remove linebreaks in alt
      alt = alt.substring(0, alt.indexOf('\n'))
      var src = node.getAttribute('src') || ''
      var title = node.title || ''
      var titlePart = title ? ' "' + title + '"' : ''
      return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : ''
    }
  })
@domchristie
Copy link
Collaborator

domchristie commented May 11, 2020

Thanks! Single line-breaks seems to be valid in CommonMark, so #325 strips multiple newlines and whitespace. It will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants