generated from codegouvfr/eleventy-dsfr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown-custom-containers.js
61 lines (57 loc) · 1.63 KB
/
markdown-custom-containers.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module.exports = {
callout: md => {
const re = /^callout(\s+.*)?$/;
return {
validate: (params) => {
return params.trim().match(re);
},
render: (tokens, idx) => {
const params = tokens[idx].info.trim().match(re);
if (tokens[idx].nesting === 1) {
// opening tag
return `
<div class="fr-callout">
<h3 class="fr-callout__title">${md.utils.escapeHtml(params?.[1]) || ""}</h3>
<div class="fr-callout__text">
`;
} else {
// closing tag
return '</div></div>\n';
}
}
}
},
quote: md => {
const re = /^quote(\s+.*)?$/
let params = undefined;
return {
validate: (params) => {
return params.trim().match(re);
},
render: (tokens, idx) => {
params = tokens[idx].info.trim().match(re) || params;
if (tokens[idx].nesting === 1) {
// opening tag
return `
<figure class="fr-quote fr-quote--column">
<blockquote>
`;
} else {
// closing tag
const imageBlock = params && params[1] ? `
<figcaption>
<div class="fr-quote__image">
<img src="${md.utils.escapeHtml(params[1]) || ""}" class="fr-responsive-img" alt="" />
</div>
</figcaption>` : undefined;
return `
${imageBlock || ""}
</blockquote>
</figure>
<br>
\n`;
}
}
}
}
}