@lab-anssi/lib 2.0.0 → 2.1.2
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,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fabriqueAdaptateurHttp = void 0;
|
|
4
|
+
const fabriqueAdaptateurHttp = () => ({
|
|
5
|
+
ressourceExiste: async (url) => {
|
|
6
|
+
const response = await fetch(url, { method: 'HEAD' });
|
|
7
|
+
return response.ok;
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
exports.fabriqueAdaptateurHttp = fabriqueAdaptateurHttp;
|
package/dist/cms/cmsCrisp.js
CHANGED
|
@@ -4,15 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CmsCrisp = void 0;
|
|
7
|
+
const erreurs_1 = require("../erreurs");
|
|
7
8
|
const adaptateurCmsCrisp_1 = require("./adaptateurCmsCrisp");
|
|
9
|
+
const adaptateurHttp_1 = require("./adaptateurHttp");
|
|
8
10
|
const crispMarkdown_1 = __importDefault(require("./crispMarkdown"));
|
|
9
|
-
const erreurs_1 = require("../erreurs");
|
|
10
11
|
class CmsCrisp {
|
|
11
12
|
adaptateurCmsCrisp;
|
|
12
13
|
constructeurCrispMarkdown;
|
|
13
14
|
constructor(idSite, cleApi) {
|
|
14
15
|
this.adaptateurCmsCrisp = new adaptateurCmsCrisp_1.AdaptateurCmsCrisp(idSite, cleApi);
|
|
15
|
-
this.constructeurCrispMarkdown = (contenuMarkdown) => new crispMarkdown_1.default(contenuMarkdown);
|
|
16
|
+
this.constructeurCrispMarkdown = (contenuMarkdown) => new crispMarkdown_1.default(contenuMarkdown, (0, adaptateurHttp_1.fabriqueAdaptateurHttp)());
|
|
16
17
|
}
|
|
17
18
|
async recupereArticle(id) {
|
|
18
19
|
const article = await this.adaptateurCmsCrisp.recupereArticle(id);
|
|
@@ -20,9 +21,9 @@ class CmsCrisp {
|
|
|
20
21
|
let crispMarkdown = this.constructeurCrispMarkdown(contenuMarkdown);
|
|
21
22
|
return {
|
|
22
23
|
titre,
|
|
23
|
-
contenu: crispMarkdown.versHTML(),
|
|
24
|
+
contenu: await crispMarkdown.versHTML(),
|
|
24
25
|
description,
|
|
25
|
-
tableDesMatieres: crispMarkdown.tableDesMatieres(),
|
|
26
|
+
tableDesMatieres: await crispMarkdown.tableDesMatieres(),
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
async recupereArticleCategorie(slug, idCategorie) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AdaptateurHttp } from './adaptateurHttp';
|
|
1
2
|
import { EntreeTableDesMatieres } from './types';
|
|
2
3
|
declare class CrispMarkdown {
|
|
3
4
|
private contenuMarkdown;
|
|
@@ -5,9 +6,9 @@ declare class CrispMarkdown {
|
|
|
5
6
|
private aDejaParse;
|
|
6
7
|
private tdm;
|
|
7
8
|
private marked;
|
|
8
|
-
constructor(contenuMarkdown: string);
|
|
9
|
-
parseLeMarkdown(): void
|
|
10
|
-
versHTML(): string | null
|
|
11
|
-
tableDesMatieres(): EntreeTableDesMatieres[]
|
|
9
|
+
constructor(contenuMarkdown: string, adaptateurHttp: AdaptateurHttp);
|
|
10
|
+
parseLeMarkdown(): Promise<void>;
|
|
11
|
+
versHTML(): Promise<string | null>;
|
|
12
|
+
tableDesMatieres(): Promise<EntreeTableDesMatieres[]>;
|
|
12
13
|
}
|
|
13
14
|
export default CrispMarkdown;
|
|
@@ -31,7 +31,7 @@ class CrispMarkdown {
|
|
|
31
31
|
aDejaParse = false;
|
|
32
32
|
tdm = [];
|
|
33
33
|
marked;
|
|
34
|
-
constructor(contenuMarkdown) {
|
|
34
|
+
constructor(contenuMarkdown, adaptateurHttp) {
|
|
35
35
|
this.contenuMarkdown = contenuMarkdown;
|
|
36
36
|
const boiteAide = extensionBoite(/^\|([^|\n]+)/, 'boiteAide', 'aide');
|
|
37
37
|
const boiteInfo = extensionBoite(/^\|\|([^||\n]+)/, 'boiteInfo', 'information');
|
|
@@ -57,7 +57,10 @@ class CrispMarkdown {
|
|
|
57
57
|
return false;
|
|
58
58
|
},
|
|
59
59
|
renderer(token) {
|
|
60
|
-
|
|
60
|
+
const elementPiste = token.lienPisteSousTitres
|
|
61
|
+
? `<track kind='captions' src='${token.lienPisteSousTitres}' srclang='fr' label='Français' default />`
|
|
62
|
+
: '';
|
|
63
|
+
return `<div class='conteneur-video'><video controls crossorigin='anonymous'><source src='${token.text}' type='video/mp4' />${elementPiste}</video><p class='legende'>${token.legende}</p></div>`;
|
|
61
64
|
},
|
|
62
65
|
};
|
|
63
66
|
// Source d'inspiration pour la gestion des sections :
|
|
@@ -109,23 +112,33 @@ class CrispMarkdown {
|
|
|
109
112
|
},
|
|
110
113
|
});
|
|
111
114
|
this.marked = new marked_1.Marked({
|
|
115
|
+
async: true,
|
|
112
116
|
renderer: moteurDeRendu(this),
|
|
113
117
|
extensions: [boiteAide, boiteInfo, boiteAlerte, video, section],
|
|
118
|
+
walkTokens: async (token) => {
|
|
119
|
+
if (token.type === 'video') {
|
|
120
|
+
const lienPisteSousTitres = token.text.replace('.mp4', '.vtt');
|
|
121
|
+
const pisteSousTitresExiste = await adaptateurHttp.ressourceExiste(lienPisteSousTitres);
|
|
122
|
+
token.lienPisteSousTitres = pisteSousTitresExiste
|
|
123
|
+
? lienPisteSousTitres
|
|
124
|
+
: undefined;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
114
127
|
});
|
|
115
128
|
}
|
|
116
|
-
parseLeMarkdown() {
|
|
117
|
-
const avecCorrectionLigneHorizontale = this.contenuMarkdown.replaceAll(
|
|
118
|
-
this.contenuHTML = this.marked.parse(avecCorrectionLigneHorizontale);
|
|
129
|
+
async parseLeMarkdown() {
|
|
130
|
+
const avecCorrectionLigneHorizontale = this.contenuMarkdown.replaceAll('\n---', '\n\n---');
|
|
131
|
+
this.contenuHTML = (await this.marked.parse(avecCorrectionLigneHorizontale));
|
|
119
132
|
this.aDejaParse = true;
|
|
120
133
|
}
|
|
121
|
-
versHTML() {
|
|
134
|
+
async versHTML() {
|
|
122
135
|
if (!this.aDejaParse)
|
|
123
|
-
this.parseLeMarkdown();
|
|
136
|
+
await this.parseLeMarkdown();
|
|
124
137
|
return this.contenuHTML;
|
|
125
138
|
}
|
|
126
|
-
tableDesMatieres() {
|
|
139
|
+
async tableDesMatieres() {
|
|
127
140
|
if (!this.aDejaParse)
|
|
128
|
-
this.parseLeMarkdown();
|
|
141
|
+
await this.parseLeMarkdown();
|
|
129
142
|
return this.tdm;
|
|
130
143
|
}
|
|
131
144
|
}
|