decode.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.xmlDecodeTree = exports.htmlDecodeTree = exports.replaceCodePoint = exports.fromCodePoint = exports.decodeCodePoint = exports.EntityDecoder = exports.DecodingMode = void 0;
  4. exports.determineBranch = determineBranch;
  5. exports.decodeHTML = decodeHTML;
  6. exports.decodeHTMLAttribute = decodeHTMLAttribute;
  7. exports.decodeHTMLStrict = decodeHTMLStrict;
  8. exports.decodeXML = decodeXML;
  9. const decode_codepoint_js_1 = require("./decode-codepoint.js");
  10. const decode_data_html_js_1 = require("./generated/decode-data-html.js");
  11. const decode_data_xml_js_1 = require("./generated/decode-data-xml.js");
  12. const bin_trie_flags_js_1 = require("./internal/bin-trie-flags.js");
  13. var CharCodes;
  14. (function (CharCodes) {
  15. CharCodes[CharCodes["NUM"] = 35] = "NUM";
  16. CharCodes[CharCodes["SEMI"] = 59] = "SEMI";
  17. CharCodes[CharCodes["EQUALS"] = 61] = "EQUALS";
  18. CharCodes[CharCodes["ZERO"] = 48] = "ZERO";
  19. CharCodes[CharCodes["NINE"] = 57] = "NINE";
  20. CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A";
  21. CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F";
  22. CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X";
  23. CharCodes[CharCodes["LOWER_Z"] = 122] = "LOWER_Z";
  24. CharCodes[CharCodes["UPPER_A"] = 65] = "UPPER_A";
  25. CharCodes[CharCodes["UPPER_F"] = 70] = "UPPER_F";
  26. CharCodes[CharCodes["UPPER_Z"] = 90] = "UPPER_Z";
  27. })(CharCodes || (CharCodes = {}));
  28. /** Bit that needs to be set to convert an upper case ASCII character to lower case */
  29. const TO_LOWER_BIT = 32;
  30. function isNumber(code) {
  31. return code >= CharCodes.ZERO && code <= CharCodes.NINE;
  32. }
  33. function isHexadecimalCharacter(code) {
  34. return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) ||
  35. (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F));
  36. }
  37. function isAsciiAlphaNumeric(code) {
  38. return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) ||
  39. (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) ||
  40. isNumber(code));
  41. }
  42. /**
  43. * Checks if the given character is a valid end character for an entity in an attribute.
  44. *
  45. * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error.
  46. * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state
  47. */
  48. function isEntityInAttributeInvalidEnd(code) {
  49. return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code);
  50. }
  51. var EntityDecoderState;
  52. (function (EntityDecoderState) {
  53. EntityDecoderState[EntityDecoderState["EntityStart"] = 0] = "EntityStart";
  54. EntityDecoderState[EntityDecoderState["NumericStart"] = 1] = "NumericStart";
  55. EntityDecoderState[EntityDecoderState["NumericDecimal"] = 2] = "NumericDecimal";
  56. EntityDecoderState[EntityDecoderState["NumericHex"] = 3] = "NumericHex";
  57. EntityDecoderState[EntityDecoderState["NamedEntity"] = 4] = "NamedEntity";
  58. })(EntityDecoderState || (EntityDecoderState = {}));
  59. var DecodingMode;
  60. (function (DecodingMode) {
  61. /** Entities in text nodes that can end with any character. */
  62. DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy";
  63. /** Only allow entities terminated with a semicolon. */
  64. DecodingMode[DecodingMode["Strict"] = 1] = "Strict";
  65. /** Entities in attributes have limitations on ending characters. */
  66. DecodingMode[DecodingMode["Attribute"] = 2] = "Attribute";
  67. })(DecodingMode || (exports.DecodingMode = DecodingMode = {}));
  68. /**
  69. * Token decoder with support of writing partial entities.
  70. */
  71. class EntityDecoder {
  72. constructor(
  73. /** The tree used to decode entities. */
  74. // biome-ignore lint/correctness/noUnusedPrivateClassMembers: False positive
  75. decodeTree,
  76. /**
  77. * The function that is called when a codepoint is decoded.
  78. *
  79. * For multi-byte named entities, this will be called multiple times,
  80. * with the second codepoint, and the same `consumed` value.
  81. *
  82. * @param codepoint The decoded codepoint.
  83. * @param consumed The number of bytes consumed by the decoder.
  84. */
  85. emitCodePoint,
  86. /** An object that is used to produce errors. */
  87. errors) {
  88. this.decodeTree = decodeTree;
  89. this.emitCodePoint = emitCodePoint;
  90. this.errors = errors;
  91. /** The current state of the decoder. */
  92. this.state = EntityDecoderState.EntityStart;
  93. /** Characters that were consumed while parsing an entity. */
  94. this.consumed = 1;
  95. /**
  96. * The result of the entity.
  97. *
  98. * Either the result index of a numeric entity, or the codepoint of a
  99. * numeric entity.
  100. */
  101. this.result = 0;
  102. /** The current index in the decode tree. */
  103. this.treeIndex = 0;
  104. /** The number of characters that were consumed in excess. */
  105. this.excess = 1;
  106. /** The mode in which the decoder is operating. */
  107. this.decodeMode = DecodingMode.Strict;
  108. }
  109. /** Resets the instance to make it reusable. */
  110. startEntity(decodeMode) {
  111. this.decodeMode = decodeMode;
  112. this.state = EntityDecoderState.EntityStart;
  113. this.result = 0;
  114. this.treeIndex = 0;
  115. this.excess = 1;
  116. this.consumed = 1;
  117. }
  118. /**
  119. * Write an entity to the decoder. This can be called multiple times with partial entities.
  120. * If the entity is incomplete, the decoder will return -1.
  121. *
  122. * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
  123. * entity is incomplete, and resume when the next string is written.
  124. *
  125. * @param input The string containing the entity (or a continuation of the entity).
  126. * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
  127. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  128. */
  129. write(input, offset) {
  130. switch (this.state) {
  131. case EntityDecoderState.EntityStart: {
  132. if (input.charCodeAt(offset) === CharCodes.NUM) {
  133. this.state = EntityDecoderState.NumericStart;
  134. this.consumed += 1;
  135. return this.stateNumericStart(input, offset + 1);
  136. }
  137. this.state = EntityDecoderState.NamedEntity;
  138. return this.stateNamedEntity(input, offset);
  139. }
  140. case EntityDecoderState.NumericStart: {
  141. return this.stateNumericStart(input, offset);
  142. }
  143. case EntityDecoderState.NumericDecimal: {
  144. return this.stateNumericDecimal(input, offset);
  145. }
  146. case EntityDecoderState.NumericHex: {
  147. return this.stateNumericHex(input, offset);
  148. }
  149. case EntityDecoderState.NamedEntity: {
  150. return this.stateNamedEntity(input, offset);
  151. }
  152. }
  153. }
  154. /**
  155. * Switches between the numeric decimal and hexadecimal states.
  156. *
  157. * Equivalent to the `Numeric character reference state` in the HTML spec.
  158. *
  159. * @param input The string containing the entity (or a continuation of the entity).
  160. * @param offset The current offset.
  161. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  162. */
  163. stateNumericStart(input, offset) {
  164. if (offset >= input.length) {
  165. return -1;
  166. }
  167. if ((input.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
  168. this.state = EntityDecoderState.NumericHex;
  169. this.consumed += 1;
  170. return this.stateNumericHex(input, offset + 1);
  171. }
  172. this.state = EntityDecoderState.NumericDecimal;
  173. return this.stateNumericDecimal(input, offset);
  174. }
  175. /**
  176. * Parses a hexadecimal numeric entity.
  177. *
  178. * Equivalent to the `Hexademical character reference state` in the HTML spec.
  179. *
  180. * @param input The string containing the entity (or a continuation of the entity).
  181. * @param offset The current offset.
  182. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  183. */
  184. stateNumericHex(input, offset) {
  185. while (offset < input.length) {
  186. const char = input.charCodeAt(offset);
  187. if (isNumber(char) || isHexadecimalCharacter(char)) {
  188. // Convert hex digit to value (0-15); 'a'/'A' -> 10.
  189. const digit = char <= CharCodes.NINE
  190. ? char - CharCodes.ZERO
  191. : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
  192. this.result = this.result * 16 + digit;
  193. this.consumed++;
  194. offset++;
  195. }
  196. else {
  197. return this.emitNumericEntity(char, 3);
  198. }
  199. }
  200. return -1; // Incomplete entity
  201. }
  202. /**
  203. * Parses a decimal numeric entity.
  204. *
  205. * Equivalent to the `Decimal character reference state` in the HTML spec.
  206. *
  207. * @param input The string containing the entity (or a continuation of the entity).
  208. * @param offset The current offset.
  209. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  210. */
  211. stateNumericDecimal(input, offset) {
  212. while (offset < input.length) {
  213. const char = input.charCodeAt(offset);
  214. if (isNumber(char)) {
  215. this.result = this.result * 10 + (char - CharCodes.ZERO);
  216. this.consumed++;
  217. offset++;
  218. }
  219. else {
  220. return this.emitNumericEntity(char, 2);
  221. }
  222. }
  223. return -1; // Incomplete entity
  224. }
  225. /**
  226. * Validate and emit a numeric entity.
  227. *
  228. * Implements the logic from the `Hexademical character reference start
  229. * state` and `Numeric character reference end state` in the HTML spec.
  230. *
  231. * @param lastCp The last code point of the entity. Used to see if the
  232. * entity was terminated with a semicolon.
  233. * @param expectedLength The minimum number of characters that should be
  234. * consumed. Used to validate that at least one digit
  235. * was consumed.
  236. * @returns The number of characters that were consumed.
  237. */
  238. emitNumericEntity(lastCp, expectedLength) {
  239. var _a;
  240. // Ensure we consumed at least one digit.
  241. if (this.consumed <= expectedLength) {
  242. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
  243. return 0;
  244. }
  245. // Figure out if this is a legit end of the entity
  246. if (lastCp === CharCodes.SEMI) {
  247. this.consumed += 1;
  248. }
  249. else if (this.decodeMode === DecodingMode.Strict) {
  250. return 0;
  251. }
  252. this.emitCodePoint((0, decode_codepoint_js_1.replaceCodePoint)(this.result), this.consumed);
  253. if (this.errors) {
  254. if (lastCp !== CharCodes.SEMI) {
  255. this.errors.missingSemicolonAfterCharacterReference();
  256. }
  257. this.errors.validateNumericCharacterReference(this.result);
  258. }
  259. return this.consumed;
  260. }
  261. /**
  262. * Parses a named entity.
  263. *
  264. * Equivalent to the `Named character reference state` in the HTML spec.
  265. *
  266. * @param input The string containing the entity (or a continuation of the entity).
  267. * @param offset The current offset.
  268. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  269. */
  270. stateNamedEntity(input, offset) {
  271. const { decodeTree } = this;
  272. let current = decodeTree[this.treeIndex];
  273. // The length is the number of bytes of the value, including the current byte.
  274. let valueLength = (current & bin_trie_flags_js_1.BinTrieFlags.VALUE_LENGTH) >> 14;
  275. while (offset < input.length) {
  276. // Handle compact runs (possibly inline): valueLength == 0 and SEMI_REQUIRED bit set.
  277. if (valueLength === 0 && (current & bin_trie_flags_js_1.BinTrieFlags.FLAG13) !== 0) {
  278. const runLength = (current & bin_trie_flags_js_1.BinTrieFlags.BRANCH_LENGTH) >> 7; /* 2..63 */
  279. const firstChar = current & bin_trie_flags_js_1.BinTrieFlags.JUMP_TABLE;
  280. // Fast-fail if we don't have enough remaining input for the full run (incomplete entity)
  281. if (offset + runLength > input.length)
  282. return -1;
  283. // Verify first char
  284. if (input.charCodeAt(offset) !== firstChar) {
  285. return this.result === 0
  286. ? 0
  287. : this.emitNotTerminatedNamedEntity();
  288. }
  289. offset++;
  290. this.excess++;
  291. // Remaining characters after the first
  292. const remaining = runLength - 1;
  293. // Iterate over packed 2-char words
  294. for (let runPos = 1; runPos < runLength; runPos += 2) {
  295. const packedWord = decodeTree[this.treeIndex + 1 + ((runPos - 1) >> 1)];
  296. const low = packedWord & 0xff;
  297. if (input.charCodeAt(offset) !== low) {
  298. return this.result === 0
  299. ? 0
  300. : this.emitNotTerminatedNamedEntity();
  301. }
  302. offset++;
  303. this.excess++;
  304. const high = (packedWord >> 8) & 0xff;
  305. if (runPos + 1 < runLength) {
  306. if (input.charCodeAt(offset) !== high) {
  307. return this.result === 0
  308. ? 0
  309. : this.emitNotTerminatedNamedEntity();
  310. }
  311. offset++;
  312. this.excess++;
  313. }
  314. }
  315. this.treeIndex += 1 + ((remaining + 1) >> 1);
  316. current = decodeTree[this.treeIndex];
  317. valueLength = (current & bin_trie_flags_js_1.BinTrieFlags.VALUE_LENGTH) >> 14;
  318. }
  319. if (offset >= input.length)
  320. break;
  321. const char = input.charCodeAt(offset);
  322. /*
  323. * Implicit semicolon handling for nodes that require a semicolon but
  324. * don't have an explicit ';' branch stored in the trie. If we have
  325. * a value on the current node, it requires a semicolon, and the
  326. * current input character is a semicolon, emit the entity using the
  327. * current node (without descending further).
  328. */
  329. if (char === CharCodes.SEMI &&
  330. valueLength !== 0 &&
  331. (current & bin_trie_flags_js_1.BinTrieFlags.FLAG13) !== 0) {
  332. return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess);
  333. }
  334. this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char);
  335. if (this.treeIndex < 0) {
  336. return this.result === 0 ||
  337. // If we are parsing an attribute
  338. (this.decodeMode === DecodingMode.Attribute &&
  339. // We shouldn't have consumed any characters after the entity,
  340. (valueLength === 0 ||
  341. // And there should be no invalid characters.
  342. isEntityInAttributeInvalidEnd(char)))
  343. ? 0
  344. : this.emitNotTerminatedNamedEntity();
  345. }
  346. current = decodeTree[this.treeIndex];
  347. valueLength = (current & bin_trie_flags_js_1.BinTrieFlags.VALUE_LENGTH) >> 14;
  348. // If the branch is a value, store it and continue
  349. if (valueLength !== 0) {
  350. // If the entity is terminated by a semicolon, we are done.
  351. if (char === CharCodes.SEMI) {
  352. return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess);
  353. }
  354. // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it.
  355. if (this.decodeMode !== DecodingMode.Strict &&
  356. (current & bin_trie_flags_js_1.BinTrieFlags.FLAG13) === 0) {
  357. this.result = this.treeIndex;
  358. this.consumed += this.excess;
  359. this.excess = 0;
  360. }
  361. }
  362. // Increment offset & excess for next iteration
  363. offset++;
  364. this.excess++;
  365. }
  366. return -1;
  367. }
  368. /**
  369. * Emit a named entity that was not terminated with a semicolon.
  370. *
  371. * @returns The number of characters consumed.
  372. */
  373. emitNotTerminatedNamedEntity() {
  374. var _a;
  375. const { result, decodeTree } = this;
  376. const valueLength = (decodeTree[result] & bin_trie_flags_js_1.BinTrieFlags.VALUE_LENGTH) >> 14;
  377. this.emitNamedEntityData(result, valueLength, this.consumed);
  378. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.missingSemicolonAfterCharacterReference();
  379. return this.consumed;
  380. }
  381. /**
  382. * Emit a named entity.
  383. *
  384. * @param result The index of the entity in the decode tree.
  385. * @param valueLength The number of bytes in the entity.
  386. * @param consumed The number of characters consumed.
  387. *
  388. * @returns The number of characters consumed.
  389. */
  390. emitNamedEntityData(result, valueLength, consumed) {
  391. const { decodeTree } = this;
  392. this.emitCodePoint(valueLength === 1
  393. ? decodeTree[result] &
  394. ~(bin_trie_flags_js_1.BinTrieFlags.VALUE_LENGTH | bin_trie_flags_js_1.BinTrieFlags.FLAG13)
  395. : decodeTree[result + 1], consumed);
  396. if (valueLength === 3) {
  397. // For multi-byte values, we need to emit the second byte.
  398. this.emitCodePoint(decodeTree[result + 2], consumed);
  399. }
  400. return consumed;
  401. }
  402. /**
  403. * Signal to the parser that the end of the input was reached.
  404. *
  405. * Remaining data will be emitted and relevant errors will be produced.
  406. *
  407. * @returns The number of characters consumed.
  408. */
  409. end() {
  410. var _a;
  411. switch (this.state) {
  412. case EntityDecoderState.NamedEntity: {
  413. // Emit a named entity if we have one.
  414. return this.result !== 0 &&
  415. (this.decodeMode !== DecodingMode.Attribute ||
  416. this.result === this.treeIndex)
  417. ? this.emitNotTerminatedNamedEntity()
  418. : 0;
  419. }
  420. // Otherwise, emit a numeric entity if we have one.
  421. case EntityDecoderState.NumericDecimal: {
  422. return this.emitNumericEntity(0, 2);
  423. }
  424. case EntityDecoderState.NumericHex: {
  425. return this.emitNumericEntity(0, 3);
  426. }
  427. case EntityDecoderState.NumericStart: {
  428. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
  429. return 0;
  430. }
  431. case EntityDecoderState.EntityStart: {
  432. // Return 0 if we have no entity.
  433. return 0;
  434. }
  435. }
  436. }
  437. }
  438. exports.EntityDecoder = EntityDecoder;
  439. /**
  440. * Creates a function that decodes entities in a string.
  441. *
  442. * @param decodeTree The decode tree.
  443. * @returns A function that decodes entities in a string.
  444. */
  445. function getDecoder(decodeTree) {
  446. let returnValue = "";
  447. const decoder = new EntityDecoder(decodeTree, (data) => (returnValue += (0, decode_codepoint_js_1.fromCodePoint)(data)));
  448. return function decodeWithTrie(input, decodeMode) {
  449. let lastIndex = 0;
  450. let offset = 0;
  451. while ((offset = input.indexOf("&", offset)) >= 0) {
  452. returnValue += input.slice(lastIndex, offset);
  453. decoder.startEntity(decodeMode);
  454. const length = decoder.write(input,
  455. // Skip the "&"
  456. offset + 1);
  457. if (length < 0) {
  458. lastIndex = offset + decoder.end();
  459. break;
  460. }
  461. lastIndex = offset + length;
  462. // If `length` is 0, skip the current `&` and continue.
  463. offset = length === 0 ? lastIndex + 1 : lastIndex;
  464. }
  465. const result = returnValue + input.slice(lastIndex);
  466. // Make sure we don't keep a reference to the final string.
  467. returnValue = "";
  468. return result;
  469. };
  470. }
  471. /**
  472. * Determines the branch of the current node that is taken given the current
  473. * character. This function is used to traverse the trie.
  474. *
  475. * @param decodeTree The trie.
  476. * @param current The current node.
  477. * @param nodeIdx The index right after the current node and its value.
  478. * @param char The current character.
  479. * @returns The index of the next node, or -1 if no branch is taken.
  480. */
  481. function determineBranch(decodeTree, current, nodeIndex, char) {
  482. const branchCount = (current & bin_trie_flags_js_1.BinTrieFlags.BRANCH_LENGTH) >> 7;
  483. const jumpOffset = current & bin_trie_flags_js_1.BinTrieFlags.JUMP_TABLE;
  484. // Case 1: Single branch encoded in jump offset
  485. if (branchCount === 0) {
  486. return jumpOffset !== 0 && char === jumpOffset ? nodeIndex : -1;
  487. }
  488. // Case 2: Multiple branches encoded in jump table
  489. if (jumpOffset) {
  490. const value = char - jumpOffset;
  491. return value < 0 || value >= branchCount
  492. ? -1
  493. : decodeTree[nodeIndex + value] - 1;
  494. }
  495. // Case 3: Multiple branches encoded in packed dictionary (two keys per uint16)
  496. const packedKeySlots = (branchCount + 1) >> 1;
  497. /*
  498. * Treat packed keys as a virtual sorted array of length `branchCount`.
  499. * Key(i) = low byte for even i, high byte for odd i in slot i>>1.
  500. */
  501. let lo = 0;
  502. let hi = branchCount - 1;
  503. while (lo <= hi) {
  504. const mid = (lo + hi) >>> 1;
  505. const slot = mid >> 1;
  506. const packed = decodeTree[nodeIndex + slot];
  507. const midKey = (packed >> ((mid & 1) * 8)) & 0xff;
  508. if (midKey < char) {
  509. lo = mid + 1;
  510. }
  511. else if (midKey > char) {
  512. hi = mid - 1;
  513. }
  514. else {
  515. return decodeTree[nodeIndex + packedKeySlots + mid];
  516. }
  517. }
  518. return -1;
  519. }
  520. const htmlDecoder = /* #__PURE__ */ getDecoder(decode_data_html_js_1.htmlDecodeTree);
  521. const xmlDecoder = /* #__PURE__ */ getDecoder(decode_data_xml_js_1.xmlDecodeTree);
  522. /**
  523. * Decodes an HTML string.
  524. *
  525. * @param htmlString The string to decode.
  526. * @param mode The decoding mode.
  527. * @returns The decoded string.
  528. */
  529. function decodeHTML(htmlString, mode = DecodingMode.Legacy) {
  530. return htmlDecoder(htmlString, mode);
  531. }
  532. /**
  533. * Decodes an HTML string in an attribute.
  534. *
  535. * @param htmlAttribute The string to decode.
  536. * @returns The decoded string.
  537. */
  538. function decodeHTMLAttribute(htmlAttribute) {
  539. return htmlDecoder(htmlAttribute, DecodingMode.Attribute);
  540. }
  541. /**
  542. * Decodes an HTML string, requiring all entities to be terminated by a semicolon.
  543. *
  544. * @param htmlString The string to decode.
  545. * @returns The decoded string.
  546. */
  547. function decodeHTMLStrict(htmlString) {
  548. return htmlDecoder(htmlString, DecodingMode.Strict);
  549. }
  550. /**
  551. * Decodes an XML string, requiring all entities to be terminated by a semicolon.
  552. *
  553. * @param xmlString The string to decode.
  554. * @returns The decoded string.
  555. */
  556. function decodeXML(xmlString) {
  557. return xmlDecoder(xmlString, DecodingMode.Strict);
  558. }
  559. var decode_codepoint_js_2 = require("./decode-codepoint.js");
  560. Object.defineProperty(exports, "decodeCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.decodeCodePoint; } });
  561. Object.defineProperty(exports, "fromCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.fromCodePoint; } });
  562. Object.defineProperty(exports, "replaceCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.replaceCodePoint; } });
  563. // Re-export for use by eg. htmlparser2
  564. var decode_data_html_js_2 = require("./generated/decode-data-html.js");
  565. Object.defineProperty(exports, "htmlDecodeTree", { enumerable: true, get: function () { return decode_data_html_js_2.htmlDecodeTree; } });
  566. var decode_data_xml_js_2 = require("./generated/decode-data-xml.js");
  567. Object.defineProperty(exports, "xmlDecodeTree", { enumerable: true, get: function () { return decode_data_xml_js_2.xmlDecodeTree; } });
  568. //# sourceMappingURL=decode.js.map