fix: Improve reliability of inter-linking documents through importer. closes OLN-156

This commit is contained in:
Tom Moor
2024-01-10 21:19:39 -05:00
parent 22c52f84c5
commit 89931ca2f0
2 changed files with 24 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import TurndownService from "turndown";
/**
* A turndown plugin for converting anchors to inline links without a title.
*
* @param turndownService The TurndownService instance.
*/
export default function underlines(turndownService: TurndownService) {
turndownService.addRule("inlineLink", {
filter(node, options) {
return !!(
options.linkStyle === "inlined" &&
node.nodeName === "A" &&
node.getAttribute("href")
);
},
replacement(content, node: HTMLElement) {
const href = node.getAttribute("href");
return "[" + content + "](" + href + ")";
},
});
}