client/markdown: allow to specify image size
This commit is contained in:
parent
6bf5764c6c
commit
32d498c74b
2 changed files with 39 additions and 2 deletions
|
@ -28,3 +28,11 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p>You can also specify the size of embedded images like this:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>![alt](href =WIDTHx "title")</code></li>
|
||||
<li><code>![alt](href =xHEIGHT "title")</code></li>
|
||||
<li><code>![alt](href =WIDTHxHEIGHT "title")</code></li>
|
||||
</ul>
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue