Skip to content

Commit

Permalink
fix: modify urlTransform by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 24, 2023
1 parent f15cb20 commit c2340cc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions core/src/index.tsx
Expand Up @@ -4,6 +4,7 @@ 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 { retrieveMeta } from './plugins/retrieveMeta';
import { rehypeRewriteHandle, defaultRehypePlugins } from './rehypePlugins';
Expand All @@ -14,6 +15,7 @@ export * from './Props';
export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props, ref) => {
const rehypePlugins: PluggableList = [
reservedMeta,
rehypeRaw,
retrieveMeta,
[rehypePrism, { ignoreMissing: true }],
...defaultRehypePlugins,
Expand Down
2 changes: 2 additions & 0 deletions core/src/nohighlight.tsx
Expand Up @@ -5,6 +5,7 @@ import rehypeRewrite from 'rehype-rewrite';
import { reservedMeta } from './plugins/reservedMeta';
import { retrieveMeta } from './plugins/retrieveMeta';
import rehypeAttrs from 'rehype-attr';
import rehypeRaw from 'rehype-raw';
import { rehypeRewriteHandle, defaultRehypePlugins } from './rehypePlugins';
import type { MarkdownPreviewProps, MarkdownPreviewRef } from './Props';

Expand All @@ -13,6 +14,7 @@ export * from './Props';
export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props, ref) => {
const rehypePlugins: PluggableList = [
reservedMeta,
rehypeRaw,
retrieveMeta,
...defaultRehypePlugins,
[rehypeRewrite, { rewrite: rehypeRewriteHandle(props.disableCopy ?? false, props.rehypeRewrite) }],
Expand Down
9 changes: 8 additions & 1 deletion core/src/preview.tsx
@@ -1,12 +1,17 @@
import React, { useImperativeHandle } from 'react';
import ReactMarkdown from 'react-markdown';
import ReactMarkdown, { UrlTransform } from 'react-markdown';
import { PluggableList } from 'unified';
import gfm from 'remark-gfm';
import raw from 'rehype-raw';
import { useCopied } from './plugins/useCopied';
import { type MarkdownPreviewProps, type MarkdownPreviewRef } from './Props';
import './styles/markdown.less';

/**
* https://github.com/uiwjs/react-md-editor/issues/607
*/
const defaultUrlTransform: UrlTransform = (url) => url;

export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props, ref) => {
const {
prefixCls = 'wmde-markdown wmde-markdown-color',
Expand All @@ -21,6 +26,7 @@ export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props
rehypeRewrite: rewrite,
wrapperElement = {},
warpperElement = {},
urlTransform,
...other
} = props;
const mdp = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -48,6 +54,7 @@ export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props
{...customProps}
{...other}
skipHtml={skipHtml}
urlTransform={urlTransform || defaultUrlTransform}
rehypePlugins={pluginsFilter ? pluginsFilter('rehype', rehypePlugins) : rehypePlugins}
remarkPlugins={pluginsFilter ? pluginsFilter('remark', remarkPlugins) : remarkPlugins}
children={source || ''}
Expand Down
8 changes: 1 addition & 7 deletions website/src/App.tsx
Expand Up @@ -46,13 +46,7 @@ export const Example = () => {
spellCheck="false"
onChange={(e) => setValue(e.target.value)}
/>
<MarkdownPreview
urlTransform={(url) => {
return url;
}}
className="editor-preview"
source={value}
/>
<MarkdownPreview className="editor-preview" source={value} />
</EditorWrapper>
);
};
Expand Down

0 comments on commit c2340cc

Please sign in to comment.