Skip to content

Commit

Permalink
fix: Fixed merged comments <!-- --> into one node instead of multiple (
Browse files Browse the repository at this point in the history
…#248)

* fix: Fixed merged comments <!-- --> into one node instead of multiple

* fix: Fixed merged comments in nohighlight
  • Loading branch information
RARgames committed Nov 21, 2023
1 parent 74fa8e9 commit cc96b52
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
18 changes: 9 additions & 9 deletions core/package.json
Expand Up @@ -56,15 +56,15 @@
"dependencies": {
"@babel/runtime": "^7.17.2",
"@uiw/copy-to-clipboard": "~1.0.12",
"react-markdown": "~8.0.0",
"rehype-attr": "~2.1.0",
"rehype-autolink-headings": "~6.1.1",
"rehype-ignore": "^1.0.1",
"react-markdown": "~9.0.1",
"rehype-attr": "~3.0.1",
"rehype-autolink-headings": "~7.1.0",
"rehype-ignore": "^2.0.0",
"rehype-prism-plus": "1.6.3",
"rehype-raw": "^6.1.1",
"rehype-rewrite": "~3.0.6",
"rehype-slug": "~5.1.0",
"remark-gfm": "~3.0.1",
"unist-util-visit": "^4.1.0"
"rehype-raw": "^7.0.0",
"rehype-rewrite": "~4.0.0",
"rehype-slug": "~6.0.0",
"remark-gfm": "~4.0.0",
"unist-util-visit": "^5.0.0"
}
}
2 changes: 2 additions & 0 deletions core/src/index.tsx
Expand Up @@ -4,13 +4,15 @@ import rehypePrism from 'rehype-prism-plus';
import { PluggableList } from 'unified';
import rehypeRewrite from 'rehype-rewrite';
import rehypeAttrs from 'rehype-attr';
import rehypeRaw from 'rehype-raw';
import { reservedMeta } from './plugins/reservedMeta';
import { rehypeRewriteHandle, defaultRehypePlugins } from './rehypePlugins';

export * from './preview';

export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props, ref) => {
const rehypePlugins: PluggableList = [
rehypeRaw,
reservedMeta,
[rehypePrism, { ignoreMissing: true }],
...defaultRehypePlugins,
Expand Down
2 changes: 2 additions & 0 deletions core/src/nohighlight.tsx
Expand Up @@ -4,10 +4,12 @@ import { PluggableList } from 'unified';
import rehypeRewrite from 'rehype-rewrite';
import { reservedMeta } from './plugins/reservedMeta';
import rehypeAttrs from 'rehype-attr';
import rehypeRaw from 'rehype-raw';
import { rehypeRewriteHandle, defaultRehypePlugins } from './rehypePlugins';

export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props, ref) => {
const rehypePlugins: PluggableList = [
rehypeRaw,
reservedMeta,
...defaultRehypePlugins,
[rehypeRewrite, { rewrite: rehypeRewriteHandle(props.disableCopy ?? false, props.rehypeRewrite) }],
Expand Down
8 changes: 4 additions & 4 deletions core/src/plugins/reservedMeta.ts
@@ -1,14 +1,14 @@
import { Plugin } from 'unified';
import { Root, RootContent } from 'hast';
import { Root, RootContent, Element } from 'hast';
import { visit } from 'unist-util-visit';

export interface ReservedMetaOptions {}

export const reservedMeta: Plugin<[ReservedMetaOptions?], Root> = (options = {}) => {
return (tree) => {
visit(tree, (node: Root | RootContent) => {
if (node.type === 'element' && node.tagName === 'code' && node.data && node.data.meta) {
node.properties = { ...node.properties, 'data-meta': String(node.data.meta) };
visit(tree, (node: Root | RootContent | Element) => {
if (node.type === 'element' && node.tagName === 'code' && node.properties && node.properties.meta) {
node.properties = { ...node.properties, 'data-meta': String(node.properties.meta) };
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/rehypePlugins.tsx
Expand Up @@ -21,7 +21,7 @@ export const rehypeRewriteHandle =
const code = getCodeString(node.children);
node.children.push(copyElement(code));
}
rewrite && rewrite(node, index, parent);
rewrite && rewrite(node, index === null ? undefined : index, parent === null ? undefined : parent);
};

export const defaultRehypePlugins: PluggableList = [slug, headings, rehypeIgnore];

0 comments on commit cc96b52

Please sign in to comment.