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

Replace rehype with rehype-dom in the browser #242

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"markdown-it-video": "~0.6.3",
"mime": "~3.0.0",
"rehype": "~11.0.0",
"rehype-dom": "~5.0.0",
"rehype-react": "~6.2.1"
}
}
9 changes: 7 additions & 2 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import twemoji from '@twemoji/api';
import { sanitize } from 'isomorphic-dompurify';

import { Fragment, createElement } from 'react';
import rehype from 'rehype';
import rehypeDom from 'rehype-dom';
import rehype2react from 'rehype-react';

import html5Embed from './html5-embed';
Expand All @@ -21,6 +21,11 @@ import relNofollow from './links-rel-nofollow';
import replaceSymbols from './default-transformer';

let counter = 0;
let rehypeParser = rehypeDom;

if (typeof window === 'undefined') {
rehypeParser = require('rehype');
}

export function emojify(input) {
return twemoji.parse(input);
Expand Down Expand Up @@ -107,7 +112,7 @@ export function getComponentTree({ html, settings, components }) {

let parsedHTML = null;
try {
parsedHTML = rehype()
parsedHTML = rehypeParser()
.data('settings', rehypeSettings)
.use(rehype2react, {
Fragment,
Expand Down
Loading