2016-11-27 65 views
0

我正在使用React CodeMirror作爲我的項目中的響應文本編輯器。這就是我現在所擁有的:React CodeMirror中的突出顯示行

<CodeMirror 
    options={{ 
    mode: 'python', 
    lineNumbers: true, 
    }} 
/> 

我的問題是,沒有人知道它是否可以添加一行剛好路過的道具突出?也許這樣?

<CodeMirror 
    options={{ 
    mode: 'python', 
    lineNumbers: true, 
    lineHighlight: { 
     from: 1, 
     to: 10 
    }, 
    }} 
/> 

這本質上突出顯示所有線路由於1和10

之間!

+0

請檢查[反應-codemirror2](https://github.com/scniro/react-codemirror2)用於React – scniro

回答

0

採取參照該文檔: https://codemirror.net/demo/markselection.html

和相關的代碼:

<script> 
var editor = CodeMirror.fromTextArea(document.getElementById("code"), { 
    lineNumbers: true, 
    styleSelectedText: true 
}); 
editor.markText({line: 6, ch: 26}, {line: 6, ch: 42}, {className: "styled-background"}); 
</script>