@mostajs/markdown-html 0.1.0 → 0.1.1
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.
- package/package.json +8 -2
- package/src/index.js +8 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostajs/markdown-html",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Rendu Markdown → HTML zéro dépendance, sans build : titres, listes, tableaux, code, citations, liens, cases à cocher + table des matières. Tout est échappé (le HTML d'un .md n'est PAS interprété). Pour servir un README comme page d'aide.",
|
|
5
5
|
"author": "Dr Hamid MADANI <drmdh@msn.com>",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
@@ -25,5 +25,11 @@
|
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
27
|
"test": "node test-scripts/unit/markdown-html.test.mjs"
|
|
28
|
+
},
|
|
29
|
+
"mostajs": {
|
|
30
|
+
"niveau": "N2",
|
|
31
|
+
"nature": "compose",
|
|
32
|
+
"reutilisabilite": "multi-domaine",
|
|
33
|
+
"depend_de": []
|
|
28
34
|
}
|
|
29
|
-
}
|
|
35
|
+
}
|
package/src/index.js
CHANGED
|
@@ -93,10 +93,16 @@ export function mdToHtml(md = '') {
|
|
|
93
93
|
if (ul && !state.ul) { closeList(state); out.push('<ul>'); state.ul = true; }
|
|
94
94
|
if (ol && !state.ol) { closeList(state); out.push('<ol>'); state.ol = true; }
|
|
95
95
|
let item = (ul || ol)[1];
|
|
96
|
+
i++;
|
|
97
|
+
// Lazy continuation : recolle les lignes repliées du même élément (Markdown à retour à la ligne dur)
|
|
98
|
+
// → l'élément reste dans la liste (indentation pendante) ET le **gras** à cheval sur 2 lignes est interprété.
|
|
99
|
+
while (i < lines.length && lines[i].trim() && !/^\s*([-*+]\s|\d+[.)]\s|#{1,6}\s|>|\||```)/.test(lines[i])) {
|
|
100
|
+
item += ' ' + lines[i].trim(); i++;
|
|
101
|
+
}
|
|
96
102
|
const box = item.match(/^\[([ xX])\]\s+(.*)$/);
|
|
97
103
|
if (box) item = `<input type="checkbox" disabled${/[xX]/.test(box[1]) ? ' checked' : ''}> ${box[2]}`;
|
|
98
|
-
out.push(`<li>${box ? item.replace(/^(<input[^>]*>
|
|
99
|
-
|
|
104
|
+
out.push(`<li>${box ? item.replace(/^(<input[^>]*> )(.*)$/, (m, a, b) => a + inline(b)) : inline(item)}</li>`);
|
|
105
|
+
continue;
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
// Ligne vide → ferme les listes
|