remarkable
remarkable copied to clipboard
Support data URIs in links?
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;
}
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;