@ouestfrance/sipa-bms-ui 8.44.0 → 8.45.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.
- package/dist/components/form/bms-input-code.linters.d.ts +0 -14
- package/dist/sipa-bms-ui.es.js +16 -3
- package/dist/sipa-bms-ui.es.js.map +1 -1
- package/dist/sipa-bms-ui.umd.js +16 -3
- package/dist/sipa-bms-ui.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/form/bms-input-code.linters.spec.ts +14 -3
- package/src/components/form/bms-input-code.linters.ts +23 -3
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { Diagnostic } from '@codemirror/lint';
|
|
2
2
|
import { Extension } from '@codemirror/state';
|
|
3
|
-
/**
|
|
4
|
-
* Retourne les diagnostics HTML pour un code donné.
|
|
5
|
-
* Parse le contenu comme du XML strict pour détecter les erreurs de structure.
|
|
6
|
-
*
|
|
7
|
-
* Comportement attendu :
|
|
8
|
-
* - Chaîne vide → aucun diagnostic
|
|
9
|
-
* - HTML bien formé (`<div><p>Hello</p></div>`) → aucun diagnostic
|
|
10
|
-
* - Balises auto-fermantes XHTML (`<br />`, `<img />`) → aucun diagnostic
|
|
11
|
-
* - Balise non fermée (`<div><p>Hello</div>`) → diagnostic « HTML invalide »
|
|
12
|
-
* - Attribut mal formé (`<div class=>`) → diagnostic « HTML invalide »
|
|
13
|
-
*
|
|
14
|
-
* Limitation : le parser XML est plus strict que le parser HTML du navigateur.
|
|
15
|
-
* Les balises void HTML5 non fermées (`<br>`, `<img>`) sont considérées invalides.
|
|
16
|
-
*/
|
|
17
3
|
export declare const htmlDiagnostics: (code: string) => Diagnostic[];
|
|
18
4
|
/**
|
|
19
5
|
* Retourne les diagnostics CSS pour un code donné.
|
package/dist/sipa-bms-ui.es.js
CHANGED
|
@@ -112756,12 +112756,25 @@ var useDarkMode = () => {
|
|
|
112756
112756
|
* Limitation : le parser XML est plus strict que le parser HTML du navigateur.
|
|
112757
112757
|
* Les balises void HTML5 non fermées (`<br>`, `<img>`) sont considérées invalides.
|
|
112758
112758
|
*/
|
|
112759
|
+
var ROOT_TAG = "<root>";
|
|
112760
|
+
var htmlErrorOffset = (errorText, code) => {
|
|
112761
|
+
const match = errorText.match(/error on line (\d+) at column (\d+)/i);
|
|
112762
|
+
if (!match) return 0;
|
|
112763
|
+
const line = parseInt(match[1]);
|
|
112764
|
+
const col = parseInt(match[2]) - (line === 1 ? 6 : 0);
|
|
112765
|
+
const lines = code.split("\n");
|
|
112766
|
+
let offset = 0;
|
|
112767
|
+
for (let i = 0; i < line - 1 && i < lines.length; i++) offset += lines[i].length + 1;
|
|
112768
|
+
return Math.min(Math.max(0, offset + col - 1), code.length);
|
|
112769
|
+
};
|
|
112759
112770
|
var htmlDiagnostics = (code) => {
|
|
112760
112771
|
if (!code.trim()) return [];
|
|
112761
|
-
|
|
112772
|
+
const parserError = new DOMParser().parseFromString(`${ROOT_TAG}${code}</root>`, "text/xml").querySelector("parsererror");
|
|
112773
|
+
if (!parserError) return [];
|
|
112774
|
+
const from = htmlErrorOffset(parserError.textContent ?? "", code);
|
|
112762
112775
|
return [{
|
|
112763
|
-
from
|
|
112764
|
-
to: code.length,
|
|
112776
|
+
from,
|
|
112777
|
+
to: Math.min(from + 1, code.length),
|
|
112765
112778
|
severity: "error",
|
|
112766
112779
|
message: "HTML invalide : balise mal formée ou non fermée"
|
|
112767
112780
|
}];
|