option to supress inline links

main
Lee Hanken 2022-04-02 11:13:18 +01:00
parent 994c97da6d
commit b43206d0c0
11 changed files with 16 additions and 6 deletions

11
index.js Normal file → Executable file
View File

@ -31,12 +31,15 @@ app.use(express.urlencoded({
app.get('/', (req, res) => {
url = req.query.url;
title = req.query.title;
links = req.query.links;
let inline_title = false;
if (title)
inline_title = !!JSON.parse(title);
if (links)
links = !JSON.parse(links);
if (url && validURL(url)) {
send_headers(res);
read_url(url, res, inline_title);
read_url(url, res, inline_title, links);
} else {
res.status(400).send("Please specify a valid url query parameter");
}
@ -85,16 +88,16 @@ function process_dom(url, document, res, inline_title) {
for (let i=0;i<replacement.placeholders.length;i++) {
markdown = markdown.replace(replacement.placeholders[i], replacement.tables[i]);
}
let result = (url) ? common_filters.filter(url, markdown) : markdown;
let result = (url) ? common_filters.filter(url, markdown, links) : markdown;
if (inline_title && title) {
result = "# " + title.textContent + "\n" + result;
}
return result;
}
function read_url(url, res, inline_title) {
function read_url(url, res, inline_title, links) {
JSDOM.fromURL(url).then((document)=>{
let markdown = process_dom(url, document, res, inline_title);
let markdown = process_dom(url, document, res, inline_title, links);
res.send(markdown);
}).catch((error)=> {
res.status(400).send("Sorry, could not fetch and convert that URL");

1
node_modules/.bin/acorn generated vendored
View File

@ -1 +0,0 @@
../acorn/bin/acorn

BIN
node_modules/.bin/acorn generated vendored Executable file

Binary file not shown.

1
node_modules/.bin/escodegen generated vendored
View File

@ -1 +0,0 @@
../escodegen/bin/escodegen.js

BIN
node_modules/.bin/escodegen generated vendored Executable file

Binary file not shown.

1
node_modules/.bin/esgenerate generated vendored
View File

@ -1 +0,0 @@
../escodegen/bin/esgenerate.js

BIN
node_modules/.bin/esgenerate generated vendored Executable file

Binary file not shown.

1
node_modules/.bin/esparse generated vendored
View File

@ -1 +0,0 @@
../esprima/bin/esparse.js

BIN
node_modules/.bin/esparse generated vendored Executable file

Binary file not shown.

1
node_modules/.bin/esvalidate generated vendored
View File

@ -1 +0,0 @@
../esprima/bin/esvalidate.js

BIN
node_modules/.bin/esvalidate generated vendored Executable file

Binary file not shown.

1
node_modules/.bin/mime generated vendored
View File

@ -1 +0,0 @@
../mime/cli.js

BIN
node_modules/.bin/mime generated vendored Executable file

Binary file not shown.

View File

@ -1 +0,0 @@
../acorn/bin/acorn

BIN
node_modules/acorn-globals/node_modules/.bin/acorn generated vendored Executable file

Binary file not shown.

0
node_modules/mime/.npmignore generated vendored Normal file → Executable file
View File

0
node_modules/nwsapi/dist/lint.log generated vendored Normal file → Executable file
View File

11
url_to_markdown_common_filters.js Normal file → Executable file
View File

@ -39,7 +39,7 @@ module.exports = {
}
],
filter: function (url, data) {
filter: function (url, data, links=true) {
let domain='';
let base_address='';
if (url) {
@ -73,7 +73,14 @@ module.exports = {
}
);
// removes inline links
if (!links) {
data = data.replaceAll(/([^!])\[([^\]]+)\]\(http[^\)]+\)/g,
(match, prefix, title) => prefix+'*'+title+'*'
);
}
return data;
}
}
}