1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-24 16:02:55 +02:00

Fix syntax highlighting (#2698)

* Add support with warning for decorations without paths

* Fix linting

* Fix syntax highlighting crash in examples

* Fix order of imports

* Grab text.js from upstream instead of origin which was outdated
This commit is contained in:
Sunny Hirai
2019-04-18 15:10:10 -07:00
committed by GitHub
parent b6a59c69a4
commit 2a0bb47379

View File

@@ -3,6 +3,7 @@ import { Value } from 'slate'
import Prism from 'prismjs'
import React from 'react'
import initialValueAsJson from './value.json'
/**
@@ -183,6 +184,7 @@ class CodeHighlighting extends React.Component {
const others = next() || []
if (node.type !== 'code') return others
const { document } = editor.value
const language = node.data.get('language')
const texts = node.getTexts().toArray()
const string = texts.map(t => t.text).join('\n')
@@ -217,13 +219,18 @@ class CodeHighlighting extends React.Component {
}
if (typeof token !== 'string') {
const startPath = document.assertPath(startText.key)
const endPath = document.assertPath(endText.key)
const dec = {
anchor: {
key: startText.key,
path: startPath,
offset: startOffset,
},
focus: {
key: endText.key,
path: endPath,
offset: endOffset,
},
mark: {