Minor adjustments

This commit is contained in:
Michael Rowley 2021-12-30 23:34:32 +00:00
parent 0c5c599150
commit 84ccefa5a4

View file

@ -1,6 +1,7 @@
/** /**
* @author tlwr [toby@toby.codes] * @author tlwr [toby@toby.codes]
* @author Matt C [me@mitt.dev] * @author Matt C [me@mitt.dev]
* @author Michael Rowley [michaellrowley@protonmail.com]
* @copyright Crown Copyright 2019 * @copyright Crown Copyright 2019
* @license Apache-2.0 * @license Apache-2.0
*/ */
@ -33,8 +34,6 @@ class HTMLToText extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
// TODO: Add blacklisted tags via args.
// TODO: Extract from HTML comments.
let output = ""; let output = "";
const blacklistedTags = ["script", "style"]; const blacklistedTags = ["script", "style"];
const tagRegex = /<\w+>[\s?!\-_().,/#{}*"£$%^&;:a-z]*/gis; const tagRegex = /<\w+>[\s?!\-_().,/#{}*"£$%^&;:a-z]*/gis;
@ -43,7 +42,8 @@ class HTMLToText extends Operation {
const closingTagOffset = iterativeMatch.indexOf(">"); const closingTagOffset = iterativeMatch.indexOf(">");
const tag = iterativeMatch.substring(1, closingTagOffset); const tag = iterativeMatch.substring(1, closingTagOffset);
for (let i = 0; i < blacklistedTags.length; i++) { for (let i = 0; i < blacklistedTags.length; i++) {
if (tag === blacklistedTags[i]) { if (tag === blacklistedTags[i] ||
tag.split(' ')[0] == blacklistedTags[i]) {
return; // This is why a forEach(...) loop couldn't be used for this nested one. return; // This is why a forEach(...) loop couldn't be used for this nested one.
} }
} }