diff options
| author | rr- | 2016-12-22 23:12:58 +0100 |
|---|---|---|
| committer | rr- | 2016-12-22 23:41:43 +0100 |
| commit | 32d498c74b5fcd24af6c5f1752f786d4d670b801 (patch) | |
| tree | ced1b8c6e5b928e7c65c4b475987d824ee476756 /client/js/util | |
| parent | 6bf5764c6ce49cb0c8a1f609d7e28b8a81f74326 (diff) | |
client/markdown: allow to specify image size
Diffstat (limited to 'client/js/util')
| -rw-r--r-- | client/js/util/markdown.js | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/client/js/util/markdown.js b/client/js/util/markdown.js index f69df7c..3d50b0d 100644 --- a/client/js/util/markdown.js +++ b/client/js/util/markdown.js @@ -115,8 +115,37 @@ class StrikeThroughWrapper extends BaseMarkdownWrapper { } } -function formatMarkdown(text) { +function createRenderer() { + function sanitize(str) { + return str.replace(/&<"/g, function (m) { + if (m === '&') { + return '&'; + } + if (m === '<') { + return '<'; + } + return '"'; + }); + } + const renderer = new marked.Renderer(); + renderer.image = (href, title, alt) => { + let [_, url, width, height] = + /^(.+?)(?:\s=\s*(\d*)\s*x\s*(\d*)\s*)?$/.exec(href); + let res = '<img src="' + sanitize(url) + '" alt="' + sanitize(alt); + if (width) { + res += '" width="' + width; + } + if (height) { + res += '" height="' + height; + } + return res + '">'; + } + return renderer; +} + +function formatMarkdown(text) { + const renderer = createRenderer(); const options = { renderer: renderer, breaks: true, @@ -145,7 +174,7 @@ function formatMarkdown(text) { } function formatInlineMarkdown(text) { - const renderer = new marked.Renderer(); + const renderer = createRenderer(); const options = { renderer: renderer, breaks: true, |