mirror of
https://github.com/txtdot/txtdot
synced 2024-10-18 14:40:19 +03:00
fix(server): text links
This commit is contained in:
parent
1a48066684
commit
36207f470f
@ -63,6 +63,9 @@ export class Distributor {
|
|||||||
|
|
||||||
const dom = parseHTML(output.content);
|
const dom = parseHTML(output.content);
|
||||||
|
|
||||||
|
// Get text content before link replacement, because in text format we need original links
|
||||||
|
const stdTextContent = dom.document.documentElement.textContent;
|
||||||
|
|
||||||
// post-process
|
// post-process
|
||||||
// TODO: generate dom in handler and not parse here twice
|
// TODO: generate dom in handler and not parse here twice
|
||||||
replaceHref(
|
replaceHref(
|
||||||
@ -78,7 +81,7 @@ export class Distributor {
|
|||||||
const title = output.title || dom.document.title;
|
const title = output.title || dom.document.title;
|
||||||
const lang = output.lang || dom.document.documentElement.lang;
|
const lang = output.lang || dom.document.documentElement.lang;
|
||||||
const textContent =
|
const textContent =
|
||||||
html2text(output, dom.document, title) ||
|
html2text(stdTextContent, output, title) ||
|
||||||
'Text output cannot be generated.';
|
'Text output cannot be generated.';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -6,9 +6,13 @@ function setTitle(body: string | null, title: string) {
|
|||||||
return `${title.toUpperCase()}\n${'='.repeat(title.length)}\n\n${body}`;
|
return `${title.toUpperCase()}\n${'='.repeat(title.length)}\n\n${body}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function html2text(output: EngineOutput, doc: Document, title: string) {
|
export function html2text(
|
||||||
|
stdTextContent: string | null,
|
||||||
|
output: EngineOutput,
|
||||||
|
title: string
|
||||||
|
) {
|
||||||
if (output.textContent) return output.textContent;
|
if (output.textContent) return output.textContent;
|
||||||
else if (config.plugin.html2text)
|
else if (config.plugin.html2text)
|
||||||
return setTitle(config.plugin.html2text(output.content), title);
|
return setTitle(config.plugin.html2text(output.content), title);
|
||||||
else return setTitle(doc.documentElement.textContent, title);
|
else return setTitle(stdTextContent, title);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user