marsprince/slate-vue

code-highlighting example?

moonpapers opened this issue · 1 comments

Why is this the only one missing from all the examples?

decorate([node, path]) {

            const ranges = [];


            const tokens = Prism.tokenize(node.text, Prism.languages['javascript']);

            let start = 0

              for (const token of tokens) {
                const length = getLength(token)
                const end = start + length

                if (typeof token !== 'string') {
                  ranges.push({
                    [token.type]: true,
                    anchor: { path, offset: start },
                    focus: { path, offset: end },
                  })
                }

                start = end
              }
              
              return ranges

        },

It seems to be unsuccessful. What's wrong

export const renderLeaf = ({ attributes, children, leaf }) => {
  return {
    render() {

      if(leaf.tag){
          attributes.css = `color: #905`;
      }

      return <span {...{attrs: attributes}}>{children}</span>
    }
  }
}

I see