forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquote.js
More file actions
executable file
·38 lines (26 loc) · 920 Bytes
/
quote.js
File metadata and controls
executable file
·38 lines (26 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
/**
* ```quote author="Author"
*/
const markdownItContainer = require('markdown-it-container');
const parseAttrs = require('../utils/parseAttrs');
module.exports = function(md) {
md.use(markdownItContainer, 'quote', {
marker: '`'
});
md.renderer.rules.container_quote_open = function(tokens, idx, options, env, slf) {
return `<blockquote class="quote"><div class="quote__i"><div class="quote__text">`;
};
md.renderer.rules.container_quote_close = function(tokens, idx, options, env, slf) {
let result = '</div></div>';
let i = idx - 1;
while (tokens[i].type != 'container_quote_open') i--;
let attrs = parseAttrs(tokens[i].info, true);
if (attrs.author) {
result += `<footer class="quote__footer">
<cite class="quote__author">${md.utils.escapeHtml(attrs.author)}</cite>
</footer>`;
}
return result + '</blockquote>';
};
};