Last active
March 5, 2018 22:38
-
-
Save bates64/b4e6c95205149909b16eb0d0ea401ce3 to your computer and use it in GitHub Desktop.
Image extension for mrk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const markImage = mrk({ | |
extendPatterns: { | |
image: ({ read, readUntil }, meta) => { | |
if (read(2) !== '![') return | |
// All characters up to `]` are the alt text | |
const alt = readUntil(']') | |
if (read(2) !== '](') return | |
// All characters up to `)` are the image src | |
const src = readUntil(')') | |
// Set metadata | |
meta({ alt, src }) | |
return read() === ')' | |
} | |
}, | |
extendHtmlify: {~) | |
image: ({ metadata: { alt, src } }) => `<img src='${mrk.sanitizeURL(mrk.escapeHTML(src))}' alt='${mrk.escapeHTML(alt)}'s/>` | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@heyitsmeuralex this code is still vulnerable to XSS. I suggest you update it to the one in Decent, i.e. placing the
src
attribute through amrk.sanitizeURL(mrk.escapeHTML(......))
. 🙂EDIT: resolved