| 38 | }; |
| 39 | |
| 40 | export class HTMLParser { |
| 41 | static { |
| 42 | this.prototype.attrState = AttrState.None; |
| 43 | this.prototype.tagState = TagState.None; |
| 44 | this.prototype.stringState = StringState.None; |
| 45 | this.prototype.escaping = false; |
| 46 | |
| 47 | this.prototype.currentAttrName = ''; |
| 48 | this.prototype.currentAttrValue = ''; |
| 49 | |
| 50 | this.prototype.currentName = ''; |
| 51 | this.prototype.currentNode = null; |
| 52 | this.prototype.textNode = null; |
| 53 | } |
| 54 | |
| 55 | document = new Document(); |
| 56 | parent = this.document; |
| 57 | |
| 58 | constructor() {} |
| 59 | |
| 60 | parse(input, autoParent = true) { |
| 61 | const checkToken = (a, b) => !this.escaping && a === b; |
| 62 | |
| 63 | const checkSES = c => { |
| 64 | if (this.escaping) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | if (c != '"' && c != '\'') { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | const state = c == '"' ? StringState.Double : StringState.Single; |
| 73 | |
| 74 | // start |
| 75 | if (this.stringState == StringState.None) { |
| 76 | this.stringState = state; |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | // end |
| 81 | if (this.stringState == state) { |
| 82 | this.stringState = StringState.None; |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | return false; |
| 87 | }; |
| 88 | |
| 89 | const isspace = c => c === ' ' || c === '\n'; |
| 90 | const isclosing = c => c === '>' || c === '/'; |
| 91 | |
| 92 | const isVoidEl = (name = this.currentName) => VOID_ELEMENTS.includes(name); |
| 93 | |
| 94 | input = input.replace(/<!DOCTYPE .*?>/i, '').replace(/<!--[\w\W]*?-->/g, '') |
| 95 | .replaceAll('\r\n', '\n').replaceAll('\r', '\n'); // normalize newlines |
| 96 | |
| 97 | for (let i = 0; i < input.length; i++) { |
nothing calls this directly
no outgoing calls
no test coverage detected