React中怎么使用SyntaxHighlighter ?

#1

使用ueditor富文本编辑器编辑好的文本需要配合SyntaxHighlighter高亮显示其中的代码部分,之前直接使用script标签引入SyntaxHighlighter是可以的,现在使用 React,

`import SyntaxHighlighter from 'syntaxhighlighter';` 

会报错:

TypeError: Cannot assign to read only property ‘exports’ of object ‘#’

想问一下大家,在React中如何使用SyntaxHighlighter来高亮已经编辑好的文本中的代码。

#2

用的prettyPrint,理论上来说是差不多的

import { Component } from 'react'

class Code extends Component {
  componentDidMount () {
    window.prettyPrint(null, this.code)
  }

  render () {
    return (
      <div ref="code" className="code">
        <pre className="prettyprint linenums">
          {this.props.children}
        </pre>
      </div>
    )
  }
};
#3

this.code => this.refs.code

#4

https://cloud.tencent.com/developer/doc/1201
可以了解一下