Tokenizer.d.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /** All the states the tokenizer can be in. */
  2. declare const enum State {
  3. Text = 1,
  4. BeforeTagName = 2,
  5. InTagName = 3,
  6. InSelfClosingTag = 4,
  7. BeforeClosingTagName = 5,
  8. InClosingTagName = 6,
  9. AfterClosingTagName = 7,
  10. BeforeAttributeName = 8,
  11. InAttributeName = 9,
  12. AfterAttributeName = 10,
  13. BeforeAttributeValue = 11,
  14. InAttributeValueDq = 12,
  15. InAttributeValueSq = 13,
  16. InAttributeValueNq = 14,
  17. BeforeDeclaration = 15,
  18. InDeclaration = 16,
  19. InProcessingInstruction = 17,
  20. BeforeComment = 18,
  21. InComment = 19,
  22. AfterComment1 = 20,
  23. AfterComment2 = 21,
  24. BeforeCdata1 = 22,
  25. BeforeCdata2 = 23,
  26. BeforeCdata3 = 24,
  27. BeforeCdata4 = 25,
  28. BeforeCdata5 = 26,
  29. BeforeCdata6 = 27,
  30. InCdata = 28,
  31. AfterCdata1 = 29,
  32. AfterCdata2 = 30,
  33. BeforeSpecial = 31,
  34. BeforeSpecialEnd = 32,
  35. BeforeScript1 = 33,
  36. BeforeScript2 = 34,
  37. BeforeScript3 = 35,
  38. BeforeScript4 = 36,
  39. BeforeScript5 = 37,
  40. AfterScript1 = 38,
  41. AfterScript2 = 39,
  42. AfterScript3 = 40,
  43. AfterScript4 = 41,
  44. AfterScript5 = 42,
  45. BeforeStyle1 = 43,
  46. BeforeStyle2 = 44,
  47. BeforeStyle3 = 45,
  48. BeforeStyle4 = 46,
  49. AfterStyle1 = 47,
  50. AfterStyle2 = 48,
  51. AfterStyle3 = 49,
  52. AfterStyle4 = 50,
  53. BeforeEntity = 51,
  54. BeforeNumericEntity = 52,
  55. InNamedEntity = 53,
  56. InNumericEntity = 54,
  57. InHexEntity = 55
  58. }
  59. declare const enum Special {
  60. None = 1,
  61. Script = 2,
  62. Style = 3
  63. }
  64. interface Callbacks {
  65. onattribdata(value: string): void;
  66. onattribend(): void;
  67. onattribname(name: string): void;
  68. oncdata(data: string): void;
  69. onclosetag(name: string): void;
  70. oncomment(data: string): void;
  71. ondeclaration(content: string): void;
  72. onend(): void;
  73. onerror(error: Error, state?: State): void;
  74. onopentagend(): void;
  75. onopentagname(name: string): void;
  76. onprocessinginstruction(instruction: string): void;
  77. onselfclosingtag(): void;
  78. ontext(value: string): void;
  79. }
  80. export default class Tokenizer {
  81. /** The current state the tokenizer is in. */
  82. _state: State;
  83. /** The read buffer. */
  84. _buffer: string;
  85. /** The beginning of the section that is currently being read. */
  86. _sectionStart: number;
  87. /** The index within the buffer that we are currently looking at. */
  88. _index: number;
  89. /**
  90. * Data that has already been processed will be removed from the buffer occasionally.
  91. * `_bufferOffset` keeps track of how many characters have been removed, to make sure position information is accurate.
  92. */
  93. _bufferOffset: number;
  94. /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
  95. _baseState: State;
  96. /** For special parsing behavior inside of script and style tags. */
  97. _special: Special;
  98. /** Indicates whether the tokenizer has been paused. */
  99. _running: boolean;
  100. /** Indicates whether the tokenizer has finished running / `.end` has been called. */
  101. _ended: boolean;
  102. _cbs: Callbacks;
  103. _xmlMode: boolean;
  104. _decodeEntities: boolean;
  105. constructor(options: {
  106. xmlMode?: boolean;
  107. decodeEntities?: boolean;
  108. } | null, cbs: Callbacks);
  109. reset(): void;
  110. _stateText(c: string): void;
  111. _stateBeforeTagName(c: string): void;
  112. _stateInTagName(c: string): void;
  113. _stateBeforeClosingTagName(c: string): void;
  114. _stateInClosingTagName(c: string): void;
  115. _stateAfterClosingTagName(c: string): void;
  116. _stateBeforeAttributeName(c: string): void;
  117. _stateInSelfClosingTag(c: string): void;
  118. _stateInAttributeName(c: string): void;
  119. _stateAfterAttributeName(c: string): void;
  120. _stateBeforeAttributeValue(c: string): void;
  121. _stateInAttributeValueDoubleQuotes(c: string): void;
  122. _stateInAttributeValueSingleQuotes(c: string): void;
  123. _stateInAttributeValueNoQuotes(c: string): void;
  124. _stateBeforeDeclaration(c: string): void;
  125. _stateInDeclaration(c: string): void;
  126. _stateInProcessingInstruction(c: string): void;
  127. _stateBeforeComment(c: string): void;
  128. _stateInComment(c: string): void;
  129. _stateAfterComment1(c: string): void;
  130. _stateAfterComment2(c: string): void;
  131. _stateBeforeCdata6(c: string): void;
  132. _stateInCdata(c: string): void;
  133. _stateAfterCdata1(c: string): void;
  134. _stateAfterCdata2(c: string): void;
  135. _stateBeforeSpecial(c: string): void;
  136. _stateBeforeSpecialEnd(c: string): void;
  137. _stateBeforeScript5(c: string): void;
  138. _stateAfterScript5(c: string): void;
  139. _stateBeforeStyle4(c: string): void;
  140. _stateAfterStyle4(c: string): void;
  141. _parseNamedEntityStrict(): void;
  142. _parseLegacyEntity(): void;
  143. _stateInNamedEntity(c: string): void;
  144. _decodeNumericEntity(offset: number, base: number): void;
  145. _stateInNumericEntity(c: string): void;
  146. _stateInHexEntity(c: string): void;
  147. _cleanup(): void;
  148. write(chunk: string): void;
  149. _parse(): void;
  150. pause(): void;
  151. resume(): void;
  152. end(chunk?: string): void;
  153. _finish(): void;
  154. _handleTrailingData(): void;
  155. getAbsoluteIndex(): number;
  156. _getSection(): string;
  157. _emitToken(name: "onopentagname" | "onclosetag" | "onattribdata"): void;
  158. _emitPartial(value: string): void;
  159. }
  160. export {};
  161. //# sourceMappingURL=Tokenizer.d.ts.map