core: use upstream htmlparser2 instead of in-house

This is mostly because I am not 100% certain about how stable our own
optimized version is. While it does perform a lot better, there is
significant risk that things might break in production. To avoid
that, I am replacing it with the upstream version which is much more
heavily tested.
This commit is contained in:
Abdullah Atta
2022-11-23 14:58:34 +05:00
parent b1f5ffc2ec
commit 5e6caa7273
6 changed files with 3862 additions and 1497 deletions

View File

@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Parser, Attributes } from "htmlparser2";
import { Parser } from "htmlparser2";
export class HTMLRewriter {
/**
@@ -73,7 +73,12 @@ export class HTMLRewriter {
}
this.write(`<${name}`);
if (attr) this.write(` ${attr}`);
if (attr) {
for (const key in attr) {
if (!key) continue;
this.write(` ${key}="${attr[key]}"`);
}
}
this.currentTag = name;
},
onclosetag: (name, isImplied) => {
@@ -111,8 +116,7 @@ export class HTMLRewriter {
decodeEntities: false,
lowerCaseAttributeNames: false,
lowerCaseTags: false,
recognizeCDATA: false,
parseAttributes: false
recognizeCDATA: false
}
);
}
@@ -171,8 +175,7 @@ export class HTMLParser {
decodeEntities: false,
lowerCaseAttributeNames: false,
lowerCaseTags: false,
recognizeCDATA: false,
parseAttributes: false
recognizeCDATA: false
}
);
}
@@ -182,5 +185,3 @@ export class HTMLParser {
this.parser.reset();
}
}
export { Attributes };