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

@@ -5,6 +5,7 @@ import emptyLists from "./emptyLists";
import emptyParagraph from "./emptyParagraph";
import frames from "./frames";
import images from "./images";
import inlineLink from "./inlineLink";
import sanitizeLists from "./sanitizeLists";
import sanitizeTables from "./sanitizeTables";
import underlines from "./underlines";
@@ -24,6 +25,7 @@ const service = new TurndownService({
})
.remove(["script", "style", "title", "head"])
.use(gfm)
.use(inlineLink)
.use(emptyParagraph)
.use(sanitizeTables)
.use(sanitizeLists)

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 + ")";
},
});
}