diff --git a/common.mjs b/common.mjs
index fab9508..139f5c3 100644
--- a/common.mjs
+++ b/common.mjs
@@ -54,8 +54,8 @@ export default async function(
//
const Properties = new Map([
- ["html-title", (article, singleLine, window) =>
- `
${escapeHTML(Properties.get("title")(article, singleLine, window), window.document)}
`
+ ["html-title", (article, singleLine, document) =>
+ `${escapeHTML(Properties.get("title")(article, singleLine, document), document)}
`
],
["title", (article, singleLine) =>
singleLine ? article.title.replace(/\n+/gm, ' ') : article.title
@@ -69,7 +69,7 @@ export default async function(
["length", article => article.length],
["dir", article => article.dir],
["text-content", article => article.textContent],
- ["html-content", (article, _, window) => article.content]
+ ["html-content", article => article.content]
]);
const LowConfidenceMode = {
@@ -83,7 +83,8 @@ export default async function(
//backwards compat with old, comma-separated values
function yargsCompatProperties(args) {
if (args["properties"]) {
- for (var i = 0; i < args["properties"].length; i++) {
+ let i;
+ for (i = 0; i < args["properties"].length; i++) {
const property = args["properties"][i];
if (property.indexOf(',') > -1) {
const split = args["properties"][i].split(',');
@@ -113,7 +114,7 @@ export default async function(
}
- let args = yargs
+ const args = yargs
.version(false)
.command("* [source]", __`Process HTML input`, (yargs) => {
yargs.positional("source", {
@@ -224,7 +225,7 @@ export default async function(
type: "boolean",
desc: __`Print version`
})
- .fail((msg, err, yargs) => {
+ .fail((msg, _err, _yargs) => {
console.error(msg);
setErrored(ExitCodes.badUsageCLI);
})
@@ -352,7 +353,7 @@ export default async function(
console.error(__`Warning: piping input with unknown URL. This means that relative links will be broken. Supply the --base parameter to fix.`)
}
const input = await read(process.stdin);
- [document, window] = await parseDOM(result, documentURL);
+ [document, window] = await parseDOM(input, documentURL);
} else {
if (!args["quiet"])
console.error(__`Retrieving...`);
@@ -365,7 +366,8 @@ export default async function(
}
[document, window] = await parseDOMPromise;
}
- } catch (error) {
+ } catch (e) {
+ let error = e
if (error.error) {
//Nested error?
error = error.error;
@@ -397,7 +399,7 @@ export default async function(
//Taken from https://stackoverflow.com/a/22706073/5701177
function escapeHTML(string, document) {
- var p = document.createElement("p");
+ const p = document.createElement("p");
p.appendChild(document.createTextNode(string));
return p.innerHTML;
}
@@ -461,10 +463,10 @@ export default async function(
return;
}
if (outputJSON) {
- let result = {};
+ const result = {};
if (wantedProperties) {
for (propertyName of wantedProperties)
- result[propertyName] = Properties.get(propertyName)(article, false, window);
+ result[propertyName] = Properties.get(propertyName)(article, false, document);
} else {
for (const [name, func] of Properties) {
result[name] = func(article, false, window);
@@ -474,7 +476,7 @@ export default async function(
} else {
if (wantedProperties) {
for (propertyName of wantedProperties)
- writeStream.write(Properties.get(propertyName)(article, true, window) + '\n');
+ writeStream.write(Properties.get(propertyName)(article, true, document) + '\n');
} else {
writeStream.write(`
@@ -486,7 +488,7 @@ export default async function(
`);
}
writeStream.write(`
- ${escapeHTML(Properties.get("title")(article, false, window), document)}
+ ${escapeHTML(Properties.get("title")(article, false, document), document)}
`
);
@@ -497,7 +499,7 @@ export default async function(
`);
else
@@ -505,9 +507,9 @@ export default async function(
writeStream.write(`