@mark1russell7/text 0.0.14 → 0.0.16
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/README.md +25 -1
- package/build/html.d.ts +1 -0
- package/build/html.d.ts.map +1 -1
- package/build/html.js.map +1 -1
- package/build/references.d.ts +18 -0
- package/build/references.d.ts.map +1 -0
- package/build/references.js +344 -0
- package/build/references.js.map +1 -0
- package/build/search.d.ts +12 -0
- package/build/search.d.ts.map +1 -1
- package/build/search.js +25 -7
- package/build/search.js.map +1 -1
- package/package.json +7 -2
- package/src/html-references.ts +207 -0
- package/src/html.ts +1 -0
- package/src/references.ts +140 -0
- package/src/search.ts +22 -3
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ The entry `@mark1russell7/text/search` also ranks the documents of a corpus for
|
|
|
74
74
|
- `inverseDocumentFrequency(documents, form)` gives the IDF of each term. The form `plain` is ln(N / df), so a term in each document has the weight 0. The form `smooth` is ln((N + 1) / (df + 1)) + 1.
|
|
75
75
|
- `termVector(words, idf)` gives the weights (1 + ln(tf)) × idf with a length of 1. `cosineSimilarity(a, b)` compares two vectors.
|
|
76
76
|
- `rankDocuments(corpus, query, form)` gives the score of each document, best first. A tie keeps the order of the corpus.
|
|
77
|
+
- `rankerOf(corpus, form)` computes the IDF and the vectors of a corpus one time. It gives a function of a query with the same scores as `rankDocuments`.
|
|
77
78
|
|
|
78
79
|
```ts
|
|
79
80
|
import { rankDocuments, searchWords } from "@mark1russell7/text/search";
|
|
@@ -287,6 +288,27 @@ elements.some((element) => element.name === "link" && element.attributes["rel"]
|
|
|
287
288
|
scanHtml("<html><head><title>T</title></head><body><noscript>On</noscript>Body</body></html>", { skip: ["head", "script", "style", "template", "noscript"] }).text; // " Body "
|
|
288
289
|
```
|
|
289
290
|
|
|
291
|
+
### The decode of character references
|
|
292
|
+
|
|
293
|
+
`decodeReferences(text)` of the entry `@mark1russell7/text/references` decodes the character references of HTML content, as the tokenizer of the HTML Living Standard does. Use it on the `text` of a scan.
|
|
294
|
+
|
|
295
|
+
- A named reference gets its value from the table of the standard, with its 2231 names. The longest name wins.
|
|
296
|
+
- A legacy name, for example `&` or ` `, is also correct with no semicolon. Thus `¬it;` gives `¬it;`.
|
|
297
|
+
- A decimal or hexadecimal reference gives its code point. The semicolon after the digits is optional.
|
|
298
|
+
- The value 0, a surrogate and a value above `0x10FFFF` give U+FFFD. The values `0x80` to `0x9F` give the characters of windows-1252.
|
|
299
|
+
- An ampersand with no reference after it stays as text. The function changes no other character.
|
|
300
|
+
- The function does not throw, and it is linear in the length of the text.
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
import { scanHtml } from "@mark1russell7/text/html";
|
|
304
|
+
import { decodeReferences } from "@mark1russell7/text/references";
|
|
305
|
+
|
|
306
|
+
decodeReferences("We’re on it – ’’ ©2026 ¬it;"); // "We’re on it – ’’ ©2026 ¬it;"
|
|
307
|
+
decodeReferences(scanHtml("<p>Fish & chips</p>").text); // " Fish & chips "
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
The table comes from `entities.json` of the standard, under the license CC BY 4.0. The script `scripts/html-references.ts` makes the module `src/html-references.ts` from it. The table is in the entry `./references`. Thus a bundle that imports only `scanHtml` does not get the table.
|
|
311
|
+
|
|
290
312
|
## The copies that this package replaces
|
|
291
313
|
|
|
292
314
|
The tests run 58 copies of these functions from other repositories of the owner. Each copy comes from a list of the duplication atlas, at a pinned commit. The file `test/copies.json` has each copy, and `test/differences.ts` has each difference from the function of this package, with its reason. A copy that is not in the list gives the same output on each of the 1000 test strings.
|
|
@@ -310,6 +332,8 @@ The tests also examine 18 copies of a cut with a mark, from a later list of the
|
|
|
310
332
|
- `partsAt` counts in code units, as `String.prototype.slice` does. A range can cut a surrogate pair or a grapheme.
|
|
311
333
|
- The three functions count units, not the width on a screen. A wide character, for example 日, is one unit, as a narrow character is.
|
|
312
334
|
- `scanHtml` does not make a tree. It does not close an element with no end tag, and it does not move an element as a browser does.
|
|
313
|
-
- `scanHtml` keeps the character references of the text and of each attribute value. Thus `&` stays as five characters.
|
|
335
|
+
- `scanHtml` keeps the character references of the text and of each attribute value. Thus `&` stays as five characters. `decodeReferences` decodes them.
|
|
336
|
+
- `decodeReferences` uses the rule of element content. In an attribute value, a legacy name with no semicolon before `=`, a letter or a digit stays as text, for example `©=`.
|
|
337
|
+
- `decodeReferences` does not change the other characters. The tokenizer also changes a NUL character and a carriage return, but this function does not.
|
|
314
338
|
- In `scanHtml`, a comment or a skipped element with no end is text. A browser hides the rest of the page in that case.
|
|
315
339
|
- In `scanHtml`, a tag in a word also gives a space. Thus `a<b>c</b>` gives the text `a c `.
|
package/build/html.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface HtmlScan {
|
|
|
20
20
|
/**
|
|
21
21
|
* The text of the HTML outside the tags, the comments and the skipped elements. Each tag, comment and skipped element
|
|
22
22
|
* gives one space, so two words in two elements stay two words. The white space and the character references stay as in the HTML.
|
|
23
|
+
* The function `decodeReferences` of the entry `./references` decodes the character references.
|
|
23
24
|
*/
|
|
24
25
|
readonly text: string;
|
|
25
26
|
/** The start tags outside the comments and the skipped elements, in the order of the HTML. The start tag of a skipped element is in the list. */
|
package/build/html.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","names":[],"sources":["../src/html.ts"],"mappings":";;;;;;iBAOiB;;WAEN;;;;;WAKA,YAAY,SAAS;;WAErB;;;iBAIM
|
|
1
|
+
{"version":3,"file":"html.d.ts","names":[],"sources":["../src/html.ts"],"mappings":";;;;;;iBAOiB;;WAEN;;;;;WAKA,YAAY,SAAS;;WAErB;;;iBAIM;;;;;;WAMN;;WAEA,mBAAmB;;;iBAIb;;WAEN;;;qBAIE;;;;;;;;;;;;;;;wBAqGG,SAAS,cAAc,UAAS,kBAAuB"}
|
package/build/html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","names":[],"sources":["../src/html.ts"],"sourcesContent":["/**\n * This module scans HTML for its text and its start tags, with no DOM. A check of a page reads the text that a reader with\n * no script gets. It also reads the elements of the page, for example an `h1` or a `link` with `rel=\"icon\"`. The scan is\n * linear in the length of the HTML. Thus a page with many starts of a comment and no end does not stop it.\n */\n\n/** A start tag that the scan found. */\nexport interface HtmlElement {\n /** The name of the element, in lower case. */\n readonly name: string;\n /**\n * The attributes of the start tag. Each name is in lower case. A value has no quotes, and its character references stay\n * as in the HTML. An attribute with no value has an empty value. When a tag has a name two times, the first value counts.\n */\n readonly attributes: Readonly<Record<string, string>>;\n /** The index of the \"<\" of the start tag in the HTML, in UTF-16 code units. */\n readonly start: number;\n}\n\n/** The result of a scan of HTML. */\nexport interface HtmlScan {\n /**\n * The text of the HTML outside the tags, the comments and the skipped elements. Each tag, comment and skipped element\n * gives one space, so two words in two elements stay two words. The white space and the character references stay as in the HTML.\n */\n readonly text: string;\n /** The start tags outside the comments and the skipped elements, in the order of the HTML. The start tag of a skipped element is in the list. */\n readonly elements: readonly HtmlElement[];\n}\n\n/** The options of `scanHtml`. */\nexport interface HtmlScanOptions {\n /** The names of the elements whose content gives no text and no element. The default is `HTML_SKIP`. */\n readonly skip?: readonly string[];\n}\n\n/** The elements that the scan skips by default. A script and a style hold code, not text, and a template is not on the page. */\nexport const HTML_SKIP: readonly string[] = Object.freeze([\"script\", \"style\", \"template\"]);\n\n/**\n * The elements whose content has no tags. A \"<\" in a script, a title or a text area does not start a tag. The content of\n * such an element that the scan does not skip is text.\n */\nconst RAW_TEXT: readonly string[] = [\"script\", \"style\", \"title\", \"textarea\", \"xmp\", \"iframe\", \"noembed\", \"noframes\"];\n\n/** This function tells if a character is white space in HTML: space, tab, line feed, form feed or carriage return. */\nconst isSpace = (char: string): boolean => char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\f\" || char === \"\\r\";\n\n/** This function tells if a character ends the name of a tag: white space, \"/\", \">\" or the end of the HTML. */\nconst endsName = (char: string): boolean => char === \"\" || char === \"/\" || char === \">\" || isSpace(char);\n\n/** A search for the first index of a text at or after a position, or -1. */\ntype Search = (needle: string, from: number) => number;\n\n/**\n * This function gives a search in a source. A text that is not after a position is not after a later position either. Thus\n * the search keeps each failure and does not do it again, and a scan with many searches stays linear.\n */\nfunction searchIn(source: string): Search {\n const missing = new Map<string, number>();\n return (needle, from) => {\n const least = missing.get(needle);\n if (least !== undefined && from >= least) return -1;\n const index = source.indexOf(needle, from);\n if (index === -1) missing.set(needle, from);\n return index;\n };\n}\n\n/** This function reads the start tag at `lt`. It gives undefined for a tag with no \">\" after it. */\nfunction readTag(html: string, lower: string, lt: number): { element: HtmlElement; end: number } | undefined {\n let at = lt + 1;\n while (!endsName(lower.charAt(at))) at += 1;\n const name = lower.slice(lt + 1, at);\n const attributes = new Map<string, string>();\n while (at < lower.length) {\n const char = lower.charAt(at);\n if (char === \">\") return { element: { name, attributes: Object.fromEntries(attributes), start: lt }, end: at + 1 };\n if (char === \"/\" || isSpace(char)) {\n at += 1;\n continue;\n }\n // A name of an attribute ends at white space, \"/\", \">\" or \"=\". A \"=\" at its start is a part of the name.\n const from = at;\n at += 1;\n while (!endsName(lower.charAt(at)) && lower.charAt(at) !== \"=\") at += 1;\n const key = lower.slice(from, at);\n let value = \"\";\n let next = at;\n while (isSpace(lower.charAt(next))) next += 1;\n if (lower.charAt(next) === \"=\") {\n next += 1;\n while (isSpace(lower.charAt(next))) next += 1;\n const quote = lower.charAt(next);\n if (quote === '\"' || quote === \"'\") {\n const close = lower.indexOf(quote, next + 1);\n if (close === -1) return undefined;\n value = html.slice(next + 1, close);\n at = close + 1;\n } else {\n at = next;\n while (at < lower.length && lower.charAt(at) !== \">\" && !isSpace(lower.charAt(at))) at += 1;\n value = html.slice(next, at);\n }\n }\n if (!attributes.has(key)) attributes.set(key, value);\n }\n return undefined;\n}\n\n/**\n * This function gives the start and the end of the end tag of `name` at or after `from`, or undefined. The name of the end\n * tag ends at white space, \"/\" or \">\", and the tag ends at the next \">\".\n */\nfunction endTagOf(lower: string, name: string, from: number, search: Search): { start: number; end: number } | undefined {\n const needle = `</${name}`;\n for (let start = search(needle, from); start !== -1; start = search(needle, start + 1)) {\n if (!endsName(lower.charAt(start + needle.length)) || lower.charAt(start + needle.length) === \"\") continue;\n const gt = search(\">\", start + needle.length);\n return gt === -1 ? undefined : { start, end: gt + 1 };\n }\n return undefined;\n}\n\n/**\n * This function scans HTML for its text and its start tags, from the left to the right, in one pass.\n *\n * - A comment, a tag, a doctype and a processing instruction give no text. Each gives one space.\n * - The content of an element of `skip`, to its end tag, gives no text and no element.\n * - The content of a script, a style, a title or a text area that the scan does not skip is text with no tags.\n * - A \"<\" starts a tag only before a letter, \"/\", \"!\" or \"?\", as in HTML. Each other \"<\" is text, as in `1 < 2`.\n * - A comment or a skipped element with no end is text, and the scan continues in it. A tag with no \">\" ends the scan,\n * and the rest of the HTML is text.\n *\n * @param html - The HTML, a document or a part of one.\n * @param options - The elements to skip. The default is `HTML_SKIP`.\n * @returns The text and the start tags.\n */\nexport function scanHtml(html: string, options: HtmlScanOptions = {}): HtmlScan {\n const skip = new Set((options.skip ?? HTML_SKIP).map((name) => name.toLowerCase()));\n // Only A to Z go to lower case, so each index of the copy is an index of the HTML.\n const lower = html.replace(/[A-Z]+/g, (upper) => upper.toLowerCase());\n const search = searchIn(lower);\n const unclosed = new Set<string>();\n const parts: string[] = [];\n const elements: HtmlElement[] = [];\n let at = 0;\n for (let lt = search(\"<\", 0); lt !== -1; lt = search(\"<\", Math.max(at, lt + 1))) {\n const next = lower.charAt(lt + 1);\n let end: number;\n if (lower.startsWith(\"<!--\", lt)) {\n // A comment can end at once: `<!-->` and `<!--->` are comments.\n const close = search(\"-->\", lt + 2);\n if (close === -1) continue;\n end = close + 3;\n } else if (next === \"/\" || next === \"!\" || next === \"?\") {\n const gt = search(\">\", lt + 2);\n if (gt === -1) break;\n end = gt + 1;\n } else if (next >= \"a\" && next <= \"z\") {\n const tag = readTag(html, lower, lt);\n if (tag === undefined) break;\n elements.push(tag.element);\n end = tag.end;\n const { name } = tag.element;\n const skipped = skip.has(name);\n if ((skipped || RAW_TEXT.includes(name)) && !unclosed.has(name)) {\n const close = endTagOf(lower, name, end, search);\n if (close === undefined) unclosed.add(name);\n else {\n parts.push(html.slice(at, lt), \" \");\n if (!skipped) parts.push(html.slice(end, close.start), \" \");\n at = close.end;\n continue;\n }\n }\n } else continue;\n parts.push(html.slice(at, lt), \" \");\n at = end;\n }\n parts.push(html.slice(at));\n return { text: parts.join(\"\"), elements };\n}\n"],"mappings":";;AAqCA,MAAa,YAA+B,OAAO,OAAO;CAAC;CAAU;CAAS;AAAU,CAAC;;;;;AAMzF,MAAM,WAA8B;CAAC;CAAU;CAAS;CAAS;CAAY;CAAO;CAAU;CAAW;AAAU;;AAGnH,MAAM,WAAW,SAA0B,SAAS,OAAO,SAAS,OAAQ,SAAS,QAAQ,SAAS,QAAQ,SAAS;;AAGvH,MAAM,YAAY,SAA0B,SAAS,MAAM,SAAS,OAAO,SAAS,OAAO,QAAQ,IAAI;;;;;AASvG,SAAS,SAAS,QAAwB;CACxC,MAAM,0BAAU,IAAI,IAAoB;CACxC,QAAQ,QAAQ,SAAS;EACvB,MAAM,QAAQ,QAAQ,IAAI,MAAM;EAChC,IAAI,UAAU,KAAA,KAAa,QAAQ,OAAO,OAAO;EACjD,MAAM,QAAQ,OAAO,QAAQ,QAAQ,IAAI;EACzC,IAAI,UAAU,IAAI,QAAQ,IAAI,QAAQ,IAAI;EAC1C,OAAO;CACT;AACF;;AAGA,SAAS,QAAQ,MAAc,OAAe,IAA+D;CAC3G,IAAI,KAAK,KAAK;CACd,OAAO,CAAC,SAAS,MAAM,OAAO,EAAE,CAAC,GAAG,MAAM;CAC1C,MAAM,OAAO,MAAM,MAAM,KAAK,GAAG,EAAE;CACnC,MAAM,6BAAa,IAAI,IAAoB;CAC3C,OAAO,KAAK,MAAM,QAAQ;EACxB,MAAM,OAAO,MAAM,OAAO,EAAE;EAC5B,IAAI,SAAS,KAAK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WAAW,SAAS,SAAS,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,GAAG;IAC/D,MAAM,QAAQ,SAAS,OAAO,MAAM,KAAK,MAAM;IAC/C,IAAI,UAAU,KAAA,GAAW,SAAS,IAAI,IAAI;SACrC;KACH,MAAM,KAAK,KAAK,MAAM,IAAI,EAAE,GAAG,GAAG;KAClC,IAAI,CAAC,SAAS,MAAM,KAAK,KAAK,MAAM,KAAK,MAAM,KAAK,GAAG,GAAG;KAC1D,KAAK,MAAM;KACX;IACF;GACF;EACF,OAAO;EACP,MAAM,KAAK,KAAK,MAAM,IAAI,EAAE,GAAG,GAAG;EAClC,KAAK;CACP;CACA,MAAM,KAAK,KAAK,MAAM,EAAE,CAAC;CACzB,OAAO;EAAE,MAAM,MAAM,KAAK,EAAE;EAAG;CAAS;AAC1C"}
|
|
1
|
+
{"version":3,"file":"html.js","names":[],"sources":["../src/html.ts"],"sourcesContent":["/**\n * This module scans HTML for its text and its start tags, with no DOM. A check of a page reads the text that a reader with\n * no script gets. It also reads the elements of the page, for example an `h1` or a `link` with `rel=\"icon\"`. The scan is\n * linear in the length of the HTML. Thus a page with many starts of a comment and no end does not stop it.\n */\n\n/** A start tag that the scan found. */\nexport interface HtmlElement {\n /** The name of the element, in lower case. */\n readonly name: string;\n /**\n * The attributes of the start tag. Each name is in lower case. A value has no quotes, and its character references stay\n * as in the HTML. An attribute with no value has an empty value. When a tag has a name two times, the first value counts.\n */\n readonly attributes: Readonly<Record<string, string>>;\n /** The index of the \"<\" of the start tag in the HTML, in UTF-16 code units. */\n readonly start: number;\n}\n\n/** The result of a scan of HTML. */\nexport interface HtmlScan {\n /**\n * The text of the HTML outside the tags, the comments and the skipped elements. Each tag, comment and skipped element\n * gives one space, so two words in two elements stay two words. The white space and the character references stay as in the HTML.\n * The function `decodeReferences` of the entry `./references` decodes the character references.\n */\n readonly text: string;\n /** The start tags outside the comments and the skipped elements, in the order of the HTML. The start tag of a skipped element is in the list. */\n readonly elements: readonly HtmlElement[];\n}\n\n/** The options of `scanHtml`. */\nexport interface HtmlScanOptions {\n /** The names of the elements whose content gives no text and no element. The default is `HTML_SKIP`. */\n readonly skip?: readonly string[];\n}\n\n/** The elements that the scan skips by default. A script and a style hold code, not text, and a template is not on the page. */\nexport const HTML_SKIP: readonly string[] = Object.freeze([\"script\", \"style\", \"template\"]);\n\n/**\n * The elements whose content has no tags. A \"<\" in a script, a title or a text area does not start a tag. The content of\n * such an element that the scan does not skip is text.\n */\nconst RAW_TEXT: readonly string[] = [\"script\", \"style\", \"title\", \"textarea\", \"xmp\", \"iframe\", \"noembed\", \"noframes\"];\n\n/** This function tells if a character is white space in HTML: space, tab, line feed, form feed or carriage return. */\nconst isSpace = (char: string): boolean => char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\f\" || char === \"\\r\";\n\n/** This function tells if a character ends the name of a tag: white space, \"/\", \">\" or the end of the HTML. */\nconst endsName = (char: string): boolean => char === \"\" || char === \"/\" || char === \">\" || isSpace(char);\n\n/** A search for the first index of a text at or after a position, or -1. */\ntype Search = (needle: string, from: number) => number;\n\n/**\n * This function gives a search in a source. A text that is not after a position is not after a later position either. Thus\n * the search keeps each failure and does not do it again, and a scan with many searches stays linear.\n */\nfunction searchIn(source: string): Search {\n const missing = new Map<string, number>();\n return (needle, from) => {\n const least = missing.get(needle);\n if (least !== undefined && from >= least) return -1;\n const index = source.indexOf(needle, from);\n if (index === -1) missing.set(needle, from);\n return index;\n };\n}\n\n/** This function reads the start tag at `lt`. It gives undefined for a tag with no \">\" after it. */\nfunction readTag(html: string, lower: string, lt: number): { element: HtmlElement; end: number } | undefined {\n let at = lt + 1;\n while (!endsName(lower.charAt(at))) at += 1;\n const name = lower.slice(lt + 1, at);\n const attributes = new Map<string, string>();\n while (at < lower.length) {\n const char = lower.charAt(at);\n if (char === \">\") return { element: { name, attributes: Object.fromEntries(attributes), start: lt }, end: at + 1 };\n if (char === \"/\" || isSpace(char)) {\n at += 1;\n continue;\n }\n // A name of an attribute ends at white space, \"/\", \">\" or \"=\". A \"=\" at its start is a part of the name.\n const from = at;\n at += 1;\n while (!endsName(lower.charAt(at)) && lower.charAt(at) !== \"=\") at += 1;\n const key = lower.slice(from, at);\n let value = \"\";\n let next = at;\n while (isSpace(lower.charAt(next))) next += 1;\n if (lower.charAt(next) === \"=\") {\n next += 1;\n while (isSpace(lower.charAt(next))) next += 1;\n const quote = lower.charAt(next);\n if (quote === '\"' || quote === \"'\") {\n const close = lower.indexOf(quote, next + 1);\n if (close === -1) return undefined;\n value = html.slice(next + 1, close);\n at = close + 1;\n } else {\n at = next;\n while (at < lower.length && lower.charAt(at) !== \">\" && !isSpace(lower.charAt(at))) at += 1;\n value = html.slice(next, at);\n }\n }\n if (!attributes.has(key)) attributes.set(key, value);\n }\n return undefined;\n}\n\n/**\n * This function gives the start and the end of the end tag of `name` at or after `from`, or undefined. The name of the end\n * tag ends at white space, \"/\" or \">\", and the tag ends at the next \">\".\n */\nfunction endTagOf(lower: string, name: string, from: number, search: Search): { start: number; end: number } | undefined {\n const needle = `</${name}`;\n for (let start = search(needle, from); start !== -1; start = search(needle, start + 1)) {\n if (!endsName(lower.charAt(start + needle.length)) || lower.charAt(start + needle.length) === \"\") continue;\n const gt = search(\">\", start + needle.length);\n return gt === -1 ? undefined : { start, end: gt + 1 };\n }\n return undefined;\n}\n\n/**\n * This function scans HTML for its text and its start tags, from the left to the right, in one pass.\n *\n * - A comment, a tag, a doctype and a processing instruction give no text. Each gives one space.\n * - The content of an element of `skip`, to its end tag, gives no text and no element.\n * - The content of a script, a style, a title or a text area that the scan does not skip is text with no tags.\n * - A \"<\" starts a tag only before a letter, \"/\", \"!\" or \"?\", as in HTML. Each other \"<\" is text, as in `1 < 2`.\n * - A comment or a skipped element with no end is text, and the scan continues in it. A tag with no \">\" ends the scan,\n * and the rest of the HTML is text.\n *\n * @param html - The HTML, a document or a part of one.\n * @param options - The elements to skip. The default is `HTML_SKIP`.\n * @returns The text and the start tags.\n */\nexport function scanHtml(html: string, options: HtmlScanOptions = {}): HtmlScan {\n const skip = new Set((options.skip ?? HTML_SKIP).map((name) => name.toLowerCase()));\n // Only A to Z go to lower case, so each index of the copy is an index of the HTML.\n const lower = html.replace(/[A-Z]+/g, (upper) => upper.toLowerCase());\n const search = searchIn(lower);\n const unclosed = new Set<string>();\n const parts: string[] = [];\n const elements: HtmlElement[] = [];\n let at = 0;\n for (let lt = search(\"<\", 0); lt !== -1; lt = search(\"<\", Math.max(at, lt + 1))) {\n const next = lower.charAt(lt + 1);\n let end: number;\n if (lower.startsWith(\"<!--\", lt)) {\n // A comment can end at once: `<!-->` and `<!--->` are comments.\n const close = search(\"-->\", lt + 2);\n if (close === -1) continue;\n end = close + 3;\n } else if (next === \"/\" || next === \"!\" || next === \"?\") {\n const gt = search(\">\", lt + 2);\n if (gt === -1) break;\n end = gt + 1;\n } else if (next >= \"a\" && next <= \"z\") {\n const tag = readTag(html, lower, lt);\n if (tag === undefined) break;\n elements.push(tag.element);\n end = tag.end;\n const { name } = tag.element;\n const skipped = skip.has(name);\n if ((skipped || RAW_TEXT.includes(name)) && !unclosed.has(name)) {\n const close = endTagOf(lower, name, end, search);\n if (close === undefined) unclosed.add(name);\n else {\n parts.push(html.slice(at, lt), \" \");\n if (!skipped) parts.push(html.slice(end, close.start), \" \");\n at = close.end;\n continue;\n }\n }\n } else continue;\n parts.push(html.slice(at, lt), \" \");\n at = end;\n }\n parts.push(html.slice(at));\n return { text: parts.join(\"\"), elements };\n}\n"],"mappings":";;AAsCA,MAAa,YAA+B,OAAO,OAAO;CAAC;CAAU;CAAS;AAAU,CAAC;;;;;AAMzF,MAAM,WAA8B;CAAC;CAAU;CAAS;CAAS;CAAY;CAAO;CAAU;CAAW;AAAU;;AAGnH,MAAM,WAAW,SAA0B,SAAS,OAAO,SAAS,OAAQ,SAAS,QAAQ,SAAS,QAAQ,SAAS;;AAGvH,MAAM,YAAY,SAA0B,SAAS,MAAM,SAAS,OAAO,SAAS,OAAO,QAAQ,I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IAAI,KAAK,CAAC,CAAC,GAAG;EAC/E,MAAM,OAAO,MAAM,OAAO,KAAK,CAAC;EAChC,IAAI;EACJ,IAAI,MAAM,WAAW,QAAQ,EAAE,GAAG;GAEhC,MAAM,QAAQ,OAAO,OAAO,KAAK,CAAC;GAClC,IAAI,UAAU,IAAI;GAClB,MAAM,QAAQ;EAChB,OAAO,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAAK;GACvD,MAAM,KAAK,OAAO,KAAK,KAAK,CAAC;GAC7B,IAAI,OAAO,IAAI;GACf,MAAM,KAAK;EACb,OAAO,IAAI,QAAQ,OAAO,QAAQ,KAAK;GACrC,MAAM,MAAM,QAAQ,MAAM,OAAO,EAAE;GACnC,IAAI,QAAQ,KAAA,GAAW;GACvB,SAAS,KAAK,IAAI,OAAO;GACzB,MAAM,IAAI;GACV,MAAM,EAAE,SAAS,IAAI;GACrB,MAAM,UAAU,KAAK,IAAI,IAAI;GAC7B,KAAK,WAAW,SAAS,SAAS,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,GAAG;IAC/D,MAAM,QAAQ,SAAS,OAAO,MAAM,KAAK,MAAM;IAC/C,IAAI,UAAU,KAAA,GAAW,SAAS,IAAI,IAAI;SACrC;KACH,MAAM,KAAK,KAAK,MAAM,IAAI,EAAE,GAAG,GAAG;KAClC,IAAI,CAAC,SAAS,MAAM,KAAK,KAAK,MAAM,KAAK,MAAM,KAAK,GAAG,GAAG;KAC1D,KAAK,MAAM;KACX;IACF;GACF;EACF,OAAO;EACP,MAAM,KAAK,KAAK,MAAM,IAAI,EAAE,GAAG,GAAG;EAClC,KAAK;CACP;CACA,MAAM,KAAK,KAAK,MAAM,EAAE,CAAC;CACzB,OAAO;EAAE,MAAM,MAAM,KAAK,EAAE;EAAG;CAAS;AAC1C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function decodes the character references of a text, as the tokenizer of the HTML Living Standard does in the
|
|
3
|
+
* content of an element. Use it on the `text` of a scan of `scanHtml`.
|
|
4
|
+
*
|
|
5
|
+
* - A named reference gets its value from the table of the standard. The longest name wins.
|
|
6
|
+
* - A legacy name, for example `&` or `¬`, is also correct with no semicolon. Thus `¬it;` gives `¬it;`.
|
|
7
|
+
* - A decimal or hexadecimal reference, for example `’` or `’`, gives its code point. The semicolon is optional.
|
|
8
|
+
* - The value 0, a surrogate and a value above `0x10FFFF` give U+FFFD.
|
|
9
|
+
* - The values `0x80` to `0x9F` give the characters of windows-1252, from the table of the standard.
|
|
10
|
+
* - An ampersand with no reference after it stays as text. The function changes no other character.
|
|
11
|
+
*
|
|
12
|
+
* The function does not throw, and it is linear in the length of the text. The result is not longer than the text.
|
|
13
|
+
*
|
|
14
|
+
* @param text - The text of HTML content, with its character references.
|
|
15
|
+
* @returns The text with the value of each character reference in place of the reference.
|
|
16
|
+
*/
|
|
17
|
+
export declare function decodeReferences(text: string): string;
|
|
18
|
+
//# sourceMappingURL=references.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"references.d.ts","names":[],"sources":["../src/references.ts"],"mappings":";;;;;;;;;;;;;;;;wBA2HgB,iBAAiB"}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// src/html-references.ts
|
|
2
|
+
/**
|
|
3
|
+
* This module has the named character references of HTML. The script `scripts/html-references.ts` made it. Do not
|
|
4
|
+
* edit it. Start the script again to make it.
|
|
5
|
+
*
|
|
6
|
+
* The source is the table of the HTML Living Standard, `https://html.spec.whatwg.org/entities.json`. Copyright WHATWG
|
|
7
|
+
* (Apple, Google, Mozilla, Microsoft). The table has the license CC BY 4.0,
|
|
8
|
+
* `https://creativecommons.org/licenses/by/4.0/`. The SHA-256 of the source file is
|
|
9
|
+
* `d741d877ac77c4194c4ad526b5b4a19aef8dfe411ab840a466891cdbb9f362e6`.
|
|
10
|
+
*
|
|
11
|
+
* The script changed the format of the table, not its content. The source has 2231 names. 106 of them are
|
|
12
|
+
* legacy names, which are in the source with a semicolon and with no semicolon.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The names and the values of the named character references. The names with one value make one group. A comma or a
|
|
16
|
+
* line end comes between two groups. Each group has these parts:
|
|
17
|
+
*
|
|
18
|
+
* - the first code point of the value, as the difference from the first code point of the group before it,
|
|
19
|
+
* - a plus sign and the second code point, only for a value with two code points,
|
|
20
|
+
* - an equals sign and the names of the group, with a space between two names.
|
|
21
|
+
*
|
|
22
|
+
* Each number is in base 36. A name has no ampersand and no semicolon. A star after a name tells that the name is also
|
|
23
|
+
* correct with no semicolon. The groups are in the order of their values. The longest name has 31 characters, and the
|
|
24
|
+
* longest legacy name has 6 characters.
|
|
25
|
+
*/
|
|
26
|
+
const NAMED_REFERENCES = `9=Tab,1=NewLine,n=excl,1=QUOT* quot*,1=num,1=dollar,1=percnt,1=AMP* amp*,1=apos,1=lpar,1=rpar,1=ast midast,1=plus
|
|
27
|
+
1=comma,2=period,1=sol,b=colon,1=semi,1=LT* lt*,0+6he=nvlt,1=equals,0+6hx=bne,1=GT* gt*,0+6he=nvgt,1=quest,1=commat
|
|
28
|
+
r=lbrack lsqb,1=bsol,1=rbrack rsqb,1=Hat,1=UnderBar lowbar,1=DiacriticalGrave grave,6+2y=fjlig,l=lbrace lcub
|
|
29
|
+
1=VerticalLine verbar vert,1=rbrace rcub,z=NonBreakingSpace nbsp*,1=iexcl*,1=cent*,1=pound*,1=curren*,1=yen*
|
|
30
|
+
1=brvbar*,1=sect*,1=Dot DoubleDot die uml*,1=COPY* copy*,1=ordf*,1=laquo*,1=not*,1=shy*,1=REG* circledR reg*
|
|
31
|
+
1=macr* strns,1=deg*,1=PlusMinus plusmn* pm,1=sup2*,1=sup3*,1=DiacriticalAcute acute*,1=micro*,1=para*
|
|
32
|
+
1=CenterDot centerdot middot*,1=Cedilla cedil*,1=sup1*,1=ordm*,1=raquo*,1=frac14*,1=frac12* half,1=frac34*,1=iquest*
|
|
33
|
+
1=Agrave*,1=Aacute*,1=Acirc*,1=Atilde*,1=Auml*,1=Aring* angst,1=AElig*,1=Ccedil*,1=Egrave*,1=Eacute*,1=Ecirc*
|
|
34
|
+
1=Euml*,1=Igrave*,1=Iacute*,1=Icirc*,1=Iuml*,1=ETH*,1=Ntilde*,1=Ograve*,1=Oacute*,1=Ocirc*,1=Otilde*,1=Ouml*
|
|
35
|
+
1=times*,1=Oslash*,1=Ugrave*,1=Uacute*,1=Ucirc*,1=Uuml*,1=Yacute*,1=THORN*,1=szlig*,1=agrave*,1=aacute*,1=acirc*
|
|
36
|
+
1=atilde*,1=auml*,1=aring*,1=aelig*,1=ccedil*,1=egrave*,1=eacute*,1=ecirc*,1=euml*,1=igrave*,1=iacute*,1=icirc*
|
|
37
|
+
1=iuml*,1=eth*,1=ntilde*,1=ograve*,1=oacute*,1=ocirc*,1=otilde*,1=ouml*,1=div divide*,1=oslash*,1=ugrave*,1=uacute*
|
|
38
|
+
1=ucirc*,1=uuml*,1=yacute*,1=thorn*,1=yuml*,1=Amacr,1=amacr,1=Abreve,1=abreve,1=Aogon,1=aogon,1=Cacute,1=cacute
|
|
39
|
+
1=Ccirc,1=ccirc,1=Cdot,1=cdot,1=Ccaron,1=ccaron,1=Dcaron,1=dcaron,1=Dstrok,1=dstrok,1=Emacr,1=emacr,3=Edot,1=edot
|
|
40
|
+
1=Eogon,1=eogon,1=Ecaron,1=ecaron,1=Gcirc,1=gcirc,1=Gbreve,1=gbreve,1=Gdot,1=gdot,1=Gcedil,2=Hcirc,1=hcirc,1=Hstrok
|
|
41
|
+
1=hstrok,1=Itilde,1=itilde,1=Imacr,1=imacr,3=Iogon,1=iogon,1=Idot,1=imath inodot,1=IJlig,1=ijlig,1=Jcirc,1=jcirc
|
|
42
|
+
1=Kcedil,1=kcedil,1=kgreen,1=Lacute,1=lacute,1=Lcedil,1=lcedil,1=Lcaron,1=lcaron,1=Lmidot,1=lmidot,1=Lstrok,1=lstrok
|
|
43
|
+
1=Nacute,1=nacute,1=Ncedil,1=ncedil,1=Ncaron,1=ncaron,1=napos,1=ENG,1=eng,1=Omacr,1=omacr,3=Odblac,1=odblac,1=OElig
|
|
44
|
+
1=oelig,1=Racute,1=racute,1=Rcedil,1=rcedil,1=Rcaron,1=rcaron,1=Sacute,1=sacute,1=Scirc,1=scirc,1=Scedil,1=scedil
|
|
45
|
+
1=Scaron,1=scaron,1=Tcedil,1=tcedil,1=Tcaron,1=tcaron,1=Tstrok,1=tstrok,1=Utilde,1=utilde,1=Umacr,1=umacr,1=Ubreve
|
|
46
|
+
1=ubreve,1=Uring,1=uring,1=Udblac,1=udblac,1=Uogon,1=uogon,1=Wcirc,1=wcirc,1=Ycirc,1=ycirc,1=Yuml,1=Zacute,1=zacute
|
|
47
|
+
1=Zdot,1=zdot,1=Zcaron,1=zcaron,k=fnof,z=imped,1s=gacute,1u=jmath,3z=circ,1=Hacek caron,h=Breve breve
|
|
48
|
+
1=DiacriticalDot dot,1=ring,1=ogon,1=DiacriticalTilde tilde,1=DiacriticalDoubleAcute dblac,1g=DownBreve,3k=Alpha
|
|
49
|
+
1=Beta,1=Gamma,1=Delta,1=Epsilon,1=Zeta,1=Eta,1=Theta,1=Iota,1=Kappa,1=Lambda,1=Mu,1=Nu,1=Xi,1=Omicron,1=Pi,1=Rho
|
|
50
|
+
2=Sigma,1=Tau,1=Upsilon,1=Phi,1=Chi,1=Psi,1=Omega ohm,8=alpha,1=beta,1=gamma,1=delta,1=epsi epsilon,1=zeta,1=eta
|
|
51
|
+
1=theta,1=iota,1=kappa,1=lambda,1=mu,1=nu,1=xi,1=omicron,1=pi,1=rho,1=sigmaf sigmav varsigma,1=sigma,1=tau
|
|
52
|
+
1=upsi upsilon,1=phi,1=chi,1=psi,1=omega,8=thetasym thetav vartheta,1=Upsi upsih,3=phiv straightphi varphi
|
|
53
|
+
1=piv varpi,6=Gammad,1=digamma gammad,j=kappav varkappa,1=rhov varrho,4=epsiv straightepsilon varepsilon
|
|
54
|
+
1=backepsilon bepsi,b=IOcy,1=DJcy,1=GJcy,1=Jukcy,1=DScy,1=Iukcy,1=YIcy,1=Jsercy,1=LJcy,1=NJcy,1=TSHcy,1=KJcy,2=Ubrcy
|
|
55
|
+
1=DZcy,1=Acy,1=Bcy,1=Vcy,1=Gcy,1=Dcy,1=IEcy,1=ZHcy,1=Zcy,1=Icy,1=Jcy,1=Kcy,1=Lcy,1=Mcy,1=Ncy,1=Ocy,1=Pcy,1=Rcy,1=Scy
|
|
56
|
+
1=Tcy,1=Ucy,1=Fcy,1=KHcy,1=TScy,1=CHcy,1=SHcy,1=SHCHcy,1=HARDcy,1=Ycy,1=SOFTcy,1=Ecy,1=YUcy,1=YAcy,1=acy,1=bcy,1=vcy
|
|
57
|
+
1=gcy,1=dcy,1=iecy,1=zhcy,1=zcy,1=icy,1=jcy,1=kcy,1=lcy,1=mcy,1=ncy,1=ocy,1=pcy,1=rcy,1=scy,1=tcy,1=ucy,1=fcy,1=khcy
|
|
58
|
+
1=tscy,1=chcy,1=shcy,1=shchcy,1=hardcy,1=ycy,1=softcy,1=ecy,1=yucy,1=yacy,2=iocy,1=djcy,1=gjcy,1=jukcy,1=dscy
|
|
59
|
+
1=iukcy,1=yicy,1=jsercy,1=ljcy,1=njcy,1=tshcy,1=kjcy,2=ubrcy,1=dzcy,5gj=ensp,1=emsp,1=emsp13,1=emsp14,2=numsp
|
|
60
|
+
1=puncsp,1=ThinSpace thinsp,1=VeryThinSpace hairsp
|
|
61
|
+
1=NegativeMediumSpace NegativeThickSpace NegativeThinSpace NegativeVeryThinSpace ZeroWidthSpace,1=zwnj,1=zwj,1=lrm
|
|
62
|
+
1=rlm,1=dash hyphen,3=ndash,1=mdash,1=horbar,1=Verbar Vert,2=OpenCurlyQuote lsquo,1=CloseCurlyQuote rsquo rsquor
|
|
63
|
+
1=lsquor sbquo,2=OpenCurlyDoubleQuote ldquo,1=CloseCurlyDoubleQuote rdquo rdquor,1=bdquo ldquor,2=dagger
|
|
64
|
+
1=Dagger ddagger,1=bull bullet,3=nldr,1=hellip mldr,a=permil,1=pertenk,1=prime,1=Prime,1=tprime,1=backprime bprime
|
|
65
|
+
4=lsaquo,1=rsaquo,4=OverBar oline,3=caret,2=hybull,1=frasl,b=bsemi,8=qprime,8=MediumSpace,0+6bu=ThickSpace,1=NoBreak
|
|
66
|
+
1=ApplyFunction af,1=InvisibleTimes it,1=InvisibleComma ic,21=euro,1b=TripleDot tdot,1=DotDot,12=Copf complexes
|
|
67
|
+
3=incare,5=gscr,1=HilbertSpace Hscr hamilt,1=Hfr Poincareplane,1=Hopf quaternions,1=planckh
|
|
68
|
+
1=hbar hslash planck plankv,1=Iscr imagline,1=Ifr Im image imagpart,1=Laplacetrf Lscr lagran,1=ell,2=Nopf naturals
|
|
69
|
+
1=numero,1=copysr,1=weierp wp,1=Popf primes,1=Qopf rationals,1=Rscr realine,1=Re Rfr real realpart,1=Ropf reals,1=rx
|
|
70
|
+
4=TRADE trade,2=Zopf integers,3=mho,1=Zfr zeetrf,1=iiota,3=Bernoullis Bscr bernou,1=Cayleys Cfr,2=escr
|
|
71
|
+
1=Escr expectation,1=Fouriertrf Fscr,2=Mellintrf Mscr phmmat,1=order orderof oscr,1=alefsym aleph,1=beth,1=gimel
|
|
72
|
+
1=daleth,d=CapitalDifferentialD DD,1=DifferentialD dd,1=ExponentialE ee exponentiale,1=ImaginaryI ii,b=frac13
|
|
73
|
+
1=frac23,1=frac15,1=frac25,1=frac35,1=frac45,1=frac16,1=frac56,1=frac18,1=frac38,1=frac58,1=frac78
|
|
74
|
+
1e=LeftArrow ShortLeftArrow larr leftarrow slarr,1=ShortUpArrow UpArrow uarr uparrow
|
|
75
|
+
1=RightArrow ShortRightArrow rarr rightarrow srarr,1=DownArrow ShortDownArrow darr downarrow
|
|
76
|
+
1=LeftRightArrow harr leftrightarrow,1=UpDownArrow updownarrow varr,1=UpperLeftArrow nwarr nwarrow
|
|
77
|
+
1=UpperRightArrow nearr nearrow,1=LowerRightArrow searr searrow,1=LowerLeftArrow swarr swarrow,1=nlarr nleftarrow
|
|
78
|
+
1=nrarr nrightarrow,2=rarrw rightsquigarrow,0+mw=nrarrw,1=Larr twoheadleftarrow,1=Uarr,1=Rarr twoheadrightarrow
|
|
79
|
+
1=Darr,1=larrtl leftarrowtail,1=rarrtl rightarrowtail,1=LeftTeeArrow mapstoleft,1=UpTeeArrow mapstoup
|
|
80
|
+
1=RightTeeArrow map mapsto,1=DownTeeArrow mapstodown,2=hookleftarrow larrhk,1=hookrightarrow rarrhk
|
|
81
|
+
1=larrlp looparrowleft,1=looparrowright rarrlp,1=harrw leftrightsquigarrow,1=nharr nleftrightarrow,2=Lsh lsh
|
|
82
|
+
1=Rsh rsh,1=ldsh,1=rdsh,2=crarr,1=cularr curvearrowleft,1=curarr curvearrowright,3=circlearrowleft olarr
|
|
83
|
+
1=circlearrowright orarr,1=LeftVector leftharpoonup lharu,1=DownLeftVector leftharpoondown lhard
|
|
84
|
+
1=RightUpVector uharr upharpoonright,1=LeftUpVector uharl upharpoonleft,1=RightVector rharu rightharpoonup
|
|
85
|
+
1=DownRightVector rhard rightharpoondown,1=RightDownVector dharr downharpoonright
|
|
86
|
+
1=LeftDownVector dharl downharpoonleft,1=RightArrowLeftArrow rightleftarrows rlarr,1=UpArrowDownArrow udarr
|
|
87
|
+
1=LeftArrowRightArrow leftrightarrows lrarr,1=leftleftarrows llarr,1=upuparrows uuarr,1=rightrightarrows rrarr
|
|
88
|
+
1=ddarr downdownarrows,1=ReverseEquilibrium leftrightharpoons lrhar,1=Equilibrium rightleftharpoons rlhar
|
|
89
|
+
1=nLeftarrow nlArr,1=nLeftrightarrow nhArr,1=nRightarrow nrArr,1=DoubleLeftArrow Leftarrow lArr
|
|
90
|
+
1=DoubleUpArrow Uparrow uArr,1=DoubleRightArrow Implies Rightarrow rArr,1=DoubleDownArrow Downarrow dArr
|
|
91
|
+
1=DoubleLeftRightArrow Leftrightarrow hArr iff,1=DoubleUpDownArrow Updownarrow vArr,1=nwArr,1=neArr,1=seArr,1=swArr
|
|
92
|
+
1=Lleftarrow lAarr,1=Rrightarrow rAarr,2=zigrarr,7=LeftArrowBar larrb,1=RightArrowBar rarrb,g=DownArrowUpArrow duarr
|
|
93
|
+
8=loarr,1=roarr,1=hoarr,1=ForAll forall,1=comp complement,1=PartialD part,0+mw=npart,1=Exists exist
|
|
94
|
+
1=NotExists nexist nexists,1=empty emptyset emptyv varnothing,2=Del nabla,1=Element in isin isinv
|
|
95
|
+
1=NotElement notin notinva,2=ReverseElement SuchThat ni niv,1=NotReverseElement notni notniva,3=Product prod
|
|
96
|
+
1=Coproduct coprod,1=Sum sum,1=minus,1=MinusPlus mnplus mp,1=dotplus plusdo
|
|
97
|
+
2=Backslash setminus setmn smallsetminus ssetmn,1=lowast,1=SmallCircle compfn,2=Sqrt radic
|
|
98
|
+
3=Proportional prop propto varpropto vprop,1=infin,1=angrt,1=ang angle,0+6he=nang,1=angmsd measuredangle,1=angsph
|
|
99
|
+
1=VerticalBar mid shortmid smid,1=NotVerticalBar nmid nshortmid nsmid
|
|
100
|
+
1=DoubleVerticalBar par parallel shortparallel spar,1=NotDoubleVerticalBar npar nparallel nshortparallel nspar
|
|
101
|
+
1=and wedge,1=or vee,1=cap,0+1e68=caps,1=cup,0+1e68=cups,1=Integral int,1=Int,1=iiint tint
|
|
102
|
+
1=ContourIntegral conint oint,1=Conint DoubleContourIntegral,1=Cconint,1=cwint,1=ClockwiseContourIntegral cwconint
|
|
103
|
+
1=CounterClockwiseContourIntegral awconint,1=Therefore there4 therefore,1=Because becaus because,1=ratio
|
|
104
|
+
1=Colon Proportion,1=dotminus minusd,2=mDDot,1=homtht,1=Tilde sim thicksim thksim,0+6he=nvsim,1=backsim bsim
|
|
105
|
+
0+mp=race,1=ac mstpos,0+mr=acE,1=acd,1=VerticalTilde wr wreath,1=NotTilde nsim,1=EqualTilde eqsim esim
|
|
106
|
+
0+mw=NotEqualTilde nesim,1=TildeEqual sime simeq,1=NotTildeEqual nsime nsimeq,1=TildeFullEqual cong,1=simne
|
|
107
|
+
1=NotTildeFullEqual ncong,1=TildeTilde ap approx asymp thickapprox thkap,1=NotTildeTilde nap napprox,1=ape approxeq
|
|
108
|
+
1=apid,0+mw=napid,1=backcong bcong,1=CupCap asympeq,0+6he=nvap,1=Bumpeq HumpDownHump bump,0+mw=NotHumpDownHump nbump
|
|
109
|
+
1=HumpEqual bumpe bumpeq,0+mw=NotHumpEqual nbumpe,1=DotEqual doteq esdot,0+mw=nedot,1=doteqdot eDot
|
|
110
|
+
1=efDot fallingdotseq,1=erDot risingdotseq,1=Assign colone coloneq,1=ecolon eqcolon,1=ecir eqcirc,1=circeq cire
|
|
111
|
+
2=wedgeq,1=veeeq,2=triangleq trie,3=equest questeq,1=NotEqual ne,1=Congruent equiv,0+6hx=bnequiv
|
|
112
|
+
1=NotCongruent nequiv,2=le leq,0+6he=nvle,1=GreaterEqual ge geq,0+6he=nvge,1=LessFullEqual lE leqq,0+mw=nlE nleqq
|
|
113
|
+
1=GreaterFullEqual gE geqq,0+mw=NotGreaterFullEqual ngE ngeqq,1=lnE lneqq,0+1e68=lvertneqq lvnE,1=gnE gneqq
|
|
114
|
+
0+1e68=gvertneqq gvnE,1=Lt NestedLessLess ll,0+mw=NotLessLess nLtv,0+6he=nLt,1=Gt NestedGreaterGreater gg
|
|
115
|
+
0+mw=NotGreaterGreater nGtv,0+6he=nGt,1=between twixt,1=NotCupCap,1=NotLess nless nlt,1=NotGreater ngt ngtr
|
|
116
|
+
1=NotLessEqual nle nleq,1=NotGreaterEqual nge ngeq,1=LessTilde lesssim lsim,1=GreaterTilde gsim gtrsim
|
|
117
|
+
1=NotLessTilde nlsim,1=NotGreaterTilde ngsim,1=LessGreater lessgtr lg,1=GreaterLess gl gtrless,1=NotLessGreater ntlg
|
|
118
|
+
1=NotGreaterLess ntgl,1=Precedes pr prec,1=Succeeds sc succ,1=PrecedesSlantEqual prcue preccurlyeq
|
|
119
|
+
1=SucceedsSlantEqual sccue succcurlyeq,1=PrecedesTilde precsim prsim,1=SucceedsTilde scsim succsim
|
|
120
|
+
0+mw=NotSucceedsTilde,1=NotPrecedes npr nprec,1=NotSucceeds nsc nsucc,1=sub subset,0+6he=NotSubset nsubset vnsub
|
|
121
|
+
1=Superset sup supset,0+6he=NotSuperset nsupset vnsup,1=nsub,1=nsup,1=SubsetEqual sube subseteq
|
|
122
|
+
1=SupersetEqual supe supseteq,1=NotSubsetEqual nsube nsubseteq,1=NotSupersetEqual nsupe nsupseteq,1=subne subsetneq
|
|
123
|
+
0+1e68=varsubsetneq vsubne,1=supne supsetneq,0+1e68=varsupsetneq vsupne,2=cupdot,1=UnionPlus uplus
|
|
124
|
+
1=SquareSubset sqsub sqsubset,0+mw=NotSquareSubset,1=SquareSuperset sqsup sqsupset,0+mw=NotSquareSuperset
|
|
125
|
+
1=SquareSubsetEqual sqsube sqsubseteq,1=SquareSupersetEqual sqsupe sqsupseteq,1=SquareIntersection sqcap
|
|
126
|
+
0+1e68=sqcaps,1=SquareUnion sqcup,0+1e68=sqcups,1=CirclePlus oplus,1=CircleMinus ominus,1=CircleTimes otimes,1=osol
|
|
127
|
+
1=CircleDot odot,1=circledcirc ocir,1=circledast oast,2=circleddash odash,1=boxplus plusb,1=boxminus minusb
|
|
128
|
+
1=boxtimes timesb,1=dotsquare sdotb,1=RightTee vdash,1=LeftTee dashv,1=DownTee top,1=UpTee bot bottom perp,2=models
|
|
129
|
+
1=DoubleRightTee vDash,1=Vdash,1=Vvdash,1=VDash,1=nvdash,1=nvDash,1=nVdash,1=nVDash,1=prurel
|
|
130
|
+
2=LeftTriangle vartriangleleft vltri,1=RightTriangle vartriangleright vrtri,1=LeftTriangleEqual ltrie trianglelefteq
|
|
131
|
+
0+6he=nvltrie,1=RightTriangleEqual rtrie trianglerighteq,0+6he=nvrtrie,1=origof,1=imof,1=multimap mumap,1=hercon
|
|
132
|
+
1=intcal intercal,1=veebar,2=barvee,1=angrtvb,1=lrtri,1=Wedge bigwedge xwedge,1=Vee bigvee xvee
|
|
133
|
+
1=Intersection bigcap xcap,1=Union bigcup xcup,1=Diamond diam diamond,1=sdot,1=Star sstarf,1=divideontimes divonx
|
|
134
|
+
1=bowtie,1=ltimes,1=rtimes,1=leftthreetimes lthree,1=rightthreetimes rthree,1=backsimeq bsime,1=curlyvee cuvee
|
|
135
|
+
1=curlywedge cuwed,1=Sub Subset,1=Sup Supset,1=Cap,1=Cup,1=fork pitchfork,1=epar,1=lessdot ltdot,1=gtdot gtrdot,1=Ll
|
|
136
|
+
0+mw=nLl,1=Gg ggg,0+mw=nGg,1=LessEqualGreater leg lesseqgtr,0+1e68=lesg,1=GreaterEqualLess gel gtreqless,0+1e68=gesl
|
|
137
|
+
3=cuepr curlyeqprec,1=cuesc curlyeqsucc,1=NotPrecedesSlantEqual nprcue,1=NotSucceedsSlantEqual nsccue
|
|
138
|
+
1=NotSquareSubsetEqual nsqsube,1=NotSquareSupersetEqual nsqsupe,3=lnsim,1=gnsim,1=precnsim prnsim,1=scnsim succnsim
|
|
139
|
+
1=NotLeftTriangle nltri ntriangleleft,1=NotRightTriangle nrtri ntriangleright
|
|
140
|
+
1=NotLeftTriangleEqual nltrie ntrianglelefteq,1=NotRightTriangleEqual nrtrie ntrianglerighteq,1=vellip,1=ctdot
|
|
141
|
+
1=utdot,1=dtdot,1=disin,1=isinsv,1=isins,1=isindot,0+mw=notindot,1=notinvc,1=notinvb,2=isinE,0+mw=notinE,1=nisd
|
|
142
|
+
1=xnis,1=nis,1=notnivc,1=notnivb,7=barwed barwedge,1=Barwed doublebarwedge,2=LeftCeiling lceil,1=RightCeiling rceil
|
|
143
|
+
1=LeftFloor lfloor,1=RightFloor rfloor,1=drcrop,1=dlcrop,1=urcrop,1=ulcrop,1=bnot,2=profline,1=profsurf,2=telrec
|
|
144
|
+
1=target,6=ulcorn ulcorner,1=urcorn urcorner,1=dlcorn llcorner,1=drcorn lrcorner,3=frown sfrown,1=smile ssmile
|
|
145
|
+
a=cylcty,1=profalar,8=topbot,7=ovbar,2=solbar,1p=angzarr,1g=lmoust lmoustache,1=rmoust rmoustache,3=OverBracket tbrk
|
|
146
|
+
1=UnderBracket bbrk,1=bbrktbrk,12=OverParenthesis,1=UnderParenthesis,1=OverBrace,1=UnderBrace,3=trpezium,5=elinters
|
|
147
|
+
1o=blank,4l=circledS oS,1k=HorizontalLine boxh,2=boxv,a=boxdr,4=boxdl,4=boxur,4=boxul,4=boxvr,8=boxvl,8=boxhd
|
|
148
|
+
8=boxhu,8=boxvh,k=boxH,1=boxV,1=boxdR,1=boxDr,1=boxDR,1=boxdL,1=boxDl,1=boxDL,1=boxuR,1=boxUr,1=boxUR,1=boxuL
|
|
149
|
+
1=boxUl,1=boxUL,1=boxvR,1=boxVr,1=boxVR,1=boxvL,1=boxVl,1=boxVL,1=boxHd,1=boxhD,1=boxHD,1=boxHu,1=boxhU,1=boxHU
|
|
150
|
+
1=boxvH,1=boxVh,1=boxVH,k=uhblk,4=lhblk,4=block,9=blk14,1=blk12,1=blk34,e=Square squ square
|
|
151
|
+
9=FilledVerySmallSquare blacksquare squarf squf,1=EmptyVerySmallSquare,2=rect,1=marker,3=fltns,2=bigtriangleup xutri
|
|
152
|
+
1=blacktriangle utrif,1=triangle utri,3=blacktriangleright rtrif,1=rtri triangleright,4=bigtriangledown xdtri
|
|
153
|
+
1=blacktriangledown dtrif,1=dtri triangledown,3=blacktriangleleft ltrif,1=ltri triangleleft,7=loz lozenge,1=cir
|
|
154
|
+
x=tridot,3=bigcirc xcirc,9=ultri,1=urtri,1=lltri,1=EmptySmallSquare,1=FilledSmallSquare,9=bigstar starf,1=star
|
|
155
|
+
8=phone,1e=female,2=male,u=spades spadesuit,3=clubs clubsuit,2=hearts heartsuit,1=diamondsuit diams,4=sung,3=flat
|
|
156
|
+
1=natur natural,1=sharp,4k=check checkmark,4=cross,9=malt maltese,m=sext,y=VerticalSeparator,q=lbbrk,1=rbbrk
|
|
157
|
+
2d=bsolhsub,1=suphsol,t=LeftDoubleBracket lobrk,1=RightDoubleBracket robrk,1=LeftAngleBracket lang langle
|
|
158
|
+
1=RightAngleBracket rang rangle,1=Lang,1=Rang,1=loang,1=roang,8=LongLeftArrow longleftarrow xlarr
|
|
159
|
+
1=LongRightArrow longrightarrow xrarr,1=LongLeftRightArrow longleftrightarrow xharr
|
|
160
|
+
1=DoubleLongLeftArrow Longleftarrow xlArr,1=DoubleLongRightArrow Longrightarrow xrArr
|
|
161
|
+
1=DoubleLongLeftRightArrow Longleftrightarrow xhArr,2=longmapsto xmap,3=dzigrarr,77=nvlArr,1=nvrArr,1=nvHarr,1=Map
|
|
162
|
+
7=lbarr,1=bkarow rbarr,1=lBarr,1=dbkarow rBarr,1=RBarr drbkarow,1=DDotrahd,1=UpArrowBar,1=DownArrowBar,3=Rarrtl
|
|
163
|
+
3=latail,1=ratail,1=lAtail,1=rAtail,1=larrfs,1=rarrfs,1=larrbfs,1=rarrbfs,3=nwarhk,1=nearhk,1=hksearow searhk
|
|
164
|
+
1=hkswarow swarhk,1=nwnear,1=nesear toea,1=seswar tosa,1=swnwar,9=rarrc,0+mw=nrarrc,2=cudarrr,1=ldca,1=rdca
|
|
165
|
+
1=cudarrl,1=larrpl,3=curarrm,1=cularrp,8=rarrpl,3=harrcir,1=Uarrocir,1=lurdshar,1=ldrushar,3=LeftRightVector
|
|
166
|
+
1=RightUpDownVector,1=DownLeftRightVector,1=LeftUpDownVector,1=LeftVectorBar,1=RightVectorBar,1=RightUpVectorBar
|
|
167
|
+
1=RightDownVectorBar,1=DownLeftVectorBar,1=DownRightVectorBar,1=LeftUpVectorBar,1=LeftDownVectorBar,1=LeftTeeVector
|
|
168
|
+
1=RightTeeVector,1=RightUpTeeVector,1=RightDownTeeVector,1=DownLeftTeeVector,1=DownRightTeeVector,1=LeftUpTeeVector
|
|
169
|
+
1=LeftDownTeeVector,1=lHar,1=uHar,1=rHar,1=dHar,1=luruhar,1=ldrdhar,1=ruluhar,1=rdldhar,1=lharul,1=llhard,1=rharul
|
|
170
|
+
1=lrhard,1=UpEquilibrium udhar,1=ReverseUpEquilibrium duhar,1=RoundImplies,1=erarr,1=simrarr,1=larrsim,1=rarrsim
|
|
171
|
+
1=rarrap,1=ltlarr,2=gtrarr,1=subrarr,2=suplarr,1=lfisht,1=rfisht,1=ufisht,1=dfisht,6=lopar,1=ropar,5=lbrke,1=rbrke
|
|
172
|
+
1=lbrkslu,1=rbrksld,1=lbrksld,1=rbrkslu,1=langd,1=rangd,1=lparlt,1=rpargt,1=gtlPar,1=ltrPar,4=vzigzag,2=vangrt
|
|
173
|
+
1=angrtvbd,7=ange,1=range,1=dwangle,1=uwangle,1=angmsdaa,1=angmsdab,1=angmsdac,1=angmsdad,1=angmsdae,1=angmsdaf
|
|
174
|
+
1=angmsdag,1=angmsdah,1=bemptyv,1=demptyv,1=cemptyv,1=raemptyv,1=laemptyv,1=ohbar,1=omid,1=opar,2=operp,2=olcross
|
|
175
|
+
1=odsold,2=olcir,1=ofcir,1=olt,1=ogt,1=cirscir,1=cirE,1=solb,1=bsolb,4=boxbox,4=trisb,1=rtriltri,1=LeftTriangleBar
|
|
176
|
+
0+mw=NotLeftTriangleBar,1=RightTriangleBar,0+mw=NotRightTriangleBar,c=iinfin,1=infintie,1=nvinfin,5=eparsl
|
|
177
|
+
1=smeparsl,1=eqvparsl,6=blacklozenge lozf,9=RuleDelayed,2=dsol,a=bigodot xodot,1=bigoplus xoplus,1=bigotimes xotime
|
|
178
|
+
2=biguplus xuplus,2=bigsqcup xsqcup,6=iiiint qint,1=fpartint,3=cirfnint,1=awint,1=rppolint,1=scpolint,1=npolint
|
|
179
|
+
1=pointint,1=quatint,1=intlarhk,b=pluscir,1=plusacir,1=simplus,1=plusdu,1=plussim,1=plustwo,2=mcomma,1=minusdu
|
|
180
|
+
3=loplus,1=roplus,1=Cross,1=timesd,1=timesbar,2=smashp,1=lotimes,1=rotimes,1=otimesas,1=Otimes,1=odiv,1=triplus
|
|
181
|
+
1=triminus,1=tritime,1=intprod iprod,3=amalg,1=capdot,2=ncup,1=ncap,1=capand,1=cupor,1=cupcap,1=capcup,1=cupbrcap
|
|
182
|
+
1=capbrcup,1=cupcup,1=capcap,1=ccups,1=ccaps,3=ccupssm,3=And,1=Or,1=andand,1=oror,1=orslope,1=andslope,2=andv,1=orv
|
|
183
|
+
1=andd,1=ord,2=wedbar,7=sdote,4=simdot,3=congdot,0+mw=ncongdot,1=easter,1=apacir,1=apE,0+mw=napE,1=eplus,1=pluse
|
|
184
|
+
1=Esim,1=Colone,1=Equal,2=ddotseq eDDot,1=equivDD,1=ltcir,1=gtcir,1=ltquest,1=gtquest,1=LessSlantEqual leqslant les
|
|
185
|
+
0+mw=NotLessSlantEqual nleqslant nles,1=GreaterSlantEqual geqslant ges,0+mw=NotGreaterSlantEqual ngeqslant nges
|
|
186
|
+
1=lesdot,1=gesdot,1=lesdoto,1=gesdoto,1=lesdotor,1=gesdotol,1=lap lessapprox,1=gap gtrapprox,1=lne lneq,1=gne gneq
|
|
187
|
+
1=lnap lnapprox,1=gnap gnapprox,1=lEg lesseqqgtr,1=gEl gtreqqless,1=lsime,1=gsime,1=lsimg,1=gsiml,1=lgE,1=glE
|
|
188
|
+
1=lesges,1=gesles,1=els eqslantless,1=egs eqslantgtr,1=elsdot,1=egsdot,1=el,1=eg,3=siml,1=simg,1=simlE,1=simgE
|
|
189
|
+
1=LessLess,0+mw=NotNestedLessLess,1=GreaterGreater,0+mw=NotNestedGreaterGreater,2=glj,1=gla,1=ltcc,1=gtcc,1=lescc
|
|
190
|
+
1=gescc,1=smt,1=lat,1=smte,0+1e68=smtes,1=late,0+1e68=lates,1=bumpE,1=PrecedesEqual pre preceq
|
|
191
|
+
0+mw=NotPrecedesEqual npre npreceq,1=SucceedsEqual sce succeq,0+mw=NotSucceedsEqual nsce nsucceq,3=prE,1=scE
|
|
192
|
+
1=precneqq prnE,1=scnE succneqq,1=prap precapprox,1=scap succapprox,1=precnapprox prnap,1=scnap succnapprox,1=Pr
|
|
193
|
+
1=Sc,1=subdot,1=supdot,1=subplus,1=supplus,1=submult,1=supmult,1=subedot,1=supedot,1=subE subseteqq
|
|
194
|
+
0+mw=nsubE nsubseteqq,1=supE supseteqq,0+mw=nsupE nsupseteqq,1=subsim,1=supsim,3=subnE subsetneqq
|
|
195
|
+
0+1e68=varsubsetneqq vsubnE,1=supnE supsetneqq,0+1e68=varsupsetneqq vsupnE,3=csub,1=csup,1=csube,1=csupe,1=subsup
|
|
196
|
+
1=supsub,1=subsub,1=supsup,1=suphsub,1=supdsub,1=forkv,1=topfork,1=mlcp,9=Dashv DoubleLeftTee,2=Vdashl,1=Barv,1=vBar
|
|
197
|
+
1=vBarv,2=Vbar,1=Not,1=bNot,1=rnmid,1=cirmid,1=midcir,1=topcir,1=nhpar,1=parsim,a=parsl,0+6hx=nparsl,1537=fflig
|
|
198
|
+
1=filig,1=fllig,1=ffilig,1=ffllig,16zc=Ascr,2=Cscr,1=Dscr,3=Gscr,3=Jscr,1=Kscr,3=Nscr,1=Oscr,1=Pscr,1=Qscr,2=Sscr
|
|
199
|
+
1=Tscr,1=Uscr,1=Vscr,1=Wscr,1=Xscr,1=Yscr,1=Zscr,1=ascr,1=bscr,1=cscr,1=dscr,2=fscr,2=hscr,1=iscr,1=jscr,1=kscr
|
|
200
|
+
1=lscr,1=mscr,1=nscr,2=pscr,1=qscr,1=rscr,1=sscr,1=tscr,1=uscr,1=vscr,1=wscr,1=xscr,1=yscr,1=zscr,1h=Afr,1=Bfr,2=Dfr
|
|
201
|
+
1=Efr,1=Ffr,1=Gfr,3=Jfr,1=Kfr,1=Lfr,1=Mfr,1=Nfr,1=Ofr,1=Pfr,1=Qfr,2=Sfr,1=Tfr,1=Ufr,1=Vfr,1=Wfr,1=Xfr,1=Yfr,2=afr
|
|
202
|
+
1=bfr,1=cfr,1=dfr,1=efr,1=ffr,1=gfr,1=hfr,1=ifr,1=jfr,1=kfr,1=lfr,1=mfr,1=nfr,1=ofr,1=pfr,1=qfr,1=rfr,1=sfr,1=tfr
|
|
203
|
+
1=ufr,1=vfr,1=wfr,1=xfr,1=yfr,1=zfr,1=Aopf,1=Bopf,2=Dopf,1=Eopf,1=Fopf,1=Gopf,2=Iopf,1=Jopf,1=Kopf,1=Lopf,1=Mopf
|
|
204
|
+
2=Oopf,4=Sopf,1=Topf,1=Uopf,1=Vopf,1=Wopf,1=Xopf,1=Yopf,2=aopf,1=bopf,1=copf,1=dopf,1=eopf,1=fopf,1=gopf,1=hopf
|
|
205
|
+
1=iopf,1=jopf,1=kopf,1=lopf,1=mopf,1=nopf,1=oopf,1=popf,1=qopf,1=ropf,1=sopf,1=topf,1=uopf,1=vopf,1=wopf,1=xopf
|
|
206
|
+
1=yopf,1=zopf`;
|
|
207
|
+
// src/references.ts
|
|
208
|
+
/**
|
|
209
|
+
* This module decodes the character references of HTML content, with no DOM. The table of the named references has
|
|
210
|
+
* 2231 names. It is in a separate entry, so a bundle that only scans HTML does not get the table.
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* The values of the code points 0x80 to 0x9F in a numeric character reference, from the table of the standard. They are
|
|
214
|
+
* the characters of windows-1252. The five code points that windows-1252 does not have stay as they are.
|
|
215
|
+
*/
|
|
216
|
+
const C1_VALUES = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";
|
|
217
|
+
/** The value of each named character reference. A name with `;` is a key, and a legacy name is also a key with no `;`. */
|
|
218
|
+
let named;
|
|
219
|
+
/** The length of the longest name, with no `;`. */
|
|
220
|
+
let longestName = 0;
|
|
221
|
+
/** The length of the longest legacy name. */
|
|
222
|
+
let longestLegacy = 0;
|
|
223
|
+
/** This function reads the table of the named character references one time, when the decoder first needs it. */
|
|
224
|
+
function namedReferences() {
|
|
225
|
+
if (named !== void 0) return named;
|
|
226
|
+
const table = /* @__PURE__ */ new Map();
|
|
227
|
+
let point = 0;
|
|
228
|
+
for (const group of NAMED_REFERENCES.split(/[,\n]/)) {
|
|
229
|
+
const equals = group.indexOf("=");
|
|
230
|
+
const [first = "", second] = group.slice(0, equals).split("+");
|
|
231
|
+
point += parseInt(first, 36);
|
|
232
|
+
const value = second === void 0 ? String.fromCodePoint(point) : String.fromCodePoint(point, parseInt(second, 36));
|
|
233
|
+
for (const entry of group.slice(equals + 1).split(" ")) {
|
|
234
|
+
const legacy = entry.endsWith("*");
|
|
235
|
+
const name = legacy ? entry.slice(0, -1) : entry;
|
|
236
|
+
table.set(`${name};`, value);
|
|
237
|
+
longestName = Math.max(longestName, name.length);
|
|
238
|
+
if (legacy) {
|
|
239
|
+
table.set(name, value);
|
|
240
|
+
longestLegacy = Math.max(longestLegacy, name.length);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
named = table;
|
|
245
|
+
return table;
|
|
246
|
+
}
|
|
247
|
+
/** This function tells if a code unit is an ASCII letter or an ASCII digit. */
|
|
248
|
+
const isAlphanumeric = (code) => code >= 48 && code <= 57 || (code | 32) >= 97 && (code | 32) <= 122;
|
|
249
|
+
/** This function gives the value of a code unit as a decimal or a hexadecimal digit, or -1 for a different code unit. */
|
|
250
|
+
function digitOf(code, hex) {
|
|
251
|
+
if (code >= 48 && code <= 57) return code - 48;
|
|
252
|
+
const lower = code | 32;
|
|
253
|
+
return hex && lower >= 97 && lower <= 102 ? lower - 97 + 10 : -1;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* This function reads the numeric character reference at the "&" at `amp`, with the fixes of the standard. It gives
|
|
257
|
+
* undefined when no digit follows "&#" or "&#x".
|
|
258
|
+
*/
|
|
259
|
+
function readNumeric(text, amp) {
|
|
260
|
+
let at = amp + 2;
|
|
261
|
+
const hex = (text.charCodeAt(at) | 32) === 120;
|
|
262
|
+
if (hex) at += 1;
|
|
263
|
+
const start = at;
|
|
264
|
+
let point = 0;
|
|
265
|
+
for (let digit = digitOf(text.charCodeAt(at), hex); digit !== -1; digit = digitOf(text.charCodeAt(at), hex)) {
|
|
266
|
+
point = Math.min(point * (hex ? 16 : 10) + digit, 1114112);
|
|
267
|
+
at += 1;
|
|
268
|
+
}
|
|
269
|
+
if (at === start) return void 0;
|
|
270
|
+
if (text.charCodeAt(at) === 59) at += 1;
|
|
271
|
+
if (point === 0 || point > 1114111 || point >= 55296 && point <= 57343) return {
|
|
272
|
+
value: "�",
|
|
273
|
+
end: at
|
|
274
|
+
};
|
|
275
|
+
if (point >= 128 && point <= 159) return {
|
|
276
|
+
value: C1_VALUES.charAt(point - 128),
|
|
277
|
+
end: at
|
|
278
|
+
};
|
|
279
|
+
return {
|
|
280
|
+
value: String.fromCodePoint(point),
|
|
281
|
+
end: at
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* This function reads the named character reference at the "&" at `amp`. The longest name wins. It gives undefined when
|
|
286
|
+
* no name of the table follows the "&".
|
|
287
|
+
*/
|
|
288
|
+
function readNamed(text, amp) {
|
|
289
|
+
const from = amp + 1;
|
|
290
|
+
if (!isAlphanumeric(text.charCodeAt(from))) return void 0;
|
|
291
|
+
const table = namedReferences();
|
|
292
|
+
let at = from;
|
|
293
|
+
while (at - from <= longestName && isAlphanumeric(text.charCodeAt(at))) at += 1;
|
|
294
|
+
if (text.charCodeAt(at) === 59) {
|
|
295
|
+
const value = table.get(text.slice(from, at + 1));
|
|
296
|
+
if (value !== void 0) return {
|
|
297
|
+
value,
|
|
298
|
+
end: at + 1
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
for (let end = Math.min(at, from + longestLegacy); end > from; end -= 1) {
|
|
302
|
+
const value = table.get(text.slice(from, end));
|
|
303
|
+
if (value !== void 0) return {
|
|
304
|
+
value,
|
|
305
|
+
end
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* This function decodes the character references of a text, as the tokenizer of the HTML Living Standard does in the
|
|
311
|
+
* content of an element. Use it on the `text` of a scan of `scanHtml`.
|
|
312
|
+
*
|
|
313
|
+
* - A named reference gets its value from the table of the standard. The longest name wins.
|
|
314
|
+
* - A legacy name, for example `&` or `¬`, is also correct with no semicolon. Thus `¬it;` gives `¬it;`.
|
|
315
|
+
* - A decimal or hexadecimal reference, for example `’` or `’`, gives its code point. The semicolon is optional.
|
|
316
|
+
* - The value 0, a surrogate and a value above `0x10FFFF` give U+FFFD.
|
|
317
|
+
* - The values `0x80` to `0x9F` give the characters of windows-1252, from the table of the standard.
|
|
318
|
+
* - An ampersand with no reference after it stays as text. The function changes no other character.
|
|
319
|
+
*
|
|
320
|
+
* The function does not throw, and it is linear in the length of the text. The result is not longer than the text.
|
|
321
|
+
*
|
|
322
|
+
* @param text - The text of HTML content, with its character references.
|
|
323
|
+
* @returns The text with the value of each character reference in place of the reference.
|
|
324
|
+
*/
|
|
325
|
+
function decodeReferences(text) {
|
|
326
|
+
let amp = text.indexOf("&");
|
|
327
|
+
if (amp === -1) return text;
|
|
328
|
+
const parts = [];
|
|
329
|
+
let at = 0;
|
|
330
|
+
while (amp !== -1) {
|
|
331
|
+
const reference = text.charCodeAt(amp + 1) === 35 ? readNumeric(text, amp) : readNamed(text, amp);
|
|
332
|
+
if (reference === void 0) amp = text.indexOf("&", amp + 1);
|
|
333
|
+
else {
|
|
334
|
+
parts.push(text.slice(at, amp), reference.value);
|
|
335
|
+
at = reference.end;
|
|
336
|
+
amp = text.indexOf("&", at);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
parts.push(text.slice(at));
|
|
340
|
+
return parts.join("");
|
|
341
|
+
}
|
|
342
|
+
export { decodeReferences };
|
|
343
|
+
|
|
344
|
+
//# sourceMappingURL=references.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"references.js","names":[],"sources":["../src/html-references.ts","../src/references.ts"],"sourcesContent":["/**\n * This module has the named character references of HTML. The script `scripts/html-references.ts` made it. Do not\n * edit it. Start the script again to make it.\n *\n * The source is the table of the HTML Living Standard, `https://html.spec.whatwg.org/entities.json`. Copyright WHATWG\n * (Apple, Google, Mozilla, Microsoft). The table has the license CC BY 4.0,\n * `https://creativecommons.org/licenses/by/4.0/`. The SHA-256 of the source file is\n * `d741d877ac77c4194c4ad526b5b4a19aef8dfe411ab840a466891cdbb9f362e6`.\n *\n * The script changed the format of the table, not its content. The source has 2231 names. 106 of them are\n * legacy names, which are in the source with a semicolon and with no semicolon.\n */\n\n/**\n * The names and the values of the named character references. The names with one value make one group. A comma or a\n * line end comes between two groups. Each group has these parts:\n *\n * - the first code point of the value, as the difference from the first code point of the group before it,\n * - a plus sign and the second code point, only for a value with two code points,\n * - an equals sign and the names of the group, with a space between two names.\n *\n * Each number is in base 36. A name has no ampersand and no semicolon. A star after a name tells that the name is also\n * correct with no semicolon. The groups are in the order of their values. The longest name has 31 characters, and the\n * longest legacy name has 6 characters.\n */\nexport const NAMED_REFERENCES: string =\n `9=Tab,1=NewLine,n=excl,1=QUOT* quot*,1=num,1=dollar,1=percnt,1=AMP* amp*,1=apos,1=lpar,1=rpar,1=ast midast,1=plus\n1=comma,2=period,1=sol,b=colon,1=semi,1=LT* lt*,0+6he=nvlt,1=equals,0+6hx=bne,1=GT* gt*,0+6he=nvgt,1=quest,1=commat\nr=lbrack lsqb,1=bsol,1=rbrack rsqb,1=Hat,1=UnderBar lowbar,1=DiacriticalGrave grave,6+2y=fjlig,l=lbrace lcub\n1=VerticalLine verbar vert,1=rbrace rcub,z=NonBreakingSpace nbsp*,1=iexcl*,1=cent*,1=pound*,1=curren*,1=yen*\n1=brvbar*,1=sect*,1=Dot DoubleDot die uml*,1=COPY* copy*,1=ordf*,1=laquo*,1=not*,1=shy*,1=REG* circledR reg*\n1=macr* strns,1=deg*,1=PlusMinus plusmn* pm,1=sup2*,1=sup3*,1=DiacriticalAcute acute*,1=micro*,1=para*\n1=CenterDot centerdot middot*,1=Cedilla cedil*,1=sup1*,1=ordm*,1=raquo*,1=frac14*,1=frac12* half,1=frac34*,1=iquest*\n1=Agrave*,1=Aacute*,1=Acirc*,1=Atilde*,1=Auml*,1=Aring* angst,1=AElig*,1=Ccedil*,1=Egrave*,1=Eacute*,1=Ecirc*\n1=Euml*,1=Igrave*,1=Iacute*,1=Icirc*,1=Iuml*,1=ETH*,1=Ntilde*,1=Ograve*,1=Oacute*,1=Ocirc*,1=Otilde*,1=Ouml*\n1=times*,1=Oslash*,1=Ugrave*,1=Uacute*,1=Ucirc*,1=Uuml*,1=Yacute*,1=THORN*,1=szlig*,1=agrave*,1=aacute*,1=acirc*\n1=atilde*,1=auml*,1=aring*,1=aelig*,1=ccedil*,1=egrave*,1=eacute*,1=ecirc*,1=euml*,1=igrave*,1=iacute*,1=icirc*\n1=iuml*,1=eth*,1=ntilde*,1=ograve*,1=oacute*,1=ocirc*,1=otilde*,1=ouml*,1=div divide*,1=oslash*,1=ugrave*,1=uacute*\n1=ucirc*,1=uuml*,1=yacute*,1=thorn*,1=yuml*,1=Amacr,1=amacr,1=Abreve,1=abreve,1=Aogon,1=aogon,1=Cacute,1=cacute\n1=Ccirc,1=ccirc,1=Cdot,1=cdot,1=Ccaron,1=ccaron,1=Dcaron,1=dcaron,1=Dstrok,1=dstrok,1=Emacr,1=emacr,3=Edot,1=edot\n1=Eogon,1=eogon,1=Ecaron,1=ecaron,1=Gcirc,1=gcirc,1=Gbreve,1=gbreve,1=Gdot,1=gdot,1=Gcedil,2=Hcirc,1=hcirc,1=Hstrok\n1=hstrok,1=Itilde,1=itilde,1=Imacr,1=imacr,3=Iogon,1=iogon,1=Idot,1=imath inodot,1=IJlig,1=ijlig,1=Jcirc,1=jcirc\n1=Kcedil,1=kcedil,1=kgreen,1=Lacute,1=lacute,1=Lcedil,1=lcedil,1=Lcaron,1=lcaron,1=Lmidot,1=lmidot,1=Lstrok,1=lstrok\n1=Nacute,1=nacute,1=Ncedil,1=ncedil,1=Ncaron,1=ncaron,1=napos,1=ENG,1=eng,1=Omacr,1=omacr,3=Odblac,1=odblac,1=OElig\n1=oelig,1=Racute,1=racute,1=Rcedil,1=rcedil,1=Rcaron,1=rcaron,1=Sacute,1=sacute,1=Scirc,1=scirc,1=Scedil,1=scedil\n1=Scaron,1=scaron,1=Tcedil,1=tcedil,1=Tcaron,1=tcaron,1=Tstrok,1=tstrok,1=Utilde,1=utilde,1=Umacr,1=umacr,1=Ubreve\n1=ubreve,1=Uring,1=uring,1=Udblac,1=udblac,1=Uogon,1=uogon,1=Wcirc,1=wcirc,1=Ycirc,1=ycirc,1=Yuml,1=Zacute,1=zacute\n1=Zdot,1=zdot,1=Zcaron,1=zcaron,k=fnof,z=imped,1s=gacute,1u=jmath,3z=circ,1=Hacek caron,h=Breve breve\n1=DiacriticalDot dot,1=ring,1=ogon,1=DiacriticalTilde tilde,1=DiacriticalDoubleAcute dblac,1g=DownBreve,3k=Alpha\n1=Beta,1=Gamma,1=Delta,1=Epsilon,1=Zeta,1=Eta,1=Theta,1=Iota,1=Kappa,1=Lambda,1=Mu,1=Nu,1=Xi,1=Omicron,1=Pi,1=Rho\n2=Sigma,1=Tau,1=Upsilon,1=Phi,1=Chi,1=Psi,1=Omega ohm,8=alpha,1=beta,1=gamma,1=delta,1=epsi epsilon,1=zeta,1=eta\n1=theta,1=iota,1=kappa,1=lambda,1=mu,1=nu,1=xi,1=omicron,1=pi,1=rho,1=sigmaf sigmav varsigma,1=sigma,1=tau\n1=upsi upsilon,1=phi,1=chi,1=psi,1=omega,8=thetasym thetav vartheta,1=Upsi upsih,3=phiv straightphi varphi\n1=piv varpi,6=Gammad,1=digamma gammad,j=kappav varkappa,1=rhov varrho,4=epsiv straightepsilon varepsilon\n1=backepsilon bepsi,b=IOcy,1=DJcy,1=GJcy,1=Jukcy,1=DScy,1=Iukcy,1=YIcy,1=Jsercy,1=LJcy,1=NJcy,1=TSHcy,1=KJcy,2=Ubrcy\n1=DZcy,1=Acy,1=Bcy,1=Vcy,1=Gcy,1=Dcy,1=IEcy,1=ZHcy,1=Zcy,1=Icy,1=Jcy,1=Kcy,1=Lcy,1=Mcy,1=Ncy,1=Ocy,1=Pcy,1=Rcy,1=Scy\n1=Tcy,1=Ucy,1=Fcy,1=KHcy,1=TScy,1=CHcy,1=SHcy,1=SHCHcy,1=HARDcy,1=Ycy,1=SOFTcy,1=Ecy,1=YUcy,1=YAcy,1=acy,1=bcy,1=vcy\n1=gcy,1=dcy,1=iecy,1=zhcy,1=zcy,1=icy,1=jcy,1=kcy,1=lcy,1=mcy,1=ncy,1=ocy,1=pcy,1=rcy,1=scy,1=tcy,1=ucy,1=fcy,1=khcy\n1=tscy,1=chcy,1=shcy,1=shchcy,1=hardcy,1=ycy,1=softcy,1=ecy,1=yucy,1=yacy,2=iocy,1=djcy,1=gjcy,1=jukcy,1=dscy\n1=iukcy,1=yicy,1=jsercy,1=ljcy,1=njcy,1=tshcy,1=kjcy,2=ubrcy,1=dzcy,5gj=ensp,1=emsp,1=emsp13,1=emsp14,2=numsp\n1=puncsp,1=ThinSpace thinsp,1=VeryThinSpace hairsp\n1=NegativeMediumSpace NegativeThickSpace NegativeThinSpace NegativeVeryThinSpace ZeroWidthSpace,1=zwnj,1=zwj,1=lrm\n1=rlm,1=dash hyphen,3=ndash,1=mdash,1=horbar,1=Verbar Vert,2=OpenCurlyQuote lsquo,1=CloseCurlyQuote rsquo rsquor\n1=lsquor sbquo,2=OpenCurlyDoubleQuote ldquo,1=CloseCurlyDoubleQuote rdquo rdquor,1=bdquo ldquor,2=dagger\n1=Dagger ddagger,1=bull bullet,3=nldr,1=hellip mldr,a=permil,1=pertenk,1=prime,1=Prime,1=tprime,1=backprime bprime\n4=lsaquo,1=rsaquo,4=OverBar oline,3=caret,2=hybull,1=frasl,b=bsemi,8=qprime,8=MediumSpace,0+6bu=ThickSpace,1=NoBreak\n1=ApplyFunction af,1=InvisibleTimes it,1=InvisibleComma ic,21=euro,1b=TripleDot tdot,1=DotDot,12=Copf complexes\n3=incare,5=gscr,1=HilbertSpace Hscr hamilt,1=Hfr Poincareplane,1=Hopf quaternions,1=planckh\n1=hbar hslash planck plankv,1=Iscr imagline,1=Ifr Im image imagpart,1=Laplacetrf Lscr lagran,1=ell,2=Nopf naturals\n1=numero,1=copysr,1=weierp wp,1=Popf primes,1=Qopf rationals,1=Rscr realine,1=Re Rfr real realpart,1=Ropf reals,1=rx\n4=TRADE trade,2=Zopf integers,3=mho,1=Zfr zeetrf,1=iiota,3=Bernoullis Bscr bernou,1=Cayleys Cfr,2=escr\n1=Escr expectation,1=Fouriertrf Fscr,2=Mellintrf Mscr phmmat,1=order orderof oscr,1=alefsym aleph,1=beth,1=gimel\n1=daleth,d=CapitalDifferentialD DD,1=DifferentialD dd,1=ExponentialE ee exponentiale,1=ImaginaryI ii,b=frac13\n1=frac23,1=frac15,1=frac25,1=frac35,1=frac45,1=frac16,1=frac56,1=frac18,1=frac38,1=frac58,1=frac78\n1e=LeftArrow ShortLeftArrow larr leftarrow slarr,1=ShortUpArrow UpArrow uarr uparrow\n1=RightArrow ShortRightArrow rarr rightarrow srarr,1=DownArrow ShortDownArrow darr downarrow\n1=LeftRightArrow harr leftrightarrow,1=UpDownArrow updownarrow varr,1=UpperLeftArrow nwarr nwarrow\n1=UpperRightArrow nearr nearrow,1=LowerRightArrow searr searrow,1=LowerLeftArrow swarr swarrow,1=nlarr nleftarrow\n1=nrarr nrightarrow,2=rarrw rightsquigarrow,0+mw=nrarrw,1=Larr twoheadleftarrow,1=Uarr,1=Rarr twoheadrightarrow\n1=Darr,1=larrtl leftarrowtail,1=rarrtl rightarrowtail,1=LeftTeeArrow mapstoleft,1=UpTeeArrow mapstoup\n1=RightTeeArrow map mapsto,1=DownTeeArrow mapstodown,2=hookleftarrow larrhk,1=hookrightarrow rarrhk\n1=larrlp looparrowleft,1=looparrowright rarrlp,1=harrw leftrightsquigarrow,1=nharr nleftrightarrow,2=Lsh lsh\n1=Rsh rsh,1=ldsh,1=rdsh,2=crarr,1=cularr curvearrowleft,1=curarr curvearrowright,3=circlearrowleft olarr\n1=circlearrowright orarr,1=LeftVector leftharpoonup lharu,1=DownLeftVector leftharpoondown lhard\n1=RightUpVector uharr upharpoonright,1=LeftUpVector uharl upharpoonleft,1=RightVector rharu rightharpoonup\n1=DownRightVector rhard rightharpoondown,1=RightDownVector dharr downharpoonright\n1=LeftDownVector dharl downharpoonleft,1=RightArrowLeftArrow rightleftarrows rlarr,1=UpArrowDownArrow udarr\n1=LeftArrowRightArrow leftrightarrows lrarr,1=leftleftarrows llarr,1=upuparrows uuarr,1=rightrightarrows rrarr\n1=ddarr downdownarrows,1=ReverseEquilibrium leftrightharpoons lrhar,1=Equilibrium rightleftharpoons rlhar\n1=nLeftarrow nlArr,1=nLeftrightarrow nhArr,1=nRightarrow nrArr,1=DoubleLeftArrow Leftarrow lArr\n1=DoubleUpArrow Uparrow uArr,1=DoubleRightArrow Implies Rightarrow rArr,1=DoubleDownArrow Downarrow dArr\n1=DoubleLeftRightArrow Leftrightarrow hArr iff,1=DoubleUpDownArrow Updownarrow vArr,1=nwArr,1=neArr,1=seArr,1=swArr\n1=Lleftarrow lAarr,1=Rrightarrow rAarr,2=zigrarr,7=LeftArrowBar larrb,1=RightArrowBar rarrb,g=DownArrowUpArrow duarr\n8=loarr,1=roarr,1=hoarr,1=ForAll forall,1=comp complement,1=PartialD part,0+mw=npart,1=Exists exist\n1=NotExists nexist nexists,1=empty emptyset emptyv varnothing,2=Del nabla,1=Element in isin isinv\n1=NotElement notin notinva,2=ReverseElement SuchThat ni niv,1=NotReverseElement notni notniva,3=Product prod\n1=Coproduct coprod,1=Sum sum,1=minus,1=MinusPlus mnplus mp,1=dotplus plusdo\n2=Backslash setminus setmn smallsetminus ssetmn,1=lowast,1=SmallCircle compfn,2=Sqrt radic\n3=Proportional prop propto varpropto vprop,1=infin,1=angrt,1=ang angle,0+6he=nang,1=angmsd measuredangle,1=angsph\n1=VerticalBar mid shortmid smid,1=NotVerticalBar nmid nshortmid nsmid\n1=DoubleVerticalBar par parallel shortparallel spar,1=NotDoubleVerticalBar npar nparallel nshortparallel nspar\n1=and wedge,1=or vee,1=cap,0+1e68=caps,1=cup,0+1e68=cups,1=Integral int,1=Int,1=iiint tint\n1=ContourIntegral conint oint,1=Conint DoubleContourIntegral,1=Cconint,1=cwint,1=ClockwiseContourIntegral cwconint\n1=CounterClockwiseContourIntegral awconint,1=Therefore there4 therefore,1=Because becaus because,1=ratio\n1=Colon Proportion,1=dotminus minusd,2=mDDot,1=homtht,1=Tilde sim thicksim thksim,0+6he=nvsim,1=backsim bsim\n0+mp=race,1=ac mstpos,0+mr=acE,1=acd,1=VerticalTilde wr wreath,1=NotTilde nsim,1=EqualTilde eqsim esim\n0+mw=NotEqualTilde nesim,1=TildeEqual sime simeq,1=NotTildeEqual nsime nsimeq,1=TildeFullEqual cong,1=simne\n1=NotTildeFullEqual ncong,1=TildeTilde ap approx asymp thickapprox thkap,1=NotTildeTilde nap napprox,1=ape approxeq\n1=apid,0+mw=napid,1=backcong bcong,1=CupCap asympeq,0+6he=nvap,1=Bumpeq HumpDownHump bump,0+mw=NotHumpDownHump nbump\n1=HumpEqual bumpe bumpeq,0+mw=NotHumpEqual nbumpe,1=DotEqual doteq esdot,0+mw=nedot,1=doteqdot eDot\n1=efDot fallingdotseq,1=erDot risingdotseq,1=Assign colone coloneq,1=ecolon eqcolon,1=ecir eqcirc,1=circeq cire\n2=wedgeq,1=veeeq,2=triangleq trie,3=equest questeq,1=NotEqual ne,1=Congruent equiv,0+6hx=bnequiv\n1=NotCongruent nequiv,2=le leq,0+6he=nvle,1=GreaterEqual ge geq,0+6he=nvge,1=LessFullEqual lE leqq,0+mw=nlE nleqq\n1=GreaterFullEqual gE geqq,0+mw=NotGreaterFullEqual ngE ngeqq,1=lnE lneqq,0+1e68=lvertneqq lvnE,1=gnE gneqq\n0+1e68=gvertneqq gvnE,1=Lt NestedLessLess ll,0+mw=NotLessLess nLtv,0+6he=nLt,1=Gt NestedGreaterGreater gg\n0+mw=NotGreaterGreater nGtv,0+6he=nGt,1=between twixt,1=NotCupCap,1=NotLess nless nlt,1=NotGreater ngt ngtr\n1=NotLessEqual nle nleq,1=NotGreaterEqual nge ngeq,1=LessTilde lesssim lsim,1=GreaterTilde gsim gtrsim\n1=NotLessTilde nlsim,1=NotGreaterTilde ngsim,1=LessGreater lessgtr lg,1=GreaterLess gl gtrless,1=NotLessGreater ntlg\n1=NotGreaterLess ntgl,1=Precedes pr prec,1=Succeeds sc succ,1=PrecedesSlantEqual prcue preccurlyeq\n1=SucceedsSlantEqual sccue succcurlyeq,1=PrecedesTilde precsim prsim,1=SucceedsTilde scsim succsim\n0+mw=NotSucceedsTilde,1=NotPrecedes npr nprec,1=NotSucceeds nsc nsucc,1=sub subset,0+6he=NotSubset nsubset vnsub\n1=Superset sup supset,0+6he=NotSuperset nsupset vnsup,1=nsub,1=nsup,1=SubsetEqual sube subseteq\n1=SupersetEqual supe supseteq,1=NotSubsetEqual nsube nsubseteq,1=NotSupersetEqual nsupe nsupseteq,1=subne subsetneq\n0+1e68=varsubsetneq vsubne,1=supne supsetneq,0+1e68=varsupsetneq vsupne,2=cupdot,1=UnionPlus uplus\n1=SquareSubset sqsub sqsubset,0+mw=NotSquareSubset,1=SquareSuperset sqsup sqsupset,0+mw=NotSquareSuperset\n1=SquareSubsetEqual sqsube sqsubseteq,1=SquareSupersetEqual sqsupe sqsupseteq,1=SquareIntersection sqcap\n0+1e68=sqcaps,1=SquareUnion sqcup,0+1e68=sqcups,1=CirclePlus oplus,1=CircleMinus ominus,1=CircleTimes otimes,1=osol\n1=CircleDot odot,1=circledcirc ocir,1=circledast oast,2=circleddash odash,1=boxplus plusb,1=boxminus minusb\n1=boxtimes timesb,1=dotsquare sdotb,1=RightTee vdash,1=LeftTee dashv,1=DownTee top,1=UpTee bot bottom perp,2=models\n1=DoubleRightTee vDash,1=Vdash,1=Vvdash,1=VDash,1=nvdash,1=nvDash,1=nVdash,1=nVDash,1=prurel\n2=LeftTriangle vartriangleleft vltri,1=RightTriangle vartriangleright vrtri,1=LeftTriangleEqual ltrie trianglelefteq\n0+6he=nvltrie,1=RightTriangleEqual rtrie trianglerighteq,0+6he=nvrtrie,1=origof,1=imof,1=multimap mumap,1=hercon\n1=intcal intercal,1=veebar,2=barvee,1=angrtvb,1=lrtri,1=Wedge bigwedge xwedge,1=Vee bigvee xvee\n1=Intersection bigcap xcap,1=Union bigcup xcup,1=Diamond diam diamond,1=sdot,1=Star sstarf,1=divideontimes divonx\n1=bowtie,1=ltimes,1=rtimes,1=leftthreetimes lthree,1=rightthreetimes rthree,1=backsimeq bsime,1=curlyvee cuvee\n1=curlywedge cuwed,1=Sub Subset,1=Sup Supset,1=Cap,1=Cup,1=fork pitchfork,1=epar,1=lessdot ltdot,1=gtdot gtrdot,1=Ll\n0+mw=nLl,1=Gg ggg,0+mw=nGg,1=LessEqualGreater leg lesseqgtr,0+1e68=lesg,1=GreaterEqualLess gel gtreqless,0+1e68=gesl\n3=cuepr curlyeqprec,1=cuesc curlyeqsucc,1=NotPrecedesSlantEqual nprcue,1=NotSucceedsSlantEqual nsccue\n1=NotSquareSubsetEqual nsqsube,1=NotSquareSupersetEqual nsqsupe,3=lnsim,1=gnsim,1=precnsim prnsim,1=scnsim succnsim\n1=NotLeftTriangle nltri ntriangleleft,1=NotRightTriangle nrtri ntriangleright\n1=NotLeftTriangleEqual nltrie ntrianglelefteq,1=NotRightTriangleEqual nrtrie ntrianglerighteq,1=vellip,1=ctdot\n1=utdot,1=dtdot,1=disin,1=isinsv,1=isins,1=isindot,0+mw=notindot,1=notinvc,1=notinvb,2=isinE,0+mw=notinE,1=nisd\n1=xnis,1=nis,1=notnivc,1=notnivb,7=barwed barwedge,1=Barwed doublebarwedge,2=LeftCeiling lceil,1=RightCeiling rceil\n1=LeftFloor lfloor,1=RightFloor rfloor,1=drcrop,1=dlcrop,1=urcrop,1=ulcrop,1=bnot,2=profline,1=profsurf,2=telrec\n1=target,6=ulcorn ulcorner,1=urcorn urcorner,1=dlcorn llcorner,1=drcorn lrcorner,3=frown sfrown,1=smile ssmile\na=cylcty,1=profalar,8=topbot,7=ovbar,2=solbar,1p=angzarr,1g=lmoust lmoustache,1=rmoust rmoustache,3=OverBracket tbrk\n1=UnderBracket bbrk,1=bbrktbrk,12=OverParenthesis,1=UnderParenthesis,1=OverBrace,1=UnderBrace,3=trpezium,5=elinters\n1o=blank,4l=circledS oS,1k=HorizontalLine boxh,2=boxv,a=boxdr,4=boxdl,4=boxur,4=boxul,4=boxvr,8=boxvl,8=boxhd\n8=boxhu,8=boxvh,k=boxH,1=boxV,1=boxdR,1=boxDr,1=boxDR,1=boxdL,1=boxDl,1=boxDL,1=boxuR,1=boxUr,1=boxUR,1=boxuL\n1=boxUl,1=boxUL,1=boxvR,1=boxVr,1=boxVR,1=boxvL,1=boxVl,1=boxVL,1=boxHd,1=boxhD,1=boxHD,1=boxHu,1=boxhU,1=boxHU\n1=boxvH,1=boxVh,1=boxVH,k=uhblk,4=lhblk,4=block,9=blk14,1=blk12,1=blk34,e=Square squ square\n9=FilledVerySmallSquare blacksquare squarf squf,1=EmptyVerySmallSquare,2=rect,1=marker,3=fltns,2=bigtriangleup xutri\n1=blacktriangle utrif,1=triangle utri,3=blacktriangleright rtrif,1=rtri triangleright,4=bigtriangledown xdtri\n1=blacktriangledown dtrif,1=dtri triangledown,3=blacktriangleleft ltrif,1=ltri triangleleft,7=loz lozenge,1=cir\nx=tridot,3=bigcirc xcirc,9=ultri,1=urtri,1=lltri,1=EmptySmallSquare,1=FilledSmallSquare,9=bigstar starf,1=star\n8=phone,1e=female,2=male,u=spades spadesuit,3=clubs clubsuit,2=hearts heartsuit,1=diamondsuit diams,4=sung,3=flat\n1=natur natural,1=sharp,4k=check checkmark,4=cross,9=malt maltese,m=sext,y=VerticalSeparator,q=lbbrk,1=rbbrk\n2d=bsolhsub,1=suphsol,t=LeftDoubleBracket lobrk,1=RightDoubleBracket robrk,1=LeftAngleBracket lang langle\n1=RightAngleBracket rang rangle,1=Lang,1=Rang,1=loang,1=roang,8=LongLeftArrow longleftarrow xlarr\n1=LongRightArrow longrightarrow xrarr,1=LongLeftRightArrow longleftrightarrow xharr\n1=DoubleLongLeftArrow Longleftarrow xlArr,1=DoubleLongRightArrow Longrightarrow xrArr\n1=DoubleLongLeftRightArrow Longleftrightarrow xhArr,2=longmapsto xmap,3=dzigrarr,77=nvlArr,1=nvrArr,1=nvHarr,1=Map\n7=lbarr,1=bkarow rbarr,1=lBarr,1=dbkarow rBarr,1=RBarr drbkarow,1=DDotrahd,1=UpArrowBar,1=DownArrowBar,3=Rarrtl\n3=latail,1=ratail,1=lAtail,1=rAtail,1=larrfs,1=rarrfs,1=larrbfs,1=rarrbfs,3=nwarhk,1=nearhk,1=hksearow searhk\n1=hkswarow swarhk,1=nwnear,1=nesear toea,1=seswar tosa,1=swnwar,9=rarrc,0+mw=nrarrc,2=cudarrr,1=ldca,1=rdca\n1=cudarrl,1=larrpl,3=curarrm,1=cularrp,8=rarrpl,3=harrcir,1=Uarrocir,1=lurdshar,1=ldrushar,3=LeftRightVector\n1=RightUpDownVector,1=DownLeftRightVector,1=LeftUpDownVector,1=LeftVectorBar,1=RightVectorBar,1=RightUpVectorBar\n1=RightDownVectorBar,1=DownLeftVectorBar,1=DownRightVectorBar,1=LeftUpVectorBar,1=LeftDownVectorBar,1=LeftTeeVector\n1=RightTeeVector,1=RightUpTeeVector,1=RightDownTeeVector,1=DownLeftTeeVector,1=DownRightTeeVector,1=LeftUpTeeVector\n1=LeftDownTeeVector,1=lHar,1=uHar,1=rHar,1=dHar,1=luruhar,1=ldrdhar,1=ruluhar,1=rdldhar,1=lharul,1=llhard,1=rharul\n1=lrhard,1=UpEquilibrium udhar,1=ReverseUpEquilibrium duhar,1=RoundImplies,1=erarr,1=simrarr,1=larrsim,1=rarrsim\n1=rarrap,1=ltlarr,2=gtrarr,1=subrarr,2=suplarr,1=lfisht,1=rfisht,1=ufisht,1=dfisht,6=lopar,1=ropar,5=lbrke,1=rbrke\n1=lbrkslu,1=rbrksld,1=lbrksld,1=rbrkslu,1=langd,1=rangd,1=lparlt,1=rpargt,1=gtlPar,1=ltrPar,4=vzigzag,2=vangrt\n1=angrtvbd,7=ange,1=range,1=dwangle,1=uwangle,1=angmsdaa,1=angmsdab,1=angmsdac,1=angmsdad,1=angmsdae,1=angmsdaf\n1=angmsdag,1=angmsdah,1=bemptyv,1=demptyv,1=cemptyv,1=raemptyv,1=laemptyv,1=ohbar,1=omid,1=opar,2=operp,2=olcross\n1=odsold,2=olcir,1=ofcir,1=olt,1=ogt,1=cirscir,1=cirE,1=solb,1=bsolb,4=boxbox,4=trisb,1=rtriltri,1=LeftTriangleBar\n0+mw=NotLeftTriangleBar,1=RightTriangleBar,0+mw=NotRightTriangleBar,c=iinfin,1=infintie,1=nvinfin,5=eparsl\n1=smeparsl,1=eqvparsl,6=blacklozenge lozf,9=RuleDelayed,2=dsol,a=bigodot xodot,1=bigoplus xoplus,1=bigotimes xotime\n2=biguplus xuplus,2=bigsqcup xsqcup,6=iiiint qint,1=fpartint,3=cirfnint,1=awint,1=rppolint,1=scpolint,1=npolint\n1=pointint,1=quatint,1=intlarhk,b=pluscir,1=plusacir,1=simplus,1=plusdu,1=plussim,1=plustwo,2=mcomma,1=minusdu\n3=loplus,1=roplus,1=Cross,1=timesd,1=timesbar,2=smashp,1=lotimes,1=rotimes,1=otimesas,1=Otimes,1=odiv,1=triplus\n1=triminus,1=tritime,1=intprod iprod,3=amalg,1=capdot,2=ncup,1=ncap,1=capand,1=cupor,1=cupcap,1=capcup,1=cupbrcap\n1=capbrcup,1=cupcup,1=capcap,1=ccups,1=ccaps,3=ccupssm,3=And,1=Or,1=andand,1=oror,1=orslope,1=andslope,2=andv,1=orv\n1=andd,1=ord,2=wedbar,7=sdote,4=simdot,3=congdot,0+mw=ncongdot,1=easter,1=apacir,1=apE,0+mw=napE,1=eplus,1=pluse\n1=Esim,1=Colone,1=Equal,2=ddotseq eDDot,1=equivDD,1=ltcir,1=gtcir,1=ltquest,1=gtquest,1=LessSlantEqual leqslant les\n0+mw=NotLessSlantEqual nleqslant nles,1=GreaterSlantEqual geqslant ges,0+mw=NotGreaterSlantEqual ngeqslant nges\n1=lesdot,1=gesdot,1=lesdoto,1=gesdoto,1=lesdotor,1=gesdotol,1=lap lessapprox,1=gap gtrapprox,1=lne lneq,1=gne gneq\n1=lnap lnapprox,1=gnap gnapprox,1=lEg lesseqqgtr,1=gEl gtreqqless,1=lsime,1=gsime,1=lsimg,1=gsiml,1=lgE,1=glE\n1=lesges,1=gesles,1=els eqslantless,1=egs eqslantgtr,1=elsdot,1=egsdot,1=el,1=eg,3=siml,1=simg,1=simlE,1=simgE\n1=LessLess,0+mw=NotNestedLessLess,1=GreaterGreater,0+mw=NotNestedGreaterGreater,2=glj,1=gla,1=ltcc,1=gtcc,1=lescc\n1=gescc,1=smt,1=lat,1=smte,0+1e68=smtes,1=late,0+1e68=lates,1=bumpE,1=PrecedesEqual pre preceq\n0+mw=NotPrecedesEqual npre npreceq,1=SucceedsEqual sce succeq,0+mw=NotSucceedsEqual nsce nsucceq,3=prE,1=scE\n1=precneqq prnE,1=scnE succneqq,1=prap precapprox,1=scap succapprox,1=precnapprox prnap,1=scnap succnapprox,1=Pr\n1=Sc,1=subdot,1=supdot,1=subplus,1=supplus,1=submult,1=supmult,1=subedot,1=supedot,1=subE subseteqq\n0+mw=nsubE nsubseteqq,1=supE supseteqq,0+mw=nsupE nsupseteqq,1=subsim,1=supsim,3=subnE subsetneqq\n0+1e68=varsubsetneqq vsubnE,1=supnE supsetneqq,0+1e68=varsupsetneqq vsupnE,3=csub,1=csup,1=csube,1=csupe,1=subsup\n1=supsub,1=subsub,1=supsup,1=suphsub,1=supdsub,1=forkv,1=topfork,1=mlcp,9=Dashv DoubleLeftTee,2=Vdashl,1=Barv,1=vBar\n1=vBarv,2=Vbar,1=Not,1=bNot,1=rnmid,1=cirmid,1=midcir,1=topcir,1=nhpar,1=parsim,a=parsl,0+6hx=nparsl,1537=fflig\n1=filig,1=fllig,1=ffilig,1=ffllig,16zc=Ascr,2=Cscr,1=Dscr,3=Gscr,3=Jscr,1=Kscr,3=Nscr,1=Oscr,1=Pscr,1=Qscr,2=Sscr\n1=Tscr,1=Uscr,1=Vscr,1=Wscr,1=Xscr,1=Yscr,1=Zscr,1=ascr,1=bscr,1=cscr,1=dscr,2=fscr,2=hscr,1=iscr,1=jscr,1=kscr\n1=lscr,1=mscr,1=nscr,2=pscr,1=qscr,1=rscr,1=sscr,1=tscr,1=uscr,1=vscr,1=wscr,1=xscr,1=yscr,1=zscr,1h=Afr,1=Bfr,2=Dfr\n1=Efr,1=Ffr,1=Gfr,3=Jfr,1=Kfr,1=Lfr,1=Mfr,1=Nfr,1=Ofr,1=Pfr,1=Qfr,2=Sfr,1=Tfr,1=Ufr,1=Vfr,1=Wfr,1=Xfr,1=Yfr,2=afr\n1=bfr,1=cfr,1=dfr,1=efr,1=ffr,1=gfr,1=hfr,1=ifr,1=jfr,1=kfr,1=lfr,1=mfr,1=nfr,1=ofr,1=pfr,1=qfr,1=rfr,1=sfr,1=tfr\n1=ufr,1=vfr,1=wfr,1=xfr,1=yfr,1=zfr,1=Aopf,1=Bopf,2=Dopf,1=Eopf,1=Fopf,1=Gopf,2=Iopf,1=Jopf,1=Kopf,1=Lopf,1=Mopf\n2=Oopf,4=Sopf,1=Topf,1=Uopf,1=Vopf,1=Wopf,1=Xopf,1=Yopf,2=aopf,1=bopf,1=copf,1=dopf,1=eopf,1=fopf,1=gopf,1=hopf\n1=iopf,1=jopf,1=kopf,1=lopf,1=mopf,1=nopf,1=oopf,1=popf,1=qopf,1=ropf,1=sopf,1=topf,1=uopf,1=vopf,1=wopf,1=xopf\n1=yopf,1=zopf`;\n","/**\n * This module decodes the character references of HTML content, with no DOM. The table of the named references has\n * 2231 names. It is in a separate entry, so a bundle that only scans HTML does not get the table.\n */\nimport { NAMED_REFERENCES } from \"./html-references.ts\";\n\n/**\n * The values of the code points 0x80 to 0x9F in a numeric character reference, from the table of the standard. They are\n * the characters of windows-1252. The five code points that windows-1252 does not have stay as they are.\n */\nconst C1_VALUES =\n \"\\u20AC\\u0081\\u201A\\u0192\\u201E\\u2026\\u2020\\u2021\\u02C6\\u2030\\u0160\\u2039\\u0152\\u008D\\u017D\\u008F\" +\n \"\\u0090\\u2018\\u2019\\u201C\\u201D\\u2022\\u2013\\u2014\\u02DC\\u2122\\u0161\\u203A\\u0153\\u009D\\u017E\\u0178\";\n\n/** The value of each named character reference. A name with `;` is a key, and a legacy name is also a key with no `;`. */\nlet named: Map<string, string> | undefined;\n/** The length of the longest name, with no `;`. */\nlet longestName = 0;\n/** The length of the longest legacy name. */\nlet longestLegacy = 0;\n\n/** This function reads the table of the named character references one time, when the decoder first needs it. */\nfunction namedReferences(): Map<string, string> {\n if (named !== undefined) return named;\n const table = new Map<string, string>();\n let point = 0;\n for (const group of NAMED_REFERENCES.split(/[,\\n]/)) {\n const equals = group.indexOf(\"=\");\n const [first = \"\", second] = group.slice(0, equals).split(\"+\");\n point += parseInt(first, 36);\n const value = second === undefined ? String.fromCodePoint(point) : String.fromCodePoint(point, parseInt(second, 36));\n for (const entry of group.slice(equals + 1).split(\" \")) {\n const legacy = entry.endsWith(\"*\");\n const name = legacy ? entry.slice(0, -1) : entry;\n table.set(`${name};`, value);\n longestName = Math.max(longestName, name.length);\n if (legacy) {\n table.set(name, value);\n longestLegacy = Math.max(longestLegacy, name.length);\n }\n }\n }\n named = table;\n return table;\n}\n\n/** This function tells if a code unit is an ASCII letter or an ASCII digit. */\nconst isAlphanumeric = (code: number): boolean => (code >= 0x30 && code <= 0x39) || ((code | 0x20) >= 0x61 && (code | 0x20) <= 0x7a);\n\n/** This function gives the value of a code unit as a decimal or a hexadecimal digit, or -1 for a different code unit. */\nfunction digitOf(code: number, hex: boolean): number {\n if (code >= 0x30 && code <= 0x39) return code - 0x30;\n const lower = code | 0x20;\n return hex && lower >= 0x61 && lower <= 0x66 ? lower - 0x61 + 10 : -1;\n}\n\n/** A character reference that the decoder found: its value, and the index after its last character. */\ninterface Reference {\n readonly value: string;\n readonly end: number;\n}\n\n/**\n * This function reads the numeric character reference at the \"&\" at `amp`, with the fixes of the standard. It gives\n * undefined when no digit follows \"&#\" or \"&#x\".\n */\nfunction readNumeric(text: string, amp: number): Reference | undefined {\n let at = amp + 2;\n const hex = (text.charCodeAt(at) | 0x20) === 0x78;\n if (hex) at += 1;\n const start = at;\n let point = 0;\n for (let digit = digitOf(text.charCodeAt(at), hex); digit !== -1; digit = digitOf(text.charCodeAt(at), hex)) {\n // A value above 0x10FFFF stays at 0x110000. Thus a long run of digits does not make a number that is too large.\n point = Math.min(point * (hex ? 16 : 10) + digit, 0x110000);\n at += 1;\n }\n if (at === start) return undefined;\n if (text.charCodeAt(at) === 0x3b) at += 1;\n if (point === 0 || point > 0x10ffff || (point >= 0xd800 && point <= 0xdfff)) return { value: \"\\uFFFD\", end: at };\n if (point >= 0x80 && point <= 0x9f) return { value: C1_VALUES.charAt(point - 0x80), end: at };\n return { value: String.fromCodePoint(point), end: at };\n}\n\n/**\n * This function reads the named character reference at the \"&\" at `amp`. The longest name wins. It gives undefined when\n * no name of the table follows the \"&\".\n */\nfunction readNamed(text: string, amp: number): Reference | undefined {\n const from = amp + 1;\n if (!isAlphanumeric(text.charCodeAt(from))) return undefined;\n const table = namedReferences();\n // A run of letters and digits that is longer than the longest name is not a name. Thus each \"&\" reads few characters.\n let at = from;\n while (at - from <= longestName && isAlphanumeric(text.charCodeAt(at))) at += 1;\n if (text.charCodeAt(at) === 0x3b) {\n const value = table.get(text.slice(from, at + 1));\n if (value !== undefined) return { value, end: at + 1 };\n }\n // With no `;`, only a legacy name can match: the longest legacy name at the start of the run.\n for (let end = Math.min(at, from + longestLegacy); end > from; end -= 1) {\n const value = table.get(text.slice(from, end));\n if (value !== undefined) return { value, end };\n }\n return undefined;\n}\n\n/**\n * This function decodes the character references of a text, as the tokenizer of the HTML Living Standard does in the\n * content of an element. Use it on the `text` of a scan of `scanHtml`.\n *\n * - A named reference gets its value from the table of the standard. The longest name wins.\n * - A legacy name, for example `&` or `¬`, is also correct with no semicolon. Thus `¬it;` gives `¬it;`.\n * - A decimal or hexadecimal reference, for example `’` or `’`, gives its code point. The semicolon is optional.\n * - The value 0, a surrogate and a value above `0x10FFFF` give U+FFFD.\n * - The values `0x80` to `0x9F` give the characters of windows-1252, from the table of the standard.\n * - An ampersand with no reference after it stays as text. The function changes no other character.\n *\n * The function does not throw, and it is linear in the length of the text. The result is not longer than the text.\n *\n * @param text - The text of HTML content, with its character references.\n * @returns The text with the value of each character reference in place of the reference.\n */\nexport function decodeReferences(text: string): string {\n let amp = text.indexOf(\"&\");\n if (amp === -1) return text;\n const parts: string[] = [];\n let at = 0;\n while (amp !== -1) {\n const reference = text.charCodeAt(amp + 1) === 0x23 ? readNumeric(text, amp) : readNamed(text, amp);\n if (reference === undefined) amp = text.indexOf(\"&\", amp + 1);\n else {\n parts.push(text.slice(at, amp), reference.value);\n at = reference.end;\n amp = text.indexOf(\"&\", at);\n }\n }\n parts.push(text.slice(at));\n return parts.join(\"\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,mBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AChBF,MAAM,YACJ;;AAIF,IAAI;;AAEJ,IAAI,cAAc;;AAElB,IAAI,gBAAgB;;AAGpB,SAAS,kBAAuC;CAC9C,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,wBAAQ,IAAI,IAAoB;CACtC,IAAI,QAAQ;CACZ,KAAK,MAAM,SAAS,iBAAiB,MAAM,OAAO,GAAG;EACnD,MAAM,SAAS,MAAM,QAAQ,GAAG;EAChC,MAAM,CAAC,QAAQ,IAAI,UAAU,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG;EAC7D,SAAS,SAAS,OAAO,EAAE;EAC3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KAAK,MAAM,CAAC;OACvD;GACH,MAAM,KAAK,KAAK,MAAM,IAAI,GAAG,GAAG,UAAU,KAAK;GAC/C,KAAK,UAAU;GACf,MAAM,KAAK,QAAQ,KAAK,EAAE;EAC5B;CACF;CACA,MAAM,KAAK,KAAK,MAAM,EAAE,CAAC;CACzB,OAAO,MAAM,KAAK,EAAE;AACtB"}
|
package/build/search.d.ts
CHANGED
|
@@ -110,4 +110,16 @@ export interface DocumentScore {
|
|
|
110
110
|
* @returns The score of each document, best first.
|
|
111
111
|
*/
|
|
112
112
|
export declare function rankDocuments(corpus: readonly (readonly string[])[], query: readonly string[], form?: IdfForm): DocumentScore[];
|
|
113
|
+
/**
|
|
114
|
+
* This function makes a ranker for one corpus. It computes the IDF and the vector of each document one time. It has no I/O.
|
|
115
|
+
*
|
|
116
|
+
* - For each query, the ranker gives the same scores as `rankDocuments(corpus, query, form)`.
|
|
117
|
+
* - A query costs one vector and one cosine for each document. Use the ranker when many queries search one corpus.
|
|
118
|
+
* - The ranker keeps the vectors of the corpus at the time of the call. A later change of the corpus does not change it.
|
|
119
|
+
*
|
|
120
|
+
* @param corpus - The documents, each as a list of words.
|
|
121
|
+
* @param form - The form of the IDF. The default is `plain`.
|
|
122
|
+
* @returns A function that gives the score of each document for a query, best first.
|
|
123
|
+
*/
|
|
124
|
+
export declare function rankerOf(corpus: readonly (readonly string[])[], form?: IdfForm): (query: readonly string[]) => DocumentScore[];
|
|
113
125
|
//# sourceMappingURL=search.d.ts.map
|
package/build/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","names":[],"sources":["../src/search.ts"],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"search.d.ts","names":[],"sources":["../src/search.ts"],"mappings":";;;;;;;;;;;;;;;;wBA4BgB,UAAU;;;;;;;;;;;wBAcV,WAAW,iBAAiB;;iBAQ3B;;WAEN,OAAO;;WAEP,QAAQ;;WAER,QAAQ;;;;;;;;;;;;;;;wBAmBH,YAAY,cAAc,UAAS;;;;;;;;YAmBvC;;;;;;;;;;;wBAYI,yBAAyB,2CAA2C,OAAM,UAAoB;;;;;;;;;;;;wBAkB9F,WAAW,0BAA0B,KAAK,8BAA8B;;;;;;;;;;wBA0BxE,iBAAiB,GAAG,6BAA6B,GAAG;;iBAQnD;;WAEN;;WAEA;;;;;;;;;;;;;;wBAeK,cAAc,wCAAwC,0BAA0B,OAAM,UAAoB;;;;;;;;;;;;wBAe1G,SAAS,wCAAwC,OAAM,WAAqB,6BAA6B"}
|
package/build/search.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* in any order. The case of the letters is not significant.
|
|
5
5
|
*
|
|
6
6
|
* The module also has a ranked search: the words of a text (`searchWords`), TF-IDF weights and the cosine similarity.
|
|
7
|
-
* `rankDocuments` puts the documents of a corpus in order for a query.
|
|
7
|
+
* `rankDocuments` puts the documents of a corpus in order for a query. `rankerOf` does this for many queries on one corpus.
|
|
8
|
+
* Each function has no I/O.
|
|
8
9
|
*/
|
|
9
10
|
/** The small final sigma. Unicode case folding changes it to the small sigma, so a word agrees in each position. */
|
|
10
11
|
const FINAL_SIGMA = /ς/gu;
|
|
@@ -138,13 +139,30 @@ function cosineSimilarity(a, b) {
|
|
|
138
139
|
* @returns The score of each document, best first.
|
|
139
140
|
*/
|
|
140
141
|
function rankDocuments(corpus, query, form = "plain") {
|
|
142
|
+
return rankerOf(corpus, form)(query);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* This function makes a ranker for one corpus. It computes the IDF and the vector of each document one time. It has no I/O.
|
|
146
|
+
*
|
|
147
|
+
* - For each query, the ranker gives the same scores as `rankDocuments(corpus, query, form)`.
|
|
148
|
+
* - A query costs one vector and one cosine for each document. Use the ranker when many queries search one corpus.
|
|
149
|
+
* - The ranker keeps the vectors of the corpus at the time of the call. A later change of the corpus does not change it.
|
|
150
|
+
*
|
|
151
|
+
* @param corpus - The documents, each as a list of words.
|
|
152
|
+
* @param form - The form of the IDF. The default is `plain`.
|
|
153
|
+
* @returns A function that gives the score of each document for a query, best first.
|
|
154
|
+
*/
|
|
155
|
+
function rankerOf(corpus, form = "plain") {
|
|
141
156
|
const idf = inverseDocumentFrequency(corpus, form);
|
|
142
|
-
const
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
157
|
+
const vectors = corpus.map((document) => termVector(document, idf));
|
|
158
|
+
return (query) => {
|
|
159
|
+
const q = termVector(query, idf);
|
|
160
|
+
return vectors.map((vector, index) => ({
|
|
161
|
+
index,
|
|
162
|
+
score: cosineSimilarity(q, vector)
|
|
163
|
+
})).sort((a, b) => b.score - a.score);
|
|
164
|
+
};
|
|
147
165
|
}
|
|
148
|
-
export { cosineSimilarity, inverseDocumentFrequency, rankDocuments, searchKey, searchWords, termVector, wordSearch };
|
|
166
|
+
export { cosineSimilarity, inverseDocumentFrequency, rankDocuments, rankerOf, searchKey, searchWords, termVector, wordSearch };
|
|
149
167
|
|
|
150
168
|
//# sourceMappingURL=search.js.map
|
package/build/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","names":[],"sources":["../src/search.ts"],"sourcesContent":["/**\n * This module has a word search of plain text. A text agrees with a search when the text has each word of the search,\n * in any order. The case of the letters is not significant.\n *\n * The module also has a ranked search: the words of a text (`searchWords`), TF-IDF weights and the cosine similarity.\n * `rankDocuments` puts the documents of a corpus in order for a query. Each function has no I/O.\n */\n\n/** The small final sigma. Unicode case folding changes it to the small sigma, so a word agrees in each position. */\nconst FINAL_SIGMA = /ς/gu;\n\n/**\n * This function gives the search key of a text. `wordSearch` compares the keys of texts. The function does these steps:\n *\n * 1. It applies the Unicode normalization NFKC. Thus the ligature \"fi\" agrees with \"fi\", and full-width letters agree\n * with ASCII letters.\n * 2. It applies the full lower case, then the full upper case, then the full lower case. Thus \"ß\", \"ẞ\" and \"SS\" give\n * \"ss\".\n * 3. It changes the small final sigma \"ς\" to \"σ\", as Unicode case folding does.\n * 4. It applies NFKC again.\n *\n * The steps use no rules of a locale. Thus the Turkish \"İ\" gives \"i\" with a combining dot above (U+0307), and the\n * Turkish \"ı\" gives \"i\". The key of a key is the same key. Accents stay, so \"é\" does not agree with \"e\".\n *\n * @param text - The plain text.\n * @returns The search key of the text.\n */\nexport function searchKey(text: string): string {\n return text.normalize(\"NFKC\").toLowerCase().toUpperCase().toLowerCase().replace(FINAL_SIGMA, \"σ\").normalize(\"NFKC\");\n}\n\n/**\n * This function gives the test of a search. The function makes the key of the search with `searchKey`. Then it splits\n * the key into words at each run of white space, the class `\\s` of a regular expression.\n *\n * The test tells if the key of a text contains each word, in any order. A word can be a part of a longer word, so the\n * search \"art\" finds \"Party\". A search with no words agrees with each text.\n *\n * @param query - The search, as a person types it.\n * @returns The test of a text.\n */\nexport function wordSearch(query: string): (text: string) => boolean {\n const words = searchKey(query)\n .split(/\\s+/u)\n .filter((word) => word !== \"\");\n return (text) => words.length === 0 || words.every((word) => searchKey(text).includes(word));\n}\n\n/** The options of `searchWords`. Each option is a rule of the caller, for example a list of stop words of a language. */\nexport interface WordOptions {\n /** The words that do not go in, as search keys. */\n readonly stop?: ReadonlySet<string>;\n /** The test of a word after the stop words. A word goes in only when the test gives true. */\n readonly keep?: (word: string) => boolean;\n /** The change of a word that goes in, for example a cut of a plural ending. */\n readonly stem?: (word: string) => string;\n}\n\n/** The word segmenter of `searchWords`. A segmenter is costly to make, so the module makes it one time, at the first use. */\nlet wordSegmenter: Intl.Segmenter | undefined;\n\n/**\n * This function gives the words of a text, in their order, for a ranked search. The function does these steps:\n *\n * 1. It makes the search key of the text with `searchKey`.\n * 2. It divides the key into word segments with `Intl.Segmenter` (Unicode Standard Annex 29). It keeps only the segments\n * that are words or numbers, not spaces or punctuation.\n * 3. It removes each word of `options.stop`, then each word that `options.keep` refuses.\n * 4. It applies `options.stem` to each word that stays.\n *\n * @param text - The plain text.\n * @param options - The rules of the caller. With no options, each word goes in with no change.\n * @returns The words of the text.\n */\nexport function searchWords(text: string, options: WordOptions = {}): string[] {\n const out: string[] = [];\n wordSegmenter ??= new Intl.Segmenter(\"en\", { granularity: \"word\" });\n for (const segment of wordSegmenter.segment(searchKey(text))) {\n if (!segment.isWordLike) continue;\n const word = segment.segment;\n if (options.stop?.has(word) || (options.keep && !options.keep(word))) continue;\n out.push(options.stem ? options.stem(word) : word);\n }\n return out;\n}\n\n/**\n * The two forms of the inverse document frequency (IDF) of a term. N is the count of documents, and df is the count of\n * the documents that have the term.\n *\n * - `plain` is ln(N / df). A term in each document has the weight 0, so it does not change a rank.\n * - `smooth` is ln((N + 1) / (df + 1)) + 1, as scikit-learn computes it. Each term has a weight of 1 or more.\n */\nexport type IdfForm = \"plain\" | \"smooth\";\n\n/**\n * This function gives the inverse document frequency of each term of a corpus. A document is a list of words, for\n * example from `searchWords`. A term counts one time in each document that has it.\n *\n * The weight of a term depends only on N and on its df. Thus the order of the documents does not change a weight.\n *\n * @param documents - The corpus.\n * @param form - The form of the IDF. The default is `plain`.\n * @returns The IDF of each term of the corpus.\n */\nexport function inverseDocumentFrequency(documents: readonly (readonly string[])[], form: IdfForm = \"plain\"): Map<string, number> {\n const df = new Map<string, number>();\n for (const document of documents) for (const term of new Set(document)) df.set(term, (df.get(term) ?? 0) + 1);\n const n = documents.length;\n return new Map([...df].map(([term, count]) => [term, form === \"plain\" ? Math.log(n / count) : Math.log((n + 1) / (count + 1)) + 1]));\n}\n\n/**\n * This function gives the TF-IDF vector of a list of words, with a length of 1.\n *\n * - The weight of a term is (1 + ln(tf)) × idf, where tf is the count of the term in the list.\n * - A term with a weight of 0, or with no IDF, is not in the vector.\n * - A list with no term of weight above 0 gives an empty vector.\n *\n * @param words - The words of a document or of a query.\n * @param idf - The IDF of each term, from `inverseDocumentFrequency`.\n * @returns The weight of each term, divided by the Euclidean length of the vector.\n */\nexport function termVector(words: readonly string[], idf: ReadonlyMap<string, number>): Map<string, number> {\n const tf = new Map<string, number>();\n for (const word of words) tf.set(word, (tf.get(word) ?? 0) + 1);\n const vector = new Map<string, number>();\n let norm = 0;\n for (const [term, count] of tf) {\n const weight = (1 + Math.log(count)) * (idf.get(term) ?? 0);\n if (weight > 0) {\n vector.set(term, weight);\n norm += weight * weight;\n }\n }\n norm = Math.sqrt(norm);\n if (norm > 0) for (const [term, weight] of vector) vector.set(term, weight / norm);\n return vector;\n}\n\n/**\n * This function gives the cosine similarity of two vectors with a length of 1, from `termVector`. The similarity is the\n * sum of the products of the weights of each term in the two vectors. It is 0 when the vectors have no term in common.\n * The function clamps the sum to 0 to 1. Thus a vector with itself gives exactly 1, and not 1 plus a rounding error.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The similarity, from 0 to 1.\n */\nexport function cosineSimilarity(a: ReadonlyMap<string, number>, b: ReadonlyMap<string, number>): number {\n const [small, large] = a.size < b.size ? [a, b] : [b, a];\n let sum = 0;\n for (const [term, weight] of small) sum += weight * (large.get(term) ?? 0);\n return Math.min(1, Math.max(0, sum));\n}\n\n/** The score of one document of a corpus for a query. */\nexport interface DocumentScore {\n /** The position of the document in the corpus. */\n readonly index: number;\n /** The cosine similarity of the TF-IDF vectors of the document and of the query. */\n readonly score: number;\n}\n\n/**\n * This function ranks the documents of a corpus for a query with TF-IDF and the cosine similarity. It has no I/O.\n *\n * - The IDF comes from the corpus only. A term of the query that is not in the corpus has no weight.\n * - The result has one score for each document, from the best to the worst. A tie keeps the order of the corpus.\n * - The score of a document does not change when the order of the other documents changes.\n *\n * @param corpus - The documents, each as a list of words.\n * @param query - The words of the query.\n * @param form - The form of the IDF. The default is `plain`.\n * @returns The score of each document, best first.\n */\nexport function rankDocuments(corpus: readonly (readonly string[])[], query: readonly string[], form: IdfForm = \"plain\"): DocumentScore[] {\n const idf = inverseDocumentFrequency(corpus, form);\n const q = termVector(query, idf);\n return corpus.map((document, index) => ({ index, score: cosineSimilarity(q, termVector(document, idf)) })).sort((a, b) => b.score - a.score);\n}\n"],"mappings":";;;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AAC,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AAC7I"}
|
|
1
|
+
{"version":3,"file":"search.js","names":[],"sources":["../src/search.ts"],"sourcesContent":["/**\n * This module has a word search of plain text. A text agrees with a search when the text has each word of the search,\n * in any order. The case of the letters is not significant.\n *\n * The module also has a ranked search: the words of a text (`searchWords`), TF-IDF weights and the cosine similarity.\n * `rankDocuments` puts the documents of a corpus in order for a query. `rankerOf` does this for many queries on one corpus.\n * Each function has no I/O.\n */\n\n/** The small final sigma. Unicode case folding changes it to the small sigma, so a word agrees in each position. */\nconst FINAL_SIGMA = /ς/gu;\n\n/**\n * This function gives the search key of a text. `wordSearch` compares the keys of texts. The function does these steps:\n *\n * 1. It applies the Unicode normalization NFKC. Thus the ligature \"fi\" agrees with \"fi\", and full-width letters agree\n * with ASCII letters.\n * 2. It applies the full lower case, then the full upper case, then the full lower case. Thus \"ß\", \"ẞ\" and \"SS\" give\n * \"ss\".\n * 3. It changes the small final sigma \"ς\" to \"σ\", as Unicode case folding does.\n * 4. It applies NFKC again.\n *\n * The steps use no rules of a locale. Thus the Turkish \"İ\" gives \"i\" with a combining dot above (U+0307), and the\n * Turkish \"ı\" gives \"i\". The key of a key is the same key. Accents stay, so \"é\" does not agree with \"e\".\n *\n * @param text - The plain text.\n * @returns The search key of the text.\n */\nexport function searchKey(text: string): string {\n return text.normalize(\"NFKC\").toLowerCase().toUpperCase().toLowerCase().replace(FINAL_SIGMA, \"σ\").normalize(\"NFKC\");\n}\n\n/**\n * This function gives the test of a search. The function makes the key of the search with `searchKey`. Then it splits\n * the key into words at each run of white space, the class `\\s` of a regular expression.\n *\n * The test tells if the key of a text contains each word, in any order. A word can be a part of a longer word, so the\n * search \"art\" finds \"Party\". A search with no words agrees with each text.\n *\n * @param query - The search, as a person types it.\n * @returns The test of a text.\n */\nexport function wordSearch(query: string): (text: string) => boolean {\n const words = searchKey(query)\n .split(/\\s+/u)\n .filter((word) => word !== \"\");\n return (text) => words.length === 0 || words.every((word) => searchKey(text).includes(word));\n}\n\n/** The options of `searchWords`. Each option is a rule of the caller, for example a list of stop words of a language. */\nexport interface WordOptions {\n /** The words that do not go in, as search keys. */\n readonly stop?: ReadonlySet<string>;\n /** The test of a word after the stop words. A word goes in only when the test gives true. */\n readonly keep?: (word: string) => boolean;\n /** The change of a word that goes in, for example a cut of a plural ending. */\n readonly stem?: (word: string) => string;\n}\n\n/** The word segmenter of `searchWords`. A segmenter is costly to make, so the module makes it one time, at the first use. */\nlet wordSegmenter: Intl.Segmenter | undefined;\n\n/**\n * This function gives the words of a text, in their order, for a ranked search. The function does these steps:\n *\n * 1. It makes the search key of the text with `searchKey`.\n * 2. It divides the key into word segments with `Intl.Segmenter` (Unicode Standard Annex 29). It keeps only the segments\n * that are words or numbers, not spaces or punctuation.\n * 3. It removes each word of `options.stop`, then each word that `options.keep` refuses.\n * 4. It applies `options.stem` to each word that stays.\n *\n * @param text - The plain text.\n * @param options - The rules of the caller. With no options, each word goes in with no change.\n * @returns The words of the text.\n */\nexport function searchWords(text: string, options: WordOptions = {}): string[] {\n const out: string[] = [];\n wordSegmenter ??= new Intl.Segmenter(\"en\", { granularity: \"word\" });\n for (const segment of wordSegmenter.segment(searchKey(text))) {\n if (!segment.isWordLike) continue;\n const word = segment.segment;\n if (options.stop?.has(word) || (options.keep && !options.keep(word))) continue;\n out.push(options.stem ? options.stem(word) : word);\n }\n return out;\n}\n\n/**\n * The two forms of the inverse document frequency (IDF) of a term. N is the count of documents, and df is the count of\n * the documents that have the term.\n *\n * - `plain` is ln(N / df). A term in each document has the weight 0, so it does not change a rank.\n * - `smooth` is ln((N + 1) / (df + 1)) + 1, as scikit-learn computes it. Each term has a weight of 1 or more.\n */\nexport type IdfForm = \"plain\" | \"smooth\";\n\n/**\n * This function gives the inverse document frequency of each term of a corpus. A document is a list of words, for\n * example from `searchWords`. A term counts one time in each document that has it.\n *\n * The weight of a term depends only on N and on its df. Thus the order of the documents does not change a weight.\n *\n * @param documents - The corpus.\n * @param form - The form of the IDF. The default is `plain`.\n * @returns The IDF of each term of the corpus.\n */\nexport function inverseDocumentFrequency(documents: readonly (readonly string[])[], form: IdfForm = \"plain\"): Map<string, number> {\n const df = new Map<string, number>();\n for (const document of documents) for (const term of new Set(document)) df.set(term, (df.get(term) ?? 0) + 1);\n const n = documents.length;\n return new Map([...df].map(([term, count]) => [term, form === \"plain\" ? Math.log(n / count) : Math.log((n + 1) / (count + 1)) + 1]));\n}\n\n/**\n * This function gives the TF-IDF vector of a list of words, with a length of 1.\n *\n * - The weight of a term is (1 + ln(tf)) × idf, where tf is the count of the term in the list.\n * - A term with a weight of 0, or with no IDF, is not in the vector.\n * - A list with no term of weight above 0 gives an empty vector.\n *\n * @param words - The words of a document or of a query.\n * @param idf - The IDF of each term, from `inverseDocumentFrequency`.\n * @returns The weight of each term, divided by the Euclidean length of the vector.\n */\nexport function termVector(words: readonly string[], idf: ReadonlyMap<string, number>): Map<string, number> {\n const tf = new Map<string, number>();\n for (const word of words) tf.set(word, (tf.get(word) ?? 0) + 1);\n const vector = new Map<string, number>();\n let norm = 0;\n for (const [term, count] of tf) {\n const weight = (1 + Math.log(count)) * (idf.get(term) ?? 0);\n if (weight > 0) {\n vector.set(term, weight);\n norm += weight * weight;\n }\n }\n norm = Math.sqrt(norm);\n if (norm > 0) for (const [term, weight] of vector) vector.set(term, weight / norm);\n return vector;\n}\n\n/**\n * This function gives the cosine similarity of two vectors with a length of 1, from `termVector`. The similarity is the\n * sum of the products of the weights of each term in the two vectors. It is 0 when the vectors have no term in common.\n * The function clamps the sum to 0 to 1. Thus a vector with itself gives exactly 1, and not 1 plus a rounding error.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The similarity, from 0 to 1.\n */\nexport function cosineSimilarity(a: ReadonlyMap<string, number>, b: ReadonlyMap<string, number>): number {\n const [small, large] = a.size < b.size ? [a, b] : [b, a];\n let sum = 0;\n for (const [term, weight] of small) sum += weight * (large.get(term) ?? 0);\n return Math.min(1, Math.max(0, sum));\n}\n\n/** The score of one document of a corpus for a query. */\nexport interface DocumentScore {\n /** The position of the document in the corpus. */\n readonly index: number;\n /** The cosine similarity of the TF-IDF vectors of the document and of the query. */\n readonly score: number;\n}\n\n/**\n * This function ranks the documents of a corpus for a query with TF-IDF and the cosine similarity. It has no I/O.\n *\n * - The IDF comes from the corpus only. A term of the query that is not in the corpus has no weight.\n * - The result has one score for each document, from the best to the worst. A tie keeps the order of the corpus.\n * - The score of a document does not change when the order of the other documents changes.\n *\n * @param corpus - The documents, each as a list of words.\n * @param query - The words of the query.\n * @param form - The form of the IDF. The default is `plain`.\n * @returns The score of each document, best first.\n */\nexport function rankDocuments(corpus: readonly (readonly string[])[], query: readonly string[], form: IdfForm = \"plain\"): DocumentScore[] {\n return rankerOf(corpus, form)(query);\n}\n\n/**\n * This function makes a ranker for one corpus. It computes the IDF and the vector of each document one time. It has no I/O.\n *\n * - For each query, the ranker gives the same scores as `rankDocuments(corpus, query, form)`.\n * - A query costs one vector and one cosine for each document. Use the ranker when many queries search one corpus.\n * - The ranker keeps the vectors of the corpus at the time of the call. A later change of the corpus does not change it.\n *\n * @param corpus - The documents, each as a list of words.\n * @param form - The form of the IDF. The default is `plain`.\n * @returns A function that gives the score of each document for a query, best first.\n */\nexport function rankerOf(corpus: readonly (readonly string[])[], form: IdfForm = \"plain\"): (query: readonly string[]) => DocumentScore[] {\n const idf = inverseDocumentFrequency(corpus, form);\n const vectors = corpus.map((document) => termVector(document, idf));\n return (query) => {\n const q = termVector(query, idf);\n return vectors.map((vector, index) => ({ index, score: cosineSimilarity(q, vector) })).sort((a, b) => b.score - a.score);\n };\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAkBpB,SAAgB,UAAU,MAAsB;CAC9C,OAAO,KAAK,UAAU,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAAC,QAAQ,aAAa,GAAG,CAAC,CAAC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E,QAAQ,EAAE,KAAK;CACzH;AACF"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/text",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"description": "Plain text helpers: the escapes for HTML, attributes, patterns, Markdown and workflow commands, English word forms (countOf, listOf), a word search (wordSearch), the text of a thrown value (errorMessage), the orders of texts by code units and by code points (compareCodeUnits, compareCodePoints), the removal of secrets (redactSecrets) and the shapes of tokens and of secrets by their context (findSecretShapes, redactSecretShapes, findSecretShapesInValue, CONTEXT_SHAPES, isSecretName), and lengths in code units, code points and graphemes with truncation and padding (textLength, truncate, pad), the marked parts of a text (partsAt, partsOf), and a scan of HTML for its text and its start tags (scanHtml).",
|
|
4
|
+
"version": "0.0.16",
|
|
5
|
+
"description": "Plain text helpers: the escapes for HTML, attributes, patterns, Markdown and workflow commands, English word forms (countOf, listOf), a word search (wordSearch), the text of a thrown value (errorMessage), the orders of texts by code units and by code points (compareCodeUnits, compareCodePoints), the removal of secrets (redactSecrets) and the shapes of tokens and of secrets by their context (findSecretShapes, redactSecretShapes, findSecretShapesInValue, CONTEXT_SHAPES, isSecretName), and lengths in code units, code points and graphemes with truncation and padding (textLength, truncate, pad), the marked parts of a text (partsAt, partsOf), and a scan of HTML for its text and its start tags (scanHtml) with the decode of its character references (decodeReferences).",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"text",
|
|
8
8
|
"escape",
|
|
9
9
|
"html",
|
|
10
|
+
"entities",
|
|
10
11
|
"regexp",
|
|
11
12
|
"markdown",
|
|
12
13
|
"search",
|
|
@@ -60,6 +61,10 @@
|
|
|
60
61
|
"types": "./build/html.d.ts",
|
|
61
62
|
"default": "./build/html.js"
|
|
62
63
|
},
|
|
64
|
+
"./references": {
|
|
65
|
+
"types": "./build/references.d.ts",
|
|
66
|
+
"default": "./build/references.js"
|
|
67
|
+
},
|
|
63
68
|
"./english": {
|
|
64
69
|
"types": "./build/english.d.ts",
|
|
65
70
|
"default": "./build/english.js"
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module has the named character references of HTML. The script `scripts/html-references.ts` made it. Do not
|
|
3
|
+
* edit it. Start the script again to make it.
|
|
4
|
+
*
|
|
5
|
+
* The source is the table of the HTML Living Standard, `https://html.spec.whatwg.org/entities.json`. Copyright WHATWG
|
|
6
|
+
* (Apple, Google, Mozilla, Microsoft). The table has the license CC BY 4.0,
|
|
7
|
+
* `https://creativecommons.org/licenses/by/4.0/`. The SHA-256 of the source file is
|
|
8
|
+
* `d741d877ac77c4194c4ad526b5b4a19aef8dfe411ab840a466891cdbb9f362e6`.
|
|
9
|
+
*
|
|
10
|
+
* The script changed the format of the table, not its content. The source has 2231 names. 106 of them are
|
|
11
|
+
* legacy names, which are in the source with a semicolon and with no semicolon.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The names and the values of the named character references. The names with one value make one group. A comma or a
|
|
16
|
+
* line end comes between two groups. Each group has these parts:
|
|
17
|
+
*
|
|
18
|
+
* - the first code point of the value, as the difference from the first code point of the group before it,
|
|
19
|
+
* - a plus sign and the second code point, only for a value with two code points,
|
|
20
|
+
* - an equals sign and the names of the group, with a space between two names.
|
|
21
|
+
*
|
|
22
|
+
* Each number is in base 36. A name has no ampersand and no semicolon. A star after a name tells that the name is also
|
|
23
|
+
* correct with no semicolon. The groups are in the order of their values. The longest name has 31 characters, and the
|
|
24
|
+
* longest legacy name has 6 characters.
|
|
25
|
+
*/
|
|
26
|
+
export const NAMED_REFERENCES: string =
|
|
27
|
+
`9=Tab,1=NewLine,n=excl,1=QUOT* quot*,1=num,1=dollar,1=percnt,1=AMP* amp*,1=apos,1=lpar,1=rpar,1=ast midast,1=plus
|
|
28
|
+
1=comma,2=period,1=sol,b=colon,1=semi,1=LT* lt*,0+6he=nvlt,1=equals,0+6hx=bne,1=GT* gt*,0+6he=nvgt,1=quest,1=commat
|
|
29
|
+
r=lbrack lsqb,1=bsol,1=rbrack rsqb,1=Hat,1=UnderBar lowbar,1=DiacriticalGrave grave,6+2y=fjlig,l=lbrace lcub
|
|
30
|
+
1=VerticalLine verbar vert,1=rbrace rcub,z=NonBreakingSpace nbsp*,1=iexcl*,1=cent*,1=pound*,1=curren*,1=yen*
|
|
31
|
+
1=brvbar*,1=sect*,1=Dot DoubleDot die uml*,1=COPY* copy*,1=ordf*,1=laquo*,1=not*,1=shy*,1=REG* circledR reg*
|
|
32
|
+
1=macr* strns,1=deg*,1=PlusMinus plusmn* pm,1=sup2*,1=sup3*,1=DiacriticalAcute acute*,1=micro*,1=para*
|
|
33
|
+
1=CenterDot centerdot middot*,1=Cedilla cedil*,1=sup1*,1=ordm*,1=raquo*,1=frac14*,1=frac12* half,1=frac34*,1=iquest*
|
|
34
|
+
1=Agrave*,1=Aacute*,1=Acirc*,1=Atilde*,1=Auml*,1=Aring* angst,1=AElig*,1=Ccedil*,1=Egrave*,1=Eacute*,1=Ecirc*
|
|
35
|
+
1=Euml*,1=Igrave*,1=Iacute*,1=Icirc*,1=Iuml*,1=ETH*,1=Ntilde*,1=Ograve*,1=Oacute*,1=Ocirc*,1=Otilde*,1=Ouml*
|
|
36
|
+
1=times*,1=Oslash*,1=Ugrave*,1=Uacute*,1=Ucirc*,1=Uuml*,1=Yacute*,1=THORN*,1=szlig*,1=agrave*,1=aacute*,1=acirc*
|
|
37
|
+
1=atilde*,1=auml*,1=aring*,1=aelig*,1=ccedil*,1=egrave*,1=eacute*,1=ecirc*,1=euml*,1=igrave*,1=iacute*,1=icirc*
|
|
38
|
+
1=iuml*,1=eth*,1=ntilde*,1=ograve*,1=oacute*,1=ocirc*,1=otilde*,1=ouml*,1=div divide*,1=oslash*,1=ugrave*,1=uacute*
|
|
39
|
+
1=ucirc*,1=uuml*,1=yacute*,1=thorn*,1=yuml*,1=Amacr,1=amacr,1=Abreve,1=abreve,1=Aogon,1=aogon,1=Cacute,1=cacute
|
|
40
|
+
1=Ccirc,1=ccirc,1=Cdot,1=cdot,1=Ccaron,1=ccaron,1=Dcaron,1=dcaron,1=Dstrok,1=dstrok,1=Emacr,1=emacr,3=Edot,1=edot
|
|
41
|
+
1=Eogon,1=eogon,1=Ecaron,1=ecaron,1=Gcirc,1=gcirc,1=Gbreve,1=gbreve,1=Gdot,1=gdot,1=Gcedil,2=Hcirc,1=hcirc,1=Hstrok
|
|
42
|
+
1=hstrok,1=Itilde,1=itilde,1=Imacr,1=imacr,3=Iogon,1=iogon,1=Idot,1=imath inodot,1=IJlig,1=ijlig,1=Jcirc,1=jcirc
|
|
43
|
+
1=Kcedil,1=kcedil,1=kgreen,1=Lacute,1=lacute,1=Lcedil,1=lcedil,1=Lcaron,1=lcaron,1=Lmidot,1=lmidot,1=Lstrok,1=lstrok
|
|
44
|
+
1=Nacute,1=nacute,1=Ncedil,1=ncedil,1=Ncaron,1=ncaron,1=napos,1=ENG,1=eng,1=Omacr,1=omacr,3=Odblac,1=odblac,1=OElig
|
|
45
|
+
1=oelig,1=Racute,1=racute,1=Rcedil,1=rcedil,1=Rcaron,1=rcaron,1=Sacute,1=sacute,1=Scirc,1=scirc,1=Scedil,1=scedil
|
|
46
|
+
1=Scaron,1=scaron,1=Tcedil,1=tcedil,1=Tcaron,1=tcaron,1=Tstrok,1=tstrok,1=Utilde,1=utilde,1=Umacr,1=umacr,1=Ubreve
|
|
47
|
+
1=ubreve,1=Uring,1=uring,1=Udblac,1=udblac,1=Uogon,1=uogon,1=Wcirc,1=wcirc,1=Ycirc,1=ycirc,1=Yuml,1=Zacute,1=zacute
|
|
48
|
+
1=Zdot,1=zdot,1=Zcaron,1=zcaron,k=fnof,z=imped,1s=gacute,1u=jmath,3z=circ,1=Hacek caron,h=Breve breve
|
|
49
|
+
1=DiacriticalDot dot,1=ring,1=ogon,1=DiacriticalTilde tilde,1=DiacriticalDoubleAcute dblac,1g=DownBreve,3k=Alpha
|
|
50
|
+
1=Beta,1=Gamma,1=Delta,1=Epsilon,1=Zeta,1=Eta,1=Theta,1=Iota,1=Kappa,1=Lambda,1=Mu,1=Nu,1=Xi,1=Omicron,1=Pi,1=Rho
|
|
51
|
+
2=Sigma,1=Tau,1=Upsilon,1=Phi,1=Chi,1=Psi,1=Omega ohm,8=alpha,1=beta,1=gamma,1=delta,1=epsi epsilon,1=zeta,1=eta
|
|
52
|
+
1=theta,1=iota,1=kappa,1=lambda,1=mu,1=nu,1=xi,1=omicron,1=pi,1=rho,1=sigmaf sigmav varsigma,1=sigma,1=tau
|
|
53
|
+
1=upsi upsilon,1=phi,1=chi,1=psi,1=omega,8=thetasym thetav vartheta,1=Upsi upsih,3=phiv straightphi varphi
|
|
54
|
+
1=piv varpi,6=Gammad,1=digamma gammad,j=kappav varkappa,1=rhov varrho,4=epsiv straightepsilon varepsilon
|
|
55
|
+
1=backepsilon bepsi,b=IOcy,1=DJcy,1=GJcy,1=Jukcy,1=DScy,1=Iukcy,1=YIcy,1=Jsercy,1=LJcy,1=NJcy,1=TSHcy,1=KJcy,2=Ubrcy
|
|
56
|
+
1=DZcy,1=Acy,1=Bcy,1=Vcy,1=Gcy,1=Dcy,1=IEcy,1=ZHcy,1=Zcy,1=Icy,1=Jcy,1=Kcy,1=Lcy,1=Mcy,1=Ncy,1=Ocy,1=Pcy,1=Rcy,1=Scy
|
|
57
|
+
1=Tcy,1=Ucy,1=Fcy,1=KHcy,1=TScy,1=CHcy,1=SHcy,1=SHCHcy,1=HARDcy,1=Ycy,1=SOFTcy,1=Ecy,1=YUcy,1=YAcy,1=acy,1=bcy,1=vcy
|
|
58
|
+
1=gcy,1=dcy,1=iecy,1=zhcy,1=zcy,1=icy,1=jcy,1=kcy,1=lcy,1=mcy,1=ncy,1=ocy,1=pcy,1=rcy,1=scy,1=tcy,1=ucy,1=fcy,1=khcy
|
|
59
|
+
1=tscy,1=chcy,1=shcy,1=shchcy,1=hardcy,1=ycy,1=softcy,1=ecy,1=yucy,1=yacy,2=iocy,1=djcy,1=gjcy,1=jukcy,1=dscy
|
|
60
|
+
1=iukcy,1=yicy,1=jsercy,1=ljcy,1=njcy,1=tshcy,1=kjcy,2=ubrcy,1=dzcy,5gj=ensp,1=emsp,1=emsp13,1=emsp14,2=numsp
|
|
61
|
+
1=puncsp,1=ThinSpace thinsp,1=VeryThinSpace hairsp
|
|
62
|
+
1=NegativeMediumSpace NegativeThickSpace NegativeThinSpace NegativeVeryThinSpace ZeroWidthSpace,1=zwnj,1=zwj,1=lrm
|
|
63
|
+
1=rlm,1=dash hyphen,3=ndash,1=mdash,1=horbar,1=Verbar Vert,2=OpenCurlyQuote lsquo,1=CloseCurlyQuote rsquo rsquor
|
|
64
|
+
1=lsquor sbquo,2=OpenCurlyDoubleQuote ldquo,1=CloseCurlyDoubleQuote rdquo rdquor,1=bdquo ldquor,2=dagger
|
|
65
|
+
1=Dagger ddagger,1=bull bullet,3=nldr,1=hellip mldr,a=permil,1=pertenk,1=prime,1=Prime,1=tprime,1=backprime bprime
|
|
66
|
+
4=lsaquo,1=rsaquo,4=OverBar oline,3=caret,2=hybull,1=frasl,b=bsemi,8=qprime,8=MediumSpace,0+6bu=ThickSpace,1=NoBreak
|
|
67
|
+
1=ApplyFunction af,1=InvisibleTimes it,1=InvisibleComma ic,21=euro,1b=TripleDot tdot,1=DotDot,12=Copf complexes
|
|
68
|
+
3=incare,5=gscr,1=HilbertSpace Hscr hamilt,1=Hfr Poincareplane,1=Hopf quaternions,1=planckh
|
|
69
|
+
1=hbar hslash planck plankv,1=Iscr imagline,1=Ifr Im image imagpart,1=Laplacetrf Lscr lagran,1=ell,2=Nopf naturals
|
|
70
|
+
1=numero,1=copysr,1=weierp wp,1=Popf primes,1=Qopf rationals,1=Rscr realine,1=Re Rfr real realpart,1=Ropf reals,1=rx
|
|
71
|
+
4=TRADE trade,2=Zopf integers,3=mho,1=Zfr zeetrf,1=iiota,3=Bernoullis Bscr bernou,1=Cayleys Cfr,2=escr
|
|
72
|
+
1=Escr expectation,1=Fouriertrf Fscr,2=Mellintrf Mscr phmmat,1=order orderof oscr,1=alefsym aleph,1=beth,1=gimel
|
|
73
|
+
1=daleth,d=CapitalDifferentialD DD,1=DifferentialD dd,1=ExponentialE ee exponentiale,1=ImaginaryI ii,b=frac13
|
|
74
|
+
1=frac23,1=frac15,1=frac25,1=frac35,1=frac45,1=frac16,1=frac56,1=frac18,1=frac38,1=frac58,1=frac78
|
|
75
|
+
1e=LeftArrow ShortLeftArrow larr leftarrow slarr,1=ShortUpArrow UpArrow uarr uparrow
|
|
76
|
+
1=RightArrow ShortRightArrow rarr rightarrow srarr,1=DownArrow ShortDownArrow darr downarrow
|
|
77
|
+
1=LeftRightArrow harr leftrightarrow,1=UpDownArrow updownarrow varr,1=UpperLeftArrow nwarr nwarrow
|
|
78
|
+
1=UpperRightArrow nearr nearrow,1=LowerRightArrow searr searrow,1=LowerLeftArrow swarr swarrow,1=nlarr nleftarrow
|
|
79
|
+
1=nrarr nrightarrow,2=rarrw rightsquigarrow,0+mw=nrarrw,1=Larr twoheadleftarrow,1=Uarr,1=Rarr twoheadrightarrow
|
|
80
|
+
1=Darr,1=larrtl leftarrowtail,1=rarrtl rightarrowtail,1=LeftTeeArrow mapstoleft,1=UpTeeArrow mapstoup
|
|
81
|
+
1=RightTeeArrow map mapsto,1=DownTeeArrow mapstodown,2=hookleftarrow larrhk,1=hookrightarrow rarrhk
|
|
82
|
+
1=larrlp looparrowleft,1=looparrowright rarrlp,1=harrw leftrightsquigarrow,1=nharr nleftrightarrow,2=Lsh lsh
|
|
83
|
+
1=Rsh rsh,1=ldsh,1=rdsh,2=crarr,1=cularr curvearrowleft,1=curarr curvearrowright,3=circlearrowleft olarr
|
|
84
|
+
1=circlearrowright orarr,1=LeftVector leftharpoonup lharu,1=DownLeftVector leftharpoondown lhard
|
|
85
|
+
1=RightUpVector uharr upharpoonright,1=LeftUpVector uharl upharpoonleft,1=RightVector rharu rightharpoonup
|
|
86
|
+
1=DownRightVector rhard rightharpoondown,1=RightDownVector dharr downharpoonright
|
|
87
|
+
1=LeftDownVector dharl downharpoonleft,1=RightArrowLeftArrow rightleftarrows rlarr,1=UpArrowDownArrow udarr
|
|
88
|
+
1=LeftArrowRightArrow leftrightarrows lrarr,1=leftleftarrows llarr,1=upuparrows uuarr,1=rightrightarrows rrarr
|
|
89
|
+
1=ddarr downdownarrows,1=ReverseEquilibrium leftrightharpoons lrhar,1=Equilibrium rightleftharpoons rlhar
|
|
90
|
+
1=nLeftarrow nlArr,1=nLeftrightarrow nhArr,1=nRightarrow nrArr,1=DoubleLeftArrow Leftarrow lArr
|
|
91
|
+
1=DoubleUpArrow Uparrow uArr,1=DoubleRightArrow Implies Rightarrow rArr,1=DoubleDownArrow Downarrow dArr
|
|
92
|
+
1=DoubleLeftRightArrow Leftrightarrow hArr iff,1=DoubleUpDownArrow Updownarrow vArr,1=nwArr,1=neArr,1=seArr,1=swArr
|
|
93
|
+
1=Lleftarrow lAarr,1=Rrightarrow rAarr,2=zigrarr,7=LeftArrowBar larrb,1=RightArrowBar rarrb,g=DownArrowUpArrow duarr
|
|
94
|
+
8=loarr,1=roarr,1=hoarr,1=ForAll forall,1=comp complement,1=PartialD part,0+mw=npart,1=Exists exist
|
|
95
|
+
1=NotExists nexist nexists,1=empty emptyset emptyv varnothing,2=Del nabla,1=Element in isin isinv
|
|
96
|
+
1=NotElement notin notinva,2=ReverseElement SuchThat ni niv,1=NotReverseElement notni notniva,3=Product prod
|
|
97
|
+
1=Coproduct coprod,1=Sum sum,1=minus,1=MinusPlus mnplus mp,1=dotplus plusdo
|
|
98
|
+
2=Backslash setminus setmn smallsetminus ssetmn,1=lowast,1=SmallCircle compfn,2=Sqrt radic
|
|
99
|
+
3=Proportional prop propto varpropto vprop,1=infin,1=angrt,1=ang angle,0+6he=nang,1=angmsd measuredangle,1=angsph
|
|
100
|
+
1=VerticalBar mid shortmid smid,1=NotVerticalBar nmid nshortmid nsmid
|
|
101
|
+
1=DoubleVerticalBar par parallel shortparallel spar,1=NotDoubleVerticalBar npar nparallel nshortparallel nspar
|
|
102
|
+
1=and wedge,1=or vee,1=cap,0+1e68=caps,1=cup,0+1e68=cups,1=Integral int,1=Int,1=iiint tint
|
|
103
|
+
1=ContourIntegral conint oint,1=Conint DoubleContourIntegral,1=Cconint,1=cwint,1=ClockwiseContourIntegral cwconint
|
|
104
|
+
1=CounterClockwiseContourIntegral awconint,1=Therefore there4 therefore,1=Because becaus because,1=ratio
|
|
105
|
+
1=Colon Proportion,1=dotminus minusd,2=mDDot,1=homtht,1=Tilde sim thicksim thksim,0+6he=nvsim,1=backsim bsim
|
|
106
|
+
0+mp=race,1=ac mstpos,0+mr=acE,1=acd,1=VerticalTilde wr wreath,1=NotTilde nsim,1=EqualTilde eqsim esim
|
|
107
|
+
0+mw=NotEqualTilde nesim,1=TildeEqual sime simeq,1=NotTildeEqual nsime nsimeq,1=TildeFullEqual cong,1=simne
|
|
108
|
+
1=NotTildeFullEqual ncong,1=TildeTilde ap approx asymp thickapprox thkap,1=NotTildeTilde nap napprox,1=ape approxeq
|
|
109
|
+
1=apid,0+mw=napid,1=backcong bcong,1=CupCap asympeq,0+6he=nvap,1=Bumpeq HumpDownHump bump,0+mw=NotHumpDownHump nbump
|
|
110
|
+
1=HumpEqual bumpe bumpeq,0+mw=NotHumpEqual nbumpe,1=DotEqual doteq esdot,0+mw=nedot,1=doteqdot eDot
|
|
111
|
+
1=efDot fallingdotseq,1=erDot risingdotseq,1=Assign colone coloneq,1=ecolon eqcolon,1=ecir eqcirc,1=circeq cire
|
|
112
|
+
2=wedgeq,1=veeeq,2=triangleq trie,3=equest questeq,1=NotEqual ne,1=Congruent equiv,0+6hx=bnequiv
|
|
113
|
+
1=NotCongruent nequiv,2=le leq,0+6he=nvle,1=GreaterEqual ge geq,0+6he=nvge,1=LessFullEqual lE leqq,0+mw=nlE nleqq
|
|
114
|
+
1=GreaterFullEqual gE geqq,0+mw=NotGreaterFullEqual ngE ngeqq,1=lnE lneqq,0+1e68=lvertneqq lvnE,1=gnE gneqq
|
|
115
|
+
0+1e68=gvertneqq gvnE,1=Lt NestedLessLess ll,0+mw=NotLessLess nLtv,0+6he=nLt,1=Gt NestedGreaterGreater gg
|
|
116
|
+
0+mw=NotGreaterGreater nGtv,0+6he=nGt,1=between twixt,1=NotCupCap,1=NotLess nless nlt,1=NotGreater ngt ngtr
|
|
117
|
+
1=NotLessEqual nle nleq,1=NotGreaterEqual nge ngeq,1=LessTilde lesssim lsim,1=GreaterTilde gsim gtrsim
|
|
118
|
+
1=NotLessTilde nlsim,1=NotGreaterTilde ngsim,1=LessGreater lessgtr lg,1=GreaterLess gl gtrless,1=NotLessGreater ntlg
|
|
119
|
+
1=NotGreaterLess ntgl,1=Precedes pr prec,1=Succeeds sc succ,1=PrecedesSlantEqual prcue preccurlyeq
|
|
120
|
+
1=SucceedsSlantEqual sccue succcurlyeq,1=PrecedesTilde precsim prsim,1=SucceedsTilde scsim succsim
|
|
121
|
+
0+mw=NotSucceedsTilde,1=NotPrecedes npr nprec,1=NotSucceeds nsc nsucc,1=sub subset,0+6he=NotSubset nsubset vnsub
|
|
122
|
+
1=Superset sup supset,0+6he=NotSuperset nsupset vnsup,1=nsub,1=nsup,1=SubsetEqual sube subseteq
|
|
123
|
+
1=SupersetEqual supe supseteq,1=NotSubsetEqual nsube nsubseteq,1=NotSupersetEqual nsupe nsupseteq,1=subne subsetneq
|
|
124
|
+
0+1e68=varsubsetneq vsubne,1=supne supsetneq,0+1e68=varsupsetneq vsupne,2=cupdot,1=UnionPlus uplus
|
|
125
|
+
1=SquareSubset sqsub sqsubset,0+mw=NotSquareSubset,1=SquareSuperset sqsup sqsupset,0+mw=NotSquareSuperset
|
|
126
|
+
1=SquareSubsetEqual sqsube sqsubseteq,1=SquareSupersetEqual sqsupe sqsupseteq,1=SquareIntersection sqcap
|
|
127
|
+
0+1e68=sqcaps,1=SquareUnion sqcup,0+1e68=sqcups,1=CirclePlus oplus,1=CircleMinus ominus,1=CircleTimes otimes,1=osol
|
|
128
|
+
1=CircleDot odot,1=circledcirc ocir,1=circledast oast,2=circleddash odash,1=boxplus plusb,1=boxminus minusb
|
|
129
|
+
1=boxtimes timesb,1=dotsquare sdotb,1=RightTee vdash,1=LeftTee dashv,1=DownTee top,1=UpTee bot bottom perp,2=models
|
|
130
|
+
1=DoubleRightTee vDash,1=Vdash,1=Vvdash,1=VDash,1=nvdash,1=nvDash,1=nVdash,1=nVDash,1=prurel
|
|
131
|
+
2=LeftTriangle vartriangleleft vltri,1=RightTriangle vartriangleright vrtri,1=LeftTriangleEqual ltrie trianglelefteq
|
|
132
|
+
0+6he=nvltrie,1=RightTriangleEqual rtrie trianglerighteq,0+6he=nvrtrie,1=origof,1=imof,1=multimap mumap,1=hercon
|
|
133
|
+
1=intcal intercal,1=veebar,2=barvee,1=angrtvb,1=lrtri,1=Wedge bigwedge xwedge,1=Vee bigvee xvee
|
|
134
|
+
1=Intersection bigcap xcap,1=Union bigcup xcup,1=Diamond diam diamond,1=sdot,1=Star sstarf,1=divideontimes divonx
|
|
135
|
+
1=bowtie,1=ltimes,1=rtimes,1=leftthreetimes lthree,1=rightthreetimes rthree,1=backsimeq bsime,1=curlyvee cuvee
|
|
136
|
+
1=curlywedge cuwed,1=Sub Subset,1=Sup Supset,1=Cap,1=Cup,1=fork pitchfork,1=epar,1=lessdot ltdot,1=gtdot gtrdot,1=Ll
|
|
137
|
+
0+mw=nLl,1=Gg ggg,0+mw=nGg,1=LessEqualGreater leg lesseqgtr,0+1e68=lesg,1=GreaterEqualLess gel gtreqless,0+1e68=gesl
|
|
138
|
+
3=cuepr curlyeqprec,1=cuesc curlyeqsucc,1=NotPrecedesSlantEqual nprcue,1=NotSucceedsSlantEqual nsccue
|
|
139
|
+
1=NotSquareSubsetEqual nsqsube,1=NotSquareSupersetEqual nsqsupe,3=lnsim,1=gnsim,1=precnsim prnsim,1=scnsim succnsim
|
|
140
|
+
1=NotLeftTriangle nltri ntriangleleft,1=NotRightTriangle nrtri ntriangleright
|
|
141
|
+
1=NotLeftTriangleEqual nltrie ntrianglelefteq,1=NotRightTriangleEqual nrtrie ntrianglerighteq,1=vellip,1=ctdot
|
|
142
|
+
1=utdot,1=dtdot,1=disin,1=isinsv,1=isins,1=isindot,0+mw=notindot,1=notinvc,1=notinvb,2=isinE,0+mw=notinE,1=nisd
|
|
143
|
+
1=xnis,1=nis,1=notnivc,1=notnivb,7=barwed barwedge,1=Barwed doublebarwedge,2=LeftCeiling lceil,1=RightCeiling rceil
|
|
144
|
+
1=LeftFloor lfloor,1=RightFloor rfloor,1=drcrop,1=dlcrop,1=urcrop,1=ulcrop,1=bnot,2=profline,1=profsurf,2=telrec
|
|
145
|
+
1=target,6=ulcorn ulcorner,1=urcorn urcorner,1=dlcorn llcorner,1=drcorn lrcorner,3=frown sfrown,1=smile ssmile
|
|
146
|
+
a=cylcty,1=profalar,8=topbot,7=ovbar,2=solbar,1p=angzarr,1g=lmoust lmoustache,1=rmoust rmoustache,3=OverBracket tbrk
|
|
147
|
+
1=UnderBracket bbrk,1=bbrktbrk,12=OverParenthesis,1=UnderParenthesis,1=OverBrace,1=UnderBrace,3=trpezium,5=elinters
|
|
148
|
+
1o=blank,4l=circledS oS,1k=HorizontalLine boxh,2=boxv,a=boxdr,4=boxdl,4=boxur,4=boxul,4=boxvr,8=boxvl,8=boxhd
|
|
149
|
+
8=boxhu,8=boxvh,k=boxH,1=boxV,1=boxdR,1=boxDr,1=boxDR,1=boxdL,1=boxDl,1=boxDL,1=boxuR,1=boxUr,1=boxUR,1=boxuL
|
|
150
|
+
1=boxUl,1=boxUL,1=boxvR,1=boxVr,1=boxVR,1=boxvL,1=boxVl,1=boxVL,1=boxHd,1=boxhD,1=boxHD,1=boxHu,1=boxhU,1=boxHU
|
|
151
|
+
1=boxvH,1=boxVh,1=boxVH,k=uhblk,4=lhblk,4=block,9=blk14,1=blk12,1=blk34,e=Square squ square
|
|
152
|
+
9=FilledVerySmallSquare blacksquare squarf squf,1=EmptyVerySmallSquare,2=rect,1=marker,3=fltns,2=bigtriangleup xutri
|
|
153
|
+
1=blacktriangle utrif,1=triangle utri,3=blacktriangleright rtrif,1=rtri triangleright,4=bigtriangledown xdtri
|
|
154
|
+
1=blacktriangledown dtrif,1=dtri triangledown,3=blacktriangleleft ltrif,1=ltri triangleleft,7=loz lozenge,1=cir
|
|
155
|
+
x=tridot,3=bigcirc xcirc,9=ultri,1=urtri,1=lltri,1=EmptySmallSquare,1=FilledSmallSquare,9=bigstar starf,1=star
|
|
156
|
+
8=phone,1e=female,2=male,u=spades spadesuit,3=clubs clubsuit,2=hearts heartsuit,1=diamondsuit diams,4=sung,3=flat
|
|
157
|
+
1=natur natural,1=sharp,4k=check checkmark,4=cross,9=malt maltese,m=sext,y=VerticalSeparator,q=lbbrk,1=rbbrk
|
|
158
|
+
2d=bsolhsub,1=suphsol,t=LeftDoubleBracket lobrk,1=RightDoubleBracket robrk,1=LeftAngleBracket lang langle
|
|
159
|
+
1=RightAngleBracket rang rangle,1=Lang,1=Rang,1=loang,1=roang,8=LongLeftArrow longleftarrow xlarr
|
|
160
|
+
1=LongRightArrow longrightarrow xrarr,1=LongLeftRightArrow longleftrightarrow xharr
|
|
161
|
+
1=DoubleLongLeftArrow Longleftarrow xlArr,1=DoubleLongRightArrow Longrightarrow xrArr
|
|
162
|
+
1=DoubleLongLeftRightArrow Longleftrightarrow xhArr,2=longmapsto xmap,3=dzigrarr,77=nvlArr,1=nvrArr,1=nvHarr,1=Map
|
|
163
|
+
7=lbarr,1=bkarow rbarr,1=lBarr,1=dbkarow rBarr,1=RBarr drbkarow,1=DDotrahd,1=UpArrowBar,1=DownArrowBar,3=Rarrtl
|
|
164
|
+
3=latail,1=ratail,1=lAtail,1=rAtail,1=larrfs,1=rarrfs,1=larrbfs,1=rarrbfs,3=nwarhk,1=nearhk,1=hksearow searhk
|
|
165
|
+
1=hkswarow swarhk,1=nwnear,1=nesear toea,1=seswar tosa,1=swnwar,9=rarrc,0+mw=nrarrc,2=cudarrr,1=ldca,1=rdca
|
|
166
|
+
1=cudarrl,1=larrpl,3=curarrm,1=cularrp,8=rarrpl,3=harrcir,1=Uarrocir,1=lurdshar,1=ldrushar,3=LeftRightVector
|
|
167
|
+
1=RightUpDownVector,1=DownLeftRightVector,1=LeftUpDownVector,1=LeftVectorBar,1=RightVectorBar,1=RightUpVectorBar
|
|
168
|
+
1=RightDownVectorBar,1=DownLeftVectorBar,1=DownRightVectorBar,1=LeftUpVectorBar,1=LeftDownVectorBar,1=LeftTeeVector
|
|
169
|
+
1=RightTeeVector,1=RightUpTeeVector,1=RightDownTeeVector,1=DownLeftTeeVector,1=DownRightTeeVector,1=LeftUpTeeVector
|
|
170
|
+
1=LeftDownTeeVector,1=lHar,1=uHar,1=rHar,1=dHar,1=luruhar,1=ldrdhar,1=ruluhar,1=rdldhar,1=lharul,1=llhard,1=rharul
|
|
171
|
+
1=lrhard,1=UpEquilibrium udhar,1=ReverseUpEquilibrium duhar,1=RoundImplies,1=erarr,1=simrarr,1=larrsim,1=rarrsim
|
|
172
|
+
1=rarrap,1=ltlarr,2=gtrarr,1=subrarr,2=suplarr,1=lfisht,1=rfisht,1=ufisht,1=dfisht,6=lopar,1=ropar,5=lbrke,1=rbrke
|
|
173
|
+
1=lbrkslu,1=rbrksld,1=lbrksld,1=rbrkslu,1=langd,1=rangd,1=lparlt,1=rpargt,1=gtlPar,1=ltrPar,4=vzigzag,2=vangrt
|
|
174
|
+
1=angrtvbd,7=ange,1=range,1=dwangle,1=uwangle,1=angmsdaa,1=angmsdab,1=angmsdac,1=angmsdad,1=angmsdae,1=angmsdaf
|
|
175
|
+
1=angmsdag,1=angmsdah,1=bemptyv,1=demptyv,1=cemptyv,1=raemptyv,1=laemptyv,1=ohbar,1=omid,1=opar,2=operp,2=olcross
|
|
176
|
+
1=odsold,2=olcir,1=ofcir,1=olt,1=ogt,1=cirscir,1=cirE,1=solb,1=bsolb,4=boxbox,4=trisb,1=rtriltri,1=LeftTriangleBar
|
|
177
|
+
0+mw=NotLeftTriangleBar,1=RightTriangleBar,0+mw=NotRightTriangleBar,c=iinfin,1=infintie,1=nvinfin,5=eparsl
|
|
178
|
+
1=smeparsl,1=eqvparsl,6=blacklozenge lozf,9=RuleDelayed,2=dsol,a=bigodot xodot,1=bigoplus xoplus,1=bigotimes xotime
|
|
179
|
+
2=biguplus xuplus,2=bigsqcup xsqcup,6=iiiint qint,1=fpartint,3=cirfnint,1=awint,1=rppolint,1=scpolint,1=npolint
|
|
180
|
+
1=pointint,1=quatint,1=intlarhk,b=pluscir,1=plusacir,1=simplus,1=plusdu,1=plussim,1=plustwo,2=mcomma,1=minusdu
|
|
181
|
+
3=loplus,1=roplus,1=Cross,1=timesd,1=timesbar,2=smashp,1=lotimes,1=rotimes,1=otimesas,1=Otimes,1=odiv,1=triplus
|
|
182
|
+
1=triminus,1=tritime,1=intprod iprod,3=amalg,1=capdot,2=ncup,1=ncap,1=capand,1=cupor,1=cupcap,1=capcup,1=cupbrcap
|
|
183
|
+
1=capbrcup,1=cupcup,1=capcap,1=ccups,1=ccaps,3=ccupssm,3=And,1=Or,1=andand,1=oror,1=orslope,1=andslope,2=andv,1=orv
|
|
184
|
+
1=andd,1=ord,2=wedbar,7=sdote,4=simdot,3=congdot,0+mw=ncongdot,1=easter,1=apacir,1=apE,0+mw=napE,1=eplus,1=pluse
|
|
185
|
+
1=Esim,1=Colone,1=Equal,2=ddotseq eDDot,1=equivDD,1=ltcir,1=gtcir,1=ltquest,1=gtquest,1=LessSlantEqual leqslant les
|
|
186
|
+
0+mw=NotLessSlantEqual nleqslant nles,1=GreaterSlantEqual geqslant ges,0+mw=NotGreaterSlantEqual ngeqslant nges
|
|
187
|
+
1=lesdot,1=gesdot,1=lesdoto,1=gesdoto,1=lesdotor,1=gesdotol,1=lap lessapprox,1=gap gtrapprox,1=lne lneq,1=gne gneq
|
|
188
|
+
1=lnap lnapprox,1=gnap gnapprox,1=lEg lesseqqgtr,1=gEl gtreqqless,1=lsime,1=gsime,1=lsimg,1=gsiml,1=lgE,1=glE
|
|
189
|
+
1=lesges,1=gesles,1=els eqslantless,1=egs eqslantgtr,1=elsdot,1=egsdot,1=el,1=eg,3=siml,1=simg,1=simlE,1=simgE
|
|
190
|
+
1=LessLess,0+mw=NotNestedLessLess,1=GreaterGreater,0+mw=NotNestedGreaterGreater,2=glj,1=gla,1=ltcc,1=gtcc,1=lescc
|
|
191
|
+
1=gescc,1=smt,1=lat,1=smte,0+1e68=smtes,1=late,0+1e68=lates,1=bumpE,1=PrecedesEqual pre preceq
|
|
192
|
+
0+mw=NotPrecedesEqual npre npreceq,1=SucceedsEqual sce succeq,0+mw=NotSucceedsEqual nsce nsucceq,3=prE,1=scE
|
|
193
|
+
1=precneqq prnE,1=scnE succneqq,1=prap precapprox,1=scap succapprox,1=precnapprox prnap,1=scnap succnapprox,1=Pr
|
|
194
|
+
1=Sc,1=subdot,1=supdot,1=subplus,1=supplus,1=submult,1=supmult,1=subedot,1=supedot,1=subE subseteqq
|
|
195
|
+
0+mw=nsubE nsubseteqq,1=supE supseteqq,0+mw=nsupE nsupseteqq,1=subsim,1=supsim,3=subnE subsetneqq
|
|
196
|
+
0+1e68=varsubsetneqq vsubnE,1=supnE supsetneqq,0+1e68=varsupsetneqq vsupnE,3=csub,1=csup,1=csube,1=csupe,1=subsup
|
|
197
|
+
1=supsub,1=subsub,1=supsup,1=suphsub,1=supdsub,1=forkv,1=topfork,1=mlcp,9=Dashv DoubleLeftTee,2=Vdashl,1=Barv,1=vBar
|
|
198
|
+
1=vBarv,2=Vbar,1=Not,1=bNot,1=rnmid,1=cirmid,1=midcir,1=topcir,1=nhpar,1=parsim,a=parsl,0+6hx=nparsl,1537=fflig
|
|
199
|
+
1=filig,1=fllig,1=ffilig,1=ffllig,16zc=Ascr,2=Cscr,1=Dscr,3=Gscr,3=Jscr,1=Kscr,3=Nscr,1=Oscr,1=Pscr,1=Qscr,2=Sscr
|
|
200
|
+
1=Tscr,1=Uscr,1=Vscr,1=Wscr,1=Xscr,1=Yscr,1=Zscr,1=ascr,1=bscr,1=cscr,1=dscr,2=fscr,2=hscr,1=iscr,1=jscr,1=kscr
|
|
201
|
+
1=lscr,1=mscr,1=nscr,2=pscr,1=qscr,1=rscr,1=sscr,1=tscr,1=uscr,1=vscr,1=wscr,1=xscr,1=yscr,1=zscr,1h=Afr,1=Bfr,2=Dfr
|
|
202
|
+
1=Efr,1=Ffr,1=Gfr,3=Jfr,1=Kfr,1=Lfr,1=Mfr,1=Nfr,1=Ofr,1=Pfr,1=Qfr,2=Sfr,1=Tfr,1=Ufr,1=Vfr,1=Wfr,1=Xfr,1=Yfr,2=afr
|
|
203
|
+
1=bfr,1=cfr,1=dfr,1=efr,1=ffr,1=gfr,1=hfr,1=ifr,1=jfr,1=kfr,1=lfr,1=mfr,1=nfr,1=ofr,1=pfr,1=qfr,1=rfr,1=sfr,1=tfr
|
|
204
|
+
1=ufr,1=vfr,1=wfr,1=xfr,1=yfr,1=zfr,1=Aopf,1=Bopf,2=Dopf,1=Eopf,1=Fopf,1=Gopf,2=Iopf,1=Jopf,1=Kopf,1=Lopf,1=Mopf
|
|
205
|
+
2=Oopf,4=Sopf,1=Topf,1=Uopf,1=Vopf,1=Wopf,1=Xopf,1=Yopf,2=aopf,1=bopf,1=copf,1=dopf,1=eopf,1=fopf,1=gopf,1=hopf
|
|
206
|
+
1=iopf,1=jopf,1=kopf,1=lopf,1=mopf,1=nopf,1=oopf,1=popf,1=qopf,1=ropf,1=sopf,1=topf,1=uopf,1=vopf,1=wopf,1=xopf
|
|
207
|
+
1=yopf,1=zopf`;
|
package/src/html.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface HtmlScan {
|
|
|
22
22
|
/**
|
|
23
23
|
* The text of the HTML outside the tags, the comments and the skipped elements. Each tag, comment and skipped element
|
|
24
24
|
* gives one space, so two words in two elements stay two words. The white space and the character references stay as in the HTML.
|
|
25
|
+
* The function `decodeReferences` of the entry `./references` decodes the character references.
|
|
25
26
|
*/
|
|
26
27
|
readonly text: string;
|
|
27
28
|
/** The start tags outside the comments and the skipped elements, in the order of the HTML. The start tag of a skipped element is in the list. */
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module decodes the character references of HTML content, with no DOM. The table of the named references has
|
|
3
|
+
* 2231 names. It is in a separate entry, so a bundle that only scans HTML does not get the table.
|
|
4
|
+
*/
|
|
5
|
+
import { NAMED_REFERENCES } from "./html-references.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The values of the code points 0x80 to 0x9F in a numeric character reference, from the table of the standard. They are
|
|
9
|
+
* the characters of windows-1252. The five code points that windows-1252 does not have stay as they are.
|
|
10
|
+
*/
|
|
11
|
+
const C1_VALUES =
|
|
12
|
+
"\u20AC\u0081\u201A\u0192\u201E\u2026\u2020\u2021\u02C6\u2030\u0160\u2039\u0152\u008D\u017D\u008F" +
|
|
13
|
+
"\u0090\u2018\u2019\u201C\u201D\u2022\u2013\u2014\u02DC\u2122\u0161\u203A\u0153\u009D\u017E\u0178";
|
|
14
|
+
|
|
15
|
+
/** The value of each named character reference. A name with `;` is a key, and a legacy name is also a key with no `;`. */
|
|
16
|
+
let named: Map<string, string> | undefined;
|
|
17
|
+
/** The length of the longest name, with no `;`. */
|
|
18
|
+
let longestName = 0;
|
|
19
|
+
/** The length of the longest legacy name. */
|
|
20
|
+
let longestLegacy = 0;
|
|
21
|
+
|
|
22
|
+
/** This function reads the table of the named character references one time, when the decoder first needs it. */
|
|
23
|
+
function namedReferences(): Map<string, string> {
|
|
24
|
+
if (named !== undefined) return named;
|
|
25
|
+
const table = new Map<string, string>();
|
|
26
|
+
let point = 0;
|
|
27
|
+
for (const group of NAMED_REFERENCES.split(/[,\n]/)) {
|
|
28
|
+
const equals = group.indexOf("=");
|
|
29
|
+
const [first = "", second] = group.slice(0, equals).split("+");
|
|
30
|
+
point += parseInt(first, 36);
|
|
31
|
+
const value = second === undefined ? String.fromCodePoint(point) : String.fromCodePoint(point, parseInt(second, 36));
|
|
32
|
+
for (const entry of group.slice(equals + 1).split(" ")) {
|
|
33
|
+
const legacy = entry.endsWith("*");
|
|
34
|
+
const name = legacy ? entry.slice(0, -1) : entry;
|
|
35
|
+
table.set(`${name};`, value);
|
|
36
|
+
longestName = Math.max(longestName, name.length);
|
|
37
|
+
if (legacy) {
|
|
38
|
+
table.set(name, value);
|
|
39
|
+
longestLegacy = Math.max(longestLegacy, name.length);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
named = table;
|
|
44
|
+
return table;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** This function tells if a code unit is an ASCII letter or an ASCII digit. */
|
|
48
|
+
const isAlphanumeric = (code: number): boolean => (code >= 0x30 && code <= 0x39) || ((code | 0x20) >= 0x61 && (code | 0x20) <= 0x7a);
|
|
49
|
+
|
|
50
|
+
/** This function gives the value of a code unit as a decimal or a hexadecimal digit, or -1 for a different code unit. */
|
|
51
|
+
function digitOf(code: number, hex: boolean): number {
|
|
52
|
+
if (code >= 0x30 && code <= 0x39) return code - 0x30;
|
|
53
|
+
const lower = code | 0x20;
|
|
54
|
+
return hex && lower >= 0x61 && lower <= 0x66 ? lower - 0x61 + 10 : -1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A character reference that the decoder found: its value, and the index after its last character. */
|
|
58
|
+
interface Reference {
|
|
59
|
+
readonly value: string;
|
|
60
|
+
readonly end: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* This function reads the numeric character reference at the "&" at `amp`, with the fixes of the standard. It gives
|
|
65
|
+
* undefined when no digit follows "&#" or "&#x".
|
|
66
|
+
*/
|
|
67
|
+
function readNumeric(text: string, amp: number): Reference | undefined {
|
|
68
|
+
let at = amp + 2;
|
|
69
|
+
const hex = (text.charCodeAt(at) | 0x20) === 0x78;
|
|
70
|
+
if (hex) at += 1;
|
|
71
|
+
const start = at;
|
|
72
|
+
let point = 0;
|
|
73
|
+
for (let digit = digitOf(text.charCodeAt(at), hex); digit !== -1; digit = digitOf(text.charCodeAt(at), hex)) {
|
|
74
|
+
// A value above 0x10FFFF stays at 0x110000. Thus a long run of digits does not make a number that is too large.
|
|
75
|
+
point = Math.min(point * (hex ? 16 : 10) + digit, 0x110000);
|
|
76
|
+
at += 1;
|
|
77
|
+
}
|
|
78
|
+
if (at === start) return undefined;
|
|
79
|
+
if (text.charCodeAt(at) === 0x3b) at += 1;
|
|
80
|
+
if (point === 0 || point > 0x10ffff || (point >= 0xd800 && point <= 0xdfff)) return { value: "\uFFFD", end: at };
|
|
81
|
+
if (point >= 0x80 && point <= 0x9f) return { value: C1_VALUES.charAt(point - 0x80), end: at };
|
|
82
|
+
return { value: String.fromCodePoint(point), end: at };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* This function reads the named character reference at the "&" at `amp`. The longest name wins. It gives undefined when
|
|
87
|
+
* no name of the table follows the "&".
|
|
88
|
+
*/
|
|
89
|
+
function readNamed(text: string, amp: number): Reference | undefined {
|
|
90
|
+
const from = amp + 1;
|
|
91
|
+
if (!isAlphanumeric(text.charCodeAt(from))) return undefined;
|
|
92
|
+
const table = namedReferences();
|
|
93
|
+
// A run of letters and digits that is longer than the longest name is not a name. Thus each "&" reads few characters.
|
|
94
|
+
let at = from;
|
|
95
|
+
while (at - from <= longestName && isAlphanumeric(text.charCodeAt(at))) at += 1;
|
|
96
|
+
if (text.charCodeAt(at) === 0x3b) {
|
|
97
|
+
const value = table.get(text.slice(from, at + 1));
|
|
98
|
+
if (value !== undefined) return { value, end: at + 1 };
|
|
99
|
+
}
|
|
100
|
+
// With no `;`, only a legacy name can match: the longest legacy name at the start of the run.
|
|
101
|
+
for (let end = Math.min(at, from + longestLegacy); end > from; end -= 1) {
|
|
102
|
+
const value = table.get(text.slice(from, end));
|
|
103
|
+
if (value !== undefined) return { value, end };
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* This function decodes the character references of a text, as the tokenizer of the HTML Living Standard does in the
|
|
110
|
+
* content of an element. Use it on the `text` of a scan of `scanHtml`.
|
|
111
|
+
*
|
|
112
|
+
* - A named reference gets its value from the table of the standard. The longest name wins.
|
|
113
|
+
* - A legacy name, for example `&` or `¬`, is also correct with no semicolon. Thus `¬it;` gives `¬it;`.
|
|
114
|
+
* - A decimal or hexadecimal reference, for example `’` or `’`, gives its code point. The semicolon is optional.
|
|
115
|
+
* - The value 0, a surrogate and a value above `0x10FFFF` give U+FFFD.
|
|
116
|
+
* - The values `0x80` to `0x9F` give the characters of windows-1252, from the table of the standard.
|
|
117
|
+
* - An ampersand with no reference after it stays as text. The function changes no other character.
|
|
118
|
+
*
|
|
119
|
+
* The function does not throw, and it is linear in the length of the text. The result is not longer than the text.
|
|
120
|
+
*
|
|
121
|
+
* @param text - The text of HTML content, with its character references.
|
|
122
|
+
* @returns The text with the value of each character reference in place of the reference.
|
|
123
|
+
*/
|
|
124
|
+
export function decodeReferences(text: string): string {
|
|
125
|
+
let amp = text.indexOf("&");
|
|
126
|
+
if (amp === -1) return text;
|
|
127
|
+
const parts: string[] = [];
|
|
128
|
+
let at = 0;
|
|
129
|
+
while (amp !== -1) {
|
|
130
|
+
const reference = text.charCodeAt(amp + 1) === 0x23 ? readNumeric(text, amp) : readNamed(text, amp);
|
|
131
|
+
if (reference === undefined) amp = text.indexOf("&", amp + 1);
|
|
132
|
+
else {
|
|
133
|
+
parts.push(text.slice(at, amp), reference.value);
|
|
134
|
+
at = reference.end;
|
|
135
|
+
amp = text.indexOf("&", at);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
parts.push(text.slice(at));
|
|
139
|
+
return parts.join("");
|
|
140
|
+
}
|
package/src/search.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* in any order. The case of the letters is not significant.
|
|
4
4
|
*
|
|
5
5
|
* The module also has a ranked search: the words of a text (`searchWords`), TF-IDF weights and the cosine similarity.
|
|
6
|
-
* `rankDocuments` puts the documents of a corpus in order for a query.
|
|
6
|
+
* `rankDocuments` puts the documents of a corpus in order for a query. `rankerOf` does this for many queries on one corpus.
|
|
7
|
+
* Each function has no I/O.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
/** The small final sigma. Unicode case folding changes it to the small sigma, so a word agrees in each position. */
|
|
@@ -175,7 +176,25 @@ export interface DocumentScore {
|
|
|
175
176
|
* @returns The score of each document, best first.
|
|
176
177
|
*/
|
|
177
178
|
export function rankDocuments(corpus: readonly (readonly string[])[], query: readonly string[], form: IdfForm = "plain"): DocumentScore[] {
|
|
179
|
+
return rankerOf(corpus, form)(query);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* This function makes a ranker for one corpus. It computes the IDF and the vector of each document one time. It has no I/O.
|
|
184
|
+
*
|
|
185
|
+
* - For each query, the ranker gives the same scores as `rankDocuments(corpus, query, form)`.
|
|
186
|
+
* - A query costs one vector and one cosine for each document. Use the ranker when many queries search one corpus.
|
|
187
|
+
* - The ranker keeps the vectors of the corpus at the time of the call. A later change of the corpus does not change it.
|
|
188
|
+
*
|
|
189
|
+
* @param corpus - The documents, each as a list of words.
|
|
190
|
+
* @param form - The form of the IDF. The default is `plain`.
|
|
191
|
+
* @returns A function that gives the score of each document for a query, best first.
|
|
192
|
+
*/
|
|
193
|
+
export function rankerOf(corpus: readonly (readonly string[])[], form: IdfForm = "plain"): (query: readonly string[]) => DocumentScore[] {
|
|
178
194
|
const idf = inverseDocumentFrequency(corpus, form);
|
|
179
|
-
const
|
|
180
|
-
return
|
|
195
|
+
const vectors = corpus.map((document) => termVector(document, idf));
|
|
196
|
+
return (query) => {
|
|
197
|
+
const q = termVector(query, idf);
|
|
198
|
+
return vectors.map((vector, index) => ({ index, score: cosineSimilarity(q, vector) })).sort((a, b) => b.score - a.score);
|
|
199
|
+
};
|
|
181
200
|
}
|