remarkable icon indicating copy to clipboard operation
remarkable copied to clipboard

Support data URIs in links?

Open jwerre opened this issue 5 years ago • 1 comments

Should be able to securely add base64 encoded images to links. Something like this:

replace: https://github.com/jonschlinkert/remarkable/blob/master/lib/helpers/parse_link_destination.js#L78

with:

let re = /^\s*data:([a-z]+\/[a-z]+(;[a-z-]+=[a-z-]+)?)?(;base64)?,[a-z0-9!$&',()*+,;=\-._~:@/?%\s]*\s*$/i;
if (!state.parser.validateLink(link) && !link.match(re) ) {
	return false;
}

jwerre avatar Feb 27 '19 01:02 jwerre

As a workaround, you can monkey-patch in a custom link validator:

const remarkable = new Remarkable();

const originalLinkValidator = remarkable.inline.validateLink;
const dataLinkRegex = /^\s*data:([a-z]+\/[a-z]+(;[a-z-]+=[a-z-]+)?)?(;base64)?,[a-z0-9!$&',()*+,;=\-._~:@/?%\s]*\s*$/i;

remarkable.inline.validateLink = (url: string) => originalLinkValidator(url) || url.match(dataLinkRegex);

This seems to be at least somewhat supported, as noted by the comment above the validateLink property:

  // Can be overridden with a custom validator
  this.validateLink = validateLink;

AlbinoDrought avatar Oct 29 '19 21:10 AlbinoDrought