|
1 | | -import React, {useEffect} from 'react'; |
| 1 | +import React from 'react'; |
2 | 2 | import {Modal, Button, Dropdown, Label} from 'semantic-ui-react'; |
3 | 3 | import * as Tools from '../utils/Tools'; |
4 | 4 | import Loading from "./Loading"; |
| 5 | +import useCodeHighlighting from './hooks/useCodeHighlighting'; |
5 | 6 |
|
6 | 7 | export default function SourceCode(props) { |
7 | | - const codeEl = React.createRef(); |
8 | | - let mark = null; |
9 | | - |
10 | | - useEffect(() => { |
11 | | - renderPrettyPrint(); |
12 | | - }, [props.sourceCode, props.sourceCodeVisible]); |
| 8 | + const codeEl = useCodeHighlighting([props.sourceCode, props.sourceCodeVisible], props.sourceCodeVariable?.keyword); |
13 | 9 |
|
14 | 10 | function handleClose() { |
15 | 11 | props.onCloseSourceCode(); |
16 | 12 | } |
17 | 13 |
|
18 | | - function renderPrettyPrint() { |
19 | | - setTimeout(() => { |
20 | | - if (codeEl.current) { |
21 | | - codeEl.current.classList.remove('prettyprinted'); |
22 | | - setTimeout(() => PR.prettyPrint( |
23 | | - () => setTimeout(() =>renderHighLight(), 1000) |
24 | | - ), 100); |
25 | | - } |
26 | | - }, codeEl.current ? 0 : 1000); |
27 | | - } |
28 | | - |
29 | | - function renderHighLight() { |
30 | | - if (mark) {mark.unmark()} |
31 | | - mark = new Mark(codeEl.current); |
32 | | - let idx = 0; |
33 | | - mark.mark(props.sourceCodeVariable.keyword, {each: el => { |
34 | | - el.setAttribute('tabindex',idx++); |
35 | | - }}); |
36 | | - } |
37 | | - |
38 | 14 | if (!props.sourceCodeVariable || !props.sourceCodeRepo) { return null; } |
39 | 15 | const sourceCodeVariable = props.sourceCodeVariable; |
40 | 16 | const dropText = ( |
|
0 commit comments