Skip to content

Commit

Permalink
refactor: use jsdom for turndownjs instead of relying on domino
Browse files Browse the repository at this point in the history
The domino library looks abandoned and had compatibility issues with the latest nextjs versions. Luckily, turndownjs accepts a JSDOM document as input and not only raw text.

Workaround for:
* mixmark-io/turndown#439 (occurred after upgrading nextjs from 13.4 to 13.5)
* mixmark-io/turndown#378 (occurred after upgrading nextjs from 12.X to 13.X)
  • Loading branch information
julienc91 committed Oct 15, 2023
1 parent acac96a commit 75570c1
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 94 deletions.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"@prisma/client": "^5.2.0",
"cookies-next": "^4.0.0",
"crypto-js": "^4.1.1",
"jsdom": "^22.1.0",
"latinize": "^2.0.0",
"next": "13.4.x",
"next": "^13.5.4",
"node-html-parser": "6.1.8",
"nodemailer": "^6.9.3",
"prisma": "^5.2.0",
Expand All @@ -28,13 +29,10 @@
"swr": "^2.2.4",
"turndown": "^7.1.2"
},
"//": "https://github.com/mixmark-io/turndown/issues/378",
"resolutions": {
"domino": "Haringat/domino#2721294c75334ece635dfc72cad0a3dede7391fb"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
"@types/crypto-js": "^4.1.1",
"@types/jsdom": "^21.1.3",
"@types/latinize": "^0.2.15",
"@types/node": "^20.3.3",
"@types/nodemailer": "^6.4.8",
Expand Down
3 changes: 2 additions & 1 deletion utils/article/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { JSDOM } from "jsdom";
import TurndownService from "turndown";

import { stripArticle } from "@caviardeul/utils/article/parsing";

const convertToMarkdown = (htmlContent: string): string => {
return new TurndownService().turndown(htmlContent);
return new TurndownService().turndown(JSDOM.fragment(htmlContent));
};

export const convertArticleToMarkdown = (
Expand Down
Loading

1 comment on commit 75570c1

@vercel
Copy link

@vercel vercel bot commented on 75570c1 Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.