Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support table for markdown #7 #11

Merged
merged 16 commits into from
Dec 29, 2023
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"redux-persist-webextension-storage": "^1.0.2",
"rehype-parse": "^9.0.0",
"rehype-remark": "^10.0.0",
"remark-gfm": "4.0.0",
"remark-pangu": "^2.2.0",
"remark-stringify": "^11.0.0",
"rfdc": "^1.3.0",
"tiny-delay": "^1.0.6",
Expand Down Expand Up @@ -103,4 +105,4 @@
"@crxjs/vite-plugin@2.0.0-beta.19": "patches/@crxjs__vite-plugin@2.0.0-beta.19.patch"
}
}
}
}
222 changes: 222 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/popup/hooks/useTransformFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { md2tid } from 'md-to-tid';
import { Dispatch, SetStateAction, useEffect, useRef } from 'react';
import rehypeParse from 'rehype-parse';
import rehypeRemark from 'rehype-remark';
import remarkGfm from 'remark-gfm';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import remarkPangu from 'remark-pangu';
import remarkStringify from 'remark-stringify';
import { unified } from 'unified';

Expand All @@ -17,8 +21,11 @@ export interface IContent {

const html2mdParser = unified()
.use(rehypeParse)
.use(remarkGfm)
.use(rehypeRemark)
.use(remarkStringify);
.use(remarkStringify)
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
.use(remarkPangu);

export function useTransformFormat(
content: IContent,
Expand Down Expand Up @@ -56,7 +63,12 @@ export function useTransformFormat(
if (!isEqual(newContent, content)) {
setContent(newContent);
}
}, [content.html, options.toMd, options.toTid, setContent]) as () => Promise<void>;
}, [
content.html,
options.toMd,
options.toTid,
setContent,
]) as () => Promise<void>;
useEffect(() => {
void transformHTML();
// don't add newContent.markdown or newContent.wikitext to the dependency array, to avoid infinite loop
Expand Down
Loading