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. /** The number of characters that have been consumed in the current run. */
  109. this.runConsumed = 0;
  110. }
  111. /** Resets the instance to make it reusable. */
  112. startEntity(decodeMode) {
  113. this.decodeMode = decodeMode;
  114. this.state = EntityDecoderState.EntityStart;
  115. this.result = 0;
  116. this.treeIndex = 0;
  117. this.excess = 1;
  118. this.consumed = 1;
  119. this.runConsumed = 0;
  120. }
  121. /**
  122. * Write an entity to the decoder. This can be called multiple times with partial entities.
  123. * If the entity is incomplete, the decoder will return -1.
  124. *
  125. * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
  126. * entity is incomplete, and resume when the next string is written.
  127. *
  128. * @param input The string containing the entity (or a continuation of the entity).
  129. * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
  130. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  131. */
  132. write(input, offset) {
  133. switch (this.state) {
  134. case EntityDecoderState.EntityStart: {
  135. if (input.charCodeAt(offset) === CharCodes.NUM) {
  136. this.state = EntityDecoderState.NumericStart;
  137. this.consumed += 1;
  138. return this.stateNumericStart(input, offset + 1);
  139. }
  140. this.state = EntityDecoderState.NamedEntity;
  141. return this.stateNamedEntity(input, offset);
  142. }
  143. case EntityDecoderState.NumericStart: {
  144. return this.stateNumericStart(input, offset);
  145. }
  146. case EntityDecoderState.NumericDecimal: {
  147. return this.stateNumericDecimal(input, offset);
  148. }
  149. case EntityDecoderState.NumericHex: {
  150. return this.stateNumericHex(input, offset);
  151. }
  152. case EntityDecoderState.NamedEntity: {
  153. return this.stateNamedEntity(input, offset);
  154. }
  155. }
  156. }
  157. /**
  158. * Switches between the numeric decimal and hexadecimal states.
  159. *
  160. * Equivalent to the `Numeric character reference state` in the HTML spec.
  161. *
  162. * @param input The string containing the entity (or a continuation of the entity).
  163. * @param offset The current offset.
  164. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  165. */
  166. stateNumericStart(input, offset) {
  167. if (offset >= input.length) {
  168. return -1;
  169. }
  170. if ((input.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
  171. this.state = EntityDecoderState.NumericHex;
  172. this.consumed += 1;
  173. return this.stateNumericHex(input, offset + 1);
  174. }
  175. this.state = EntityDecoderState.NumericDecimal;
  176. return this.stateNumericDecimal(input, offset);
  177. }
  178. /**
  179. * Parses a hexadecimal numeric entity.
  180. *
  181. * Equivalent to the `Hexademical character reference state` in the HTML spec.
  182. *
  183. * @param input The string containing the entity (or a continuation of the entity).
  184. * @param offset The current offset.
  185. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  186. */
  187. stateNumericHex(input, offset) {
  188. while (offset < input.length) {
  189. const char = input.charCodeAt(offset);
  190. if (isNumber(char) || isHexadecimalCharacter(char)) {
  191. // Convert hex digit to value (0-15); 'a'/'A' -> 10.
  192. const digit = char <= CharCodes.NINE
  193. ? char - CharCodes.ZERO
  194. : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
  195. this.result = this.result * 16 + digit;
  196. this.consumed++;
  197. offset++;
  198. }
  199. else {
  200. return this.emitNumericEntity(char, 3);
  201. }
  202. }
  203. return -1; // Incomplete entity
  204. }
  205. /**
  206. * Parses a decimal numeric entity.
  207. *
  208. * Equivalent to the `Decimal character reference state` in the HTML spec.
  209. *
  210. * @param input The string containing the entity (or a continuation of the entity).
  211. * @param offset The current offset.
  212. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  213. */
  214. stateNumericDecimal(input, offset) {
  215. while (offset < input.length) {
  216. const char = input.charCodeAt(offset);
  217. if (isNumber(char)) {
  218. this.result = this.result * 10 + (char - CharCodes.ZERO);
  219. this.consumed++;
  220. offset++;
  221. }
  222. else {
  223. return this.emitNumericEntity(char, 2);
  224. }
  225. }
  226. return -1; // Incomplete entity
  227. }
  228. /**
  229. * Validate and emit a numeric entity.
  230. *
  231. * Implements the logic from the `Hexademical character reference start
  232. * state` and `Numeric character reference end state` in the HTML spec.
  233. *
  234. * @param lastCp The last code point of the entity. Used to see if the
  235. * entity was terminated with a semicolon.
  236. * @param expectedLength The minimum number of characters that should be
  237. * consumed. Used to validate that at least one digit
  238. * was consumed.
  239. * @returns The number of characters that were consumed.
  240. */
  241. emitNumericEntity(lastCp, expectedLength) {
  242. var _a;
  243. // Ensure we consumed at least one digit.
  244. if (this.consumed <= expectedLength) {
  245. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
  246. return 0;
  247. }
  248. // Figure out if this is a legit end of the entity
  249. if (lastCp === CharCodes.SEMI) {
  250. this.consumed += 1;
  251. }
  252. else if (this.decodeMode === DecodingMode.Strict) {
  253. return 0;
  254. }
  255. this.emitCodePoint((0, decode_codepoint_js_1.replaceCodePoint)(this.result), this.consumed);
  256. if (this.errors) {
  257. if (lastCp !== CharCodes.SEMI) {
  258. this.errors.missingSemicolonAfterCharacterReference();
  259. }
  260. this.errors.validateNumericCharacterReference(this.result);
  261. }
  262. return this.consumed;
  263. }
  264. /**
  265. * Parses a named entity.
  266. *
  267. * Equivalent to the `Named character reference state` in the HTML spec.
  268. *
  269. * @param input The string containing the entity (or a continuation of the entity).
  270. * @param offset The current offset.
  271. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  272. */
  273. stateNamedEntity(input, offset) {
  274. const { decodeTree } = this;
  275. let current = decodeTree[this.treeIndex];
  276. // The length is the number of bytes of the value, including the current byte.
  277. let valueLength = (current & bin_trie_flags_js_1.BinTrieFlags.VALUE_LENGTH) >> 14;
  278. while (offset < input.length) {
  279. // Handle compact runs (possibly inline): valueLength == 0 and SEMI_REQUIRED bit set.
  280. if (valueLength === 0 && (current & bin_trie_flags_js_1.BinTrieFlags.FLAG13) !== 0) {
  281. const runLength = (current & bin_trie_flags_js_1.BinTrieFlags.BRANCH_LENGTH) >> 7; /* 2..63 */
  282. // If we are starting a run, check the first char.
  283. if (this.runConsumed === 0) {
  284. const firstChar = current & bin_trie_flags_js_1.BinTrieFlags.JUMP_TABLE;
  285. if (input.charCodeAt(offset) !== firstChar) {
  286. return this.result === 0
  287. ? 0
  288. : this.emitNotTerminatedNamedEntity();
  289. }
  290. offset++;
  291. this.excess++;
  292. this.runConsumed++;
  293. }
  294. // Check remaining characters in the run.
  295. while (this.runConsumed < runLength) {
  296. if (offset >= input.length) {
  297. return -1;
  298. }
  299. const charIndexInPacked = this.runConsumed - 1;
  300. const packedWord = decodeTree[this.treeIndex + 1 + (charIndexInPacked >> 1)];
  301. const expectedChar = charIndexInPacked % 2 === 0
  302. ? packedWord & 0xff
  303. : (packedWord >> 8) & 0xff;
  304. if (input.charCodeAt(offset) !== expectedChar) {
  305. this.runConsumed = 0;
  306. return this.result === 0
  307. ? 0
  308. : this.emitNotTerminatedNamedEntity();
  309. }
  310. offset++;
  311. this.excess++;
  312. this.runConsumed++;
  313. }
  314. this.runConsumed = 0;
  315. this.treeIndex += 1 + (runLength >> 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