mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 08:11:53 +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:
@@ -3,6 +3,7 @@ import { Value } from 'slate'
|
|||||||
|
|
||||||
import Prism from 'prismjs'
|
import Prism from 'prismjs'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import initialValueAsJson from './value.json'
|
import initialValueAsJson from './value.json'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,6 +184,7 @@ class CodeHighlighting extends React.Component {
|
|||||||
const others = next() || []
|
const others = next() || []
|
||||||
if (node.type !== 'code') return others
|
if (node.type !== 'code') return others
|
||||||
|
|
||||||
|
const { document } = editor.value
|
||||||
const language = node.data.get('language')
|
const language = node.data.get('language')
|
||||||
const texts = node.getTexts().toArray()
|
const texts = node.getTexts().toArray()
|
||||||
const string = texts.map(t => t.text).join('\n')
|
const string = texts.map(t => t.text).join('\n')
|
||||||
@@ -217,13 +219,18 @@ class CodeHighlighting extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof token !== 'string') {
|
if (typeof token !== 'string') {
|
||||||
|
const startPath = document.assertPath(startText.key)
|
||||||
|
const endPath = document.assertPath(endText.key)
|
||||||
|
|
||||||
const dec = {
|
const dec = {
|
||||||
anchor: {
|
anchor: {
|
||||||
key: startText.key,
|
key: startText.key,
|
||||||
|
path: startPath,
|
||||||
offset: startOffset,
|
offset: startOffset,
|
||||||
},
|
},
|
||||||
focus: {
|
focus: {
|
||||||
key: endText.key,
|
key: endText.key,
|
||||||
|
path: endPath,
|
||||||
offset: endOffset,
|
offset: endOffset,
|
||||||
},
|
},
|
||||||
mark: {
|
mark: {
|
||||||
|
Reference in New Issue
Block a user