forked from Tencent/CodeAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from nickcdon/dev/migrate-202208311929
🎨 工具名称和规则名称统一展示
- Loading branch information
Showing
20 changed files
with
737 additions
and
502 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
web/packages/tca-analysis/src/components/react-highlight/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useRef, useEffect } from 'react'; | ||
import hljs from 'highlight.js'; | ||
|
||
|
||
interface HighlightProps { | ||
children: React.ReactNode | React.ReactNode[]; | ||
element?: React.ReactNode; | ||
className: any; | ||
} | ||
|
||
const Highlight = (props: HighlightProps) => { | ||
const ele = useRef(null); | ||
|
||
useEffect(() => { | ||
highlightCode(); | ||
}); | ||
|
||
const highlightCode = () => { | ||
const nodes = ele.current.querySelectorAll('pre code'); | ||
|
||
nodes?.forEach((element: any) => { | ||
hljs.highlightBlock(element); | ||
}); | ||
|
||
// for (let i = 0; i < nodes.length; i++) { | ||
// hljs.highlightBlock(nodes[i]); | ||
// } | ||
}; | ||
|
||
const { | ||
children, | ||
className, | ||
// element: Element = null, | ||
// innerHTML = false, | ||
} = props; | ||
// const eleProps = { ref: ele, className }; | ||
|
||
// if (innerHTML) { | ||
// eleProps.dangerouslySetInnerHTML = { __html: children }; | ||
|
||
// if (Element) { | ||
// return <Element {...eleProps} />; | ||
// } | ||
// return <div {...eleProps} />; | ||
// } | ||
|
||
// if (Element) { | ||
// return <Element {...eleProps}>{children}</Element>; | ||
// } | ||
return <pre ref={ele}><code className={className}>{children}</code></pre>; | ||
}; | ||
|
||
export default Highlight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.