@lab-anssi/lib 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,7 @@ class CrispMarkdown {
|
|
30
30
|
contenuHTML = null;
|
31
31
|
aDejaParse = false;
|
32
32
|
tdm = [];
|
33
|
+
marked;
|
33
34
|
constructor(contenuMarkdown) {
|
34
35
|
this.contenuMarkdown = contenuMarkdown;
|
35
36
|
const boiteAide = extensionBoite(/^\|([^|\n]+)/, 'boiteAide', 'aide');
|
@@ -59,6 +60,37 @@ class CrispMarkdown {
|
|
59
60
|
return `<div class='conteneur-video'><video src='${token.text}' controls></video><p class='legende'>${token.legende}</p></div>`;
|
60
61
|
},
|
61
62
|
};
|
63
|
+
// Source d'inspiration pour la gestion des sections :
|
64
|
+
// https://github.com/markedjs/marked/discussions/2889
|
65
|
+
let niveauDeSection = 0;
|
66
|
+
const sectionRegexp = new RegExp(`^(# )[^]*?(?:\\n(?=\\1)|$)`);
|
67
|
+
const section = {
|
68
|
+
name: 'sectionBlock',
|
69
|
+
level: 'block',
|
70
|
+
start(source) {
|
71
|
+
return source.match(/^#/m)?.index;
|
72
|
+
},
|
73
|
+
tokenizer(source) {
|
74
|
+
if (niveauDeSection > 0)
|
75
|
+
return;
|
76
|
+
const match = source.match(sectionRegexp);
|
77
|
+
if (!match) {
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
niveauDeSection++;
|
81
|
+
const tokens = this.lexer.blockTokens(match[0]);
|
82
|
+
niveauDeSection--;
|
83
|
+
return {
|
84
|
+
type: 'sectionBlock',
|
85
|
+
raw: match[0],
|
86
|
+
level: 1,
|
87
|
+
tokens,
|
88
|
+
};
|
89
|
+
},
|
90
|
+
renderer(token) {
|
91
|
+
return `<section>${this.parser.parse(token.tokens)}</section>`;
|
92
|
+
},
|
93
|
+
};
|
62
94
|
const moteurDeRendu = (that) => ({
|
63
95
|
heading(...[texte, profondeur]) {
|
64
96
|
const slugDuTitre = texte.toLowerCase().replace(/\W+/g, '-');
|
@@ -76,13 +108,13 @@ class CrispMarkdown {
|
|
76
108
|
return `<a href='${lien}' target='_blank' rel='nofollow'>${texte}</a>`;
|
77
109
|
},
|
78
110
|
});
|
79
|
-
|
111
|
+
this.marked = new marked_1.Marked({
|
80
112
|
renderer: moteurDeRendu(this),
|
81
|
-
extensions: [boiteAide, boiteInfo, boiteAlerte, video],
|
113
|
+
extensions: [boiteAide, boiteInfo, boiteAlerte, video, section],
|
82
114
|
});
|
83
115
|
}
|
84
116
|
parseLeMarkdown() {
|
85
|
-
this.contenuHTML =
|
117
|
+
this.contenuHTML = this.marked.parse(this.contenuMarkdown);
|
86
118
|
this.aDejaParse = true;
|
87
119
|
}
|
88
120
|
versHTML() {
|