use link url if there's no link text

This commit is contained in:
tezlm 2022-06-01 01:37:06 -07:00
parent b5c616ad14
commit 7ceeb92648

View file

@ -18,7 +18,7 @@ function parse(data, url) {
for(let line of data.split("\n")) { for(let line of data.split("\n")) {
const header = line.match(/^(#{1,3}) */); const header = line.match(/^(#{1,3}) */);
const link = line.match(/^=> *(\S+) *(.+)/); const link = line.match(/^=> *(\S+) *(.+)?/);
if(line.startsWith("*")) { if(line.startsWith("*")) {
if(!list) html += "<ul>\n"; if(!list) html += "<ul>\n";
@ -44,9 +44,9 @@ function parse(data, url) {
} else if(link) { } else if(link) {
let loc = new URL(link[1], url); let loc = new URL(link[1], url);
if (loc.protocol === "gemini:") { if (loc.protocol === "gemini:") {
loc = `/${loc.hostname}${loc.pathname}`; loc = `/${loc.hostname}${loc.pathname}${loc.search}`;
} }
html += `<p><a href="${loc}">${clean(link[2])}</a></p>\n`; html += `<p><a href="${loc}">${clean(link[2] ?? link[1])}</a></p>\n`;
} else if(line) { } else if(line) {
html += `<p>${clean(line)}</p>\n`; html += `<p>${clean(line)}</p>\n`;
} }