@knowvah/dot-engine 2.6.10 → 2.6.11
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/common/html-entities.d.ts +13 -5
- package/dist/common/html-entities.d.ts.map +1 -1
- package/dist/common/htmltable-lex-chardata.d.ts +9 -0
- package/dist/common/htmltable-lex-chardata.d.ts.map +1 -1
- package/dist/index.js +57 -21
- package/dist/index.js.map +2 -2
- package/dist/render.js +56 -20
- package/dist/render.js.map +2 -2
- package/package.json +1 -1
- package/src/common/html-entities.ts +77 -25
- package/src/common/htmltable-lex-chardata.ts +42 -8
|
@@ -6,11 +6,19 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const HTML_ENTITIES: Readonly<Record<string, number>>;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Latin-1 inputs are decoded at the
|
|
12
|
-
* survey's render-one), so this
|
|
13
|
-
*
|
|
9
|
+
* Substitute entities like `{` and `&` with their characters: C's
|
|
10
|
+
* make_label UTF-8 branch. An `&` whose entity has no value stays (scanning
|
|
11
|
+
* resumes where htmlEntity left it). Latin-1 inputs are decoded at the
|
|
12
|
+
* byte->string boundary by the caller (the survey's render-one), so this
|
|
13
|
+
* covers them too, as does latin1ToUTF8's identical entity handling.
|
|
14
|
+
*
|
|
15
|
+
* C appends a value's bytes itself: below 0x7F one byte, below 0x7FF two,
|
|
16
|
+
* else three, truncated to `char`. For every value whose bytes are valid
|
|
17
|
+
* UTF-8 that is the character itself. 0x7F, 0x7FF, surrogates and values
|
|
18
|
+
* above 0xFFFF come out as invalid UTF-8, which a JS string cannot hold; the
|
|
19
|
+
* port keeps the character there (documented divergence).
|
|
20
|
+
* @see lib/common/utils.c:htmlEntityUTF8
|
|
21
|
+
* @see lib/common/utils.c:latin1ToUTF8
|
|
14
22
|
* @see lib/common/labels.c:make_label (CHAR_LATIN1 vs default)
|
|
15
23
|
*/
|
|
16
24
|
export declare function htmlEntityUTF8(s: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-entities.d.ts","sourceRoot":"","sources":["../../src/common/html-entities.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA6P1D,CAAC;
|
|
1
|
+
{"version":3,"file":"html-entities.d.ts","sourceRoot":"","sources":["../../src/common/html-entities.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA6P1D,CAAC;AA+DF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAWhD"}
|
|
@@ -30,6 +30,15 @@ export declare function keepLostText(st: CharDataState, lost: readonly Token[]):
|
|
|
30
30
|
* @see lib/common/htmlparse.y:table
|
|
31
31
|
*/
|
|
32
32
|
export declare function releaseXb(st: CharDataState, first: Token): void;
|
|
33
|
+
/**
|
|
34
|
+
* The characters expat hands characterData for a text run: scanEntity first
|
|
35
|
+
* rewrites each entities.h name to `&#N;` (its `&` only when no `#` follows),
|
|
36
|
+
* then expat decodes character references, of any length, and its five
|
|
37
|
+
* predefined entities. Runs expat rejects never get here (textRefError).
|
|
38
|
+
* @see lib/common/htmllex.c:findNext
|
|
39
|
+
* @see lib/common/utils.c:scanEntity
|
|
40
|
+
*/
|
|
41
|
+
export declare function decodeTextRefs(raw: string): string;
|
|
33
42
|
/** The text token of a text run, if anything is left after cleaning. */
|
|
34
43
|
export declare function textTokens(raw: string): Token[];
|
|
35
44
|
/** characterData on what expat decoded: a T_string when any character survives. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmltable-lex-chardata.d.ts","sourceRoot":"","sources":["../../src/common/htmltable-lex-chardata.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"htmltable-lex-chardata.d.ts","sourceRoot":"","sources":["../../src/common/htmltable-lex-chardata.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,uGAAuG;AACvG,eAAO,MAAM,eAAe,QAAO,aAA2C,CAAC;AAc/E,yFAAyF;AACzF,wBAAgB,SAAS,CAAC,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,CAQhE;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI,CAE5E;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAM/D;AAkCD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,EAAE,CAO/C;AAED,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,CAGvD"}
|
package/dist/index.js
CHANGED
|
@@ -10439,28 +10439,46 @@ var HTML_ENTITIES = {
|
|
|
10439
10439
|
"zwj": 8205,
|
|
10440
10440
|
"zwnj": 8204
|
|
10441
10441
|
};
|
|
10442
|
-
var
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
|
|
10446
|
-
|
|
10447
|
-
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
|
|
10451
|
-
|
|
10452
|
-
|
|
10453
|
-
}
|
|
10454
|
-
|
|
10455
|
-
|
|
10456
|
-
|
|
10442
|
+
var ENTITY_NAME_LENGTH_MAX = 8;
|
|
10443
|
+
function numericEntity(s, at) {
|
|
10444
|
+
const hex = s[at + 1] === "x" || s[at + 1] === "X";
|
|
10445
|
+
const digit = hex ? /^[0-9A-Fa-f]$/ : /^[0-9]$/;
|
|
10446
|
+
let n = 0;
|
|
10447
|
+
let i = hex ? 2 : 1;
|
|
10448
|
+
for (; i < 8; i++) {
|
|
10449
|
+
const c = s[at + i] ?? "";
|
|
10450
|
+
if (!digit.test(c)) break;
|
|
10451
|
+
n = n * (hex ? 16 : 10) + parseInt(c, 16);
|
|
10452
|
+
}
|
|
10453
|
+
if (i < 8 && s[at + i] === ";") return { value: n, next: at + i + 1 };
|
|
10454
|
+
return { value: 0, next: at };
|
|
10455
|
+
}
|
|
10456
|
+
function namedEntity(s, at) {
|
|
10457
|
+
for (let i = 0; i < ENTITY_NAME_LENGTH_MAX; i++) {
|
|
10458
|
+
const c = s[at + i];
|
|
10459
|
+
if (c === void 0 || c === "\0") break;
|
|
10460
|
+
if (c === ";") {
|
|
10461
|
+
const key = s.slice(at, at + i);
|
|
10462
|
+
if (Object.hasOwn(HTML_ENTITIES, key)) return { value: HTML_ENTITIES[key], next: at + i + 1 };
|
|
10463
|
+
break;
|
|
10464
|
+
}
|
|
10465
|
+
}
|
|
10466
|
+
return { value: 0, next: at };
|
|
10467
|
+
}
|
|
10468
|
+
function htmlEntity(s, at) {
|
|
10469
|
+
return s[at] === "#" ? numericEntity(s, at) : namedEntity(s, at);
|
|
10457
10470
|
}
|
|
10458
10471
|
function htmlEntityUTF8(s) {
|
|
10459
|
-
|
|
10460
|
-
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10472
|
+
let amp = s.indexOf("&");
|
|
10473
|
+
if (amp < 0) return s;
|
|
10474
|
+
let out = "";
|
|
10475
|
+
let from = 0;
|
|
10476
|
+
for (; amp >= 0; amp = s.indexOf("&", from)) {
|
|
10477
|
+
const e = htmlEntity(s, amp + 1);
|
|
10478
|
+
out += s.slice(from, amp) + (e.value ? String.fromCodePoint(e.value) : "&");
|
|
10479
|
+
from = e.next;
|
|
10480
|
+
}
|
|
10481
|
+
return out + s.slice(from);
|
|
10464
10482
|
}
|
|
10465
10483
|
|
|
10466
10484
|
// src/common/htmltable-lex-attvalue.ts
|
|
@@ -10854,8 +10872,26 @@ function releaseXb(st, first) {
|
|
|
10854
10872
|
function cleanText(decoded) {
|
|
10855
10873
|
return decoded.replace(/[\x00-\x1f]/g, "");
|
|
10856
10874
|
}
|
|
10875
|
+
var XML_PREDEFINED = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
|
|
10876
|
+
var SCAN_ENTITY_MIN = 2;
|
|
10877
|
+
var SCAN_ENTITY_MAX = 8;
|
|
10878
|
+
var TEXT_REF = /&(#x[0-9A-Fa-f]+|#[0-9]+|[^&;]+);/g;
|
|
10879
|
+
function textRefValue(ref, body) {
|
|
10880
|
+
if (body[0] === "#") {
|
|
10881
|
+
const v = charRefNumber(ref);
|
|
10882
|
+
return v < 0 ? ref : String.fromCodePoint(v);
|
|
10883
|
+
}
|
|
10884
|
+
const n = body.length;
|
|
10885
|
+
if (n >= SCAN_ENTITY_MIN && n <= SCAN_ENTITY_MAX && Object.hasOwn(HTML_ENTITIES, body)) {
|
|
10886
|
+
return String.fromCodePoint(HTML_ENTITIES[body]);
|
|
10887
|
+
}
|
|
10888
|
+
return Object.hasOwn(XML_PREDEFINED, body) ? XML_PREDEFINED[body] : ref;
|
|
10889
|
+
}
|
|
10890
|
+
function decodeTextRefs(raw) {
|
|
10891
|
+
return raw.indexOf("&") < 0 ? raw : raw.replace(TEXT_REF, textRefValue);
|
|
10892
|
+
}
|
|
10857
10893
|
function textTokens(raw) {
|
|
10858
|
-
return charDataTokens(
|
|
10894
|
+
return charDataTokens(decodeTextRefs(raw));
|
|
10859
10895
|
}
|
|
10860
10896
|
function charDataTokens(decoded) {
|
|
10861
10897
|
const clean = cleanText(decoded);
|