Skip to content

Commit

Permalink
fix: Fix highlightEnable props issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 13, 2022
1 parent 696d257 commit ae6c9ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
19 changes: 9 additions & 10 deletions core/src/components/TextArea/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface MarkdownProps extends IProps, React.HTMLAttributes<HTMLPreEleme

export default function Markdown(props: MarkdownProps) {
const { prefixCls } = props;
const { markdown = '', dispatch } = useContext(EditorContext);
const { markdown = '', highlightEnable, dispatch } = useContext(EditorContext);
const preRef = React.createRef<HTMLPreElement>();
useEffect(() => {
if (preRef.current && dispatch) {
Expand All @@ -34,17 +34,16 @@ export default function Markdown(props: MarkdownProps) {
if (!markdown) {
return <pre children={markdown || ''} ref={preRef} className={`${prefixCls}-text-pre wmde-markdown-color`} />;
}
const str = rehype()
.data('settings', { fragment: true })
.use(rehypePrism, { ignoreMissing: true })
.processSync(
`<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
markdown,
)}\n</code></pre>`,
);
let mdStr = `<pre class="language-markdown ${prefixCls}-text-pre wmde-markdown-color"><code class="language-markdown">${html2Escape(
markdown,
)}\n</code></pre>`;
if (highlightEnable) {
mdStr = rehype().data('settings', { fragment: true }).use(rehypePrism, { ignoreMissing: true }).processSync(mdStr)
.value as string;
}
return React.createElement('div', {
className: 'wmde-markdown-color',
dangerouslySetInnerHTML: { __html: str.value as string },
dangerouslySetInnerHTML: { __html: mdStr },
});
}, [markdown, preRef, prefixCls]);
}
8 changes: 4 additions & 4 deletions core/src/components/TextArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type TextAreaRef = {

export default function TextArea(props: ITextAreaProps) {
const { prefixCls, className, onScroll, renderTextarea, ...otherProps } = props || {};
const { markdown, scrollTop, commands, highlightEnable, extraCommands, dispatch } = useContext(EditorContext);
const { markdown, scrollTop, commands, extraCommands, dispatch } = useContext(EditorContext);
const textRef = React.useRef<HTMLTextAreaElement>(null);
const executeRef = React.useRef<TextAreaCommandOrchestrator>();
const warp = React.createRef<HTMLDivElement>();
Expand All @@ -68,7 +68,7 @@ export default function TextArea(props: ITextAreaProps) {
}, []);

// @ts-ignore
const textStyle: React.CSSProperties = highlightEnable ? {} : { '-webkit-text-fill-color': 'inherit' };
// const textStyle: React.CSSProperties = highlightEnable ? { WebkitTextFillColor: 'transparent' } : { };

return (
<div ref={warp} className={`${prefixCls}-aree ${className || ''}`} onScroll={onScroll}>
Expand Down Expand Up @@ -102,8 +102,8 @@ export default function TextArea(props: ITextAreaProps) {
)
) : (
<Fragment>
{highlightEnable && <Markdown prefixCls={prefixCls} />}
<Textarea prefixCls={prefixCls} {...otherProps} style={textStyle} />
<Markdown prefixCls={prefixCls} />
<Textarea prefixCls={prefixCls} {...otherProps} />
</Fragment>
)}
</div>
Expand Down

1 comment on commit ae6c9ff

@vercel
Copy link

@vercel vercel bot commented on ae6c9ff Jun 13, 2022

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.