@lab-anssi/lib 1.0.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.
@@ -0,0 +1,13 @@
|
|
1
|
+
export type ArticleMarkdownCrisp = {
|
2
|
+
titre: string;
|
3
|
+
contenuMarkdown: string;
|
4
|
+
description: string;
|
5
|
+
};
|
6
|
+
export declare class AdaptateurCmsCrisp {
|
7
|
+
readonly urlBase: string;
|
8
|
+
readonly enteteCrisp: {
|
9
|
+
[cle: string]: string;
|
10
|
+
};
|
11
|
+
constructor(idSite: string, cleApi: string);
|
12
|
+
recupereArticle: (idArticle: string) => Promise<ArticleMarkdownCrisp>;
|
13
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { AdaptateurCmsCrisp } from './adaptateurCmsCrisp';
|
2
|
+
import CrispMarkdown from './crispMarkdown';
|
3
|
+
export type PageHtmlCrisp = {
|
4
|
+
titre: string;
|
5
|
+
contenu: string | null;
|
6
|
+
description: string;
|
7
|
+
tableDesMatieres: any[];
|
8
|
+
};
|
9
|
+
export declare class CmsCrisp {
|
10
|
+
adaptateurCmsCrisp: AdaptateurCmsCrisp;
|
11
|
+
constructeurCrispMarkdown: (contenuMarkdown: string) => CrispMarkdown;
|
12
|
+
constructor(idSite: string, cleApi: string);
|
13
|
+
recupereArticle(id: string): Promise<PageHtmlCrisp>;
|
14
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
declare class CrispMarkdown {
|
2
|
+
private contenuMarkdown;
|
3
|
+
private contenuHTML;
|
4
|
+
private aDejaParse;
|
5
|
+
private tdm;
|
6
|
+
private marked;
|
7
|
+
constructor(contenuMarkdown: string);
|
8
|
+
parseLeMarkdown(): void;
|
9
|
+
versHTML(): string | null;
|
10
|
+
tableDesMatieres(): any[];
|
11
|
+
}
|
12
|
+
export default CrispMarkdown;
|
@@ -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() {
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { CmsCrisp, type PageHtmlCrisp } from './cms/cmsCrisp';
|