forked from IGNF/cartes.gouv.fr-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown-custom-containers.js
133 lines (124 loc) · 3.93 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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`;
}
},
};
},
alert: (md) => {
const re = /^(info|warning|error|success)(\s+.*)?$/;
return {
validate: (params) => {
return params.trim().match(re);
},
render: (tokens, idx) => {
const params = tokens[idx].info.trim().match(re);
const type = params?.[1];
const title = md.utils.escapeHtml(params?.[2]) || "";
if (tokens[idx].nesting === 1) {
title_elem = "";
small_class = "fr-alert--sm";
if (title !== "") {
title_elem = `<h3 class="fr-alert__title">${title}</h3>`;
small_class = "";
}
// opening tag
return `
<div class="fr-alert fr-alert--${type} ${small_class}">
${title_elem}
`;
} else {
// closing tag
return "</div>\n";
}
},
};
},
accordion: (md) => {
const re = /^(accordionsgroup|.*)?$/;
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
if (params?.[1] === "accordionsgroup") {
return `<div class="fr-accordions-group">`;
} else {
return `
<section class="fr-accordion">
<h3 class="fr-accordion__title">
<button class="fr-accordion__btn" aria-expanded="false" aria-controls="accordion-${idx}">
${md.utils.escapeHtml(params?.[1]) || ""}
</button>
</h3>
<div class="fr-collapse" id="accordion-${idx}">
`;
}
} else {
// closing tag
if (params?.[1] === "accordionsgroup") {
return `</div>`;
} else {
return "</div></section>\n";
}
}
},
marker: "?",
};
},
};