add something broken
This commit is contained in:
@@ -43,6 +43,152 @@ export default class CodeBlockHighlightNode extends Node {
|
||||
|
||||
get plugins() {
|
||||
return [
|
||||
// new Plugin({
|
||||
// state: {
|
||||
// init(_, { doc }) {
|
||||
// const decorations = []
|
||||
|
||||
// const blocks = findBlockNodes(doc)
|
||||
// .filter(item => item.node.type.name === 'code_block')
|
||||
|
||||
// const flatten = list => list.reduce(
|
||||
// (a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
|
||||
// )
|
||||
|
||||
// function parseNodes(nodes, className = []) {
|
||||
// return nodes.map(node => {
|
||||
|
||||
// const classes = [
|
||||
// ...className,
|
||||
// ...node.properties ? node.properties.className : [],
|
||||
// ]
|
||||
|
||||
// if (node.children) {
|
||||
// return parseNodes(node.children, classes)
|
||||
// }
|
||||
|
||||
// return {
|
||||
// text: node.value,
|
||||
// classes,
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// blocks.forEach(block => {
|
||||
// let startPos = block.pos + 1
|
||||
// const nodes = low.highlightAuto(block.node.textContent).value
|
||||
|
||||
// flatten(parseNodes(nodes))
|
||||
// .map(node => {
|
||||
// const from = startPos
|
||||
// const to = from + node.text.length
|
||||
|
||||
// startPos = to
|
||||
|
||||
// return {
|
||||
// ...node,
|
||||
// from,
|
||||
// to,
|
||||
// }
|
||||
// })
|
||||
// .forEach(node => {
|
||||
// const decoration = Decoration.inline(node.from, node.to, {
|
||||
// class: node.classes.join(' '),
|
||||
// })
|
||||
// decorations.push(decoration)
|
||||
// })
|
||||
// })
|
||||
|
||||
// return DecorationSet.create(doc, decorations)
|
||||
// },
|
||||
// apply(tr, set) {
|
||||
// return set.map(tr.mapping, tr.doc)
|
||||
// },
|
||||
// },
|
||||
// props: {
|
||||
// decorations(state) {
|
||||
// return this.getState(state)
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
|
||||
// new Plugin({
|
||||
// state: {
|
||||
// init(_, { doc }) {
|
||||
// const decorations = []
|
||||
|
||||
// const blocks = findBlockNodes(doc)
|
||||
// .filter(item => item.node.type.name === 'code_block')
|
||||
|
||||
// // console.log({blocks})
|
||||
|
||||
// const flatten = list => list.reduce(
|
||||
// (a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
|
||||
// )
|
||||
|
||||
// function parseNodes(nodes, className = []) {
|
||||
// return nodes.map(node => {
|
||||
|
||||
// const classes = [
|
||||
// ...className,
|
||||
// ...node.properties ? node.properties.className : [],
|
||||
// ]
|
||||
|
||||
// if (node.children) {
|
||||
// return parseNodes(node.children, classes)
|
||||
// }
|
||||
|
||||
// return {
|
||||
// text: node.value,
|
||||
// classes,
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// blocks.forEach(block => {
|
||||
// let startPos = block.pos + 1
|
||||
// const hightlight = low.highlightAuto(block.node.textContent)
|
||||
// const nodes = hightlight.value
|
||||
|
||||
// decorations.push(Decoration.node(block.pos, block.pos + block.node.nodeSize, {
|
||||
// 'data-language': hightlight.language,
|
||||
// }))
|
||||
|
||||
// flatten(parseNodes(nodes))
|
||||
// .map(node => {
|
||||
// const from = startPos
|
||||
// const to = from + node.text.length
|
||||
|
||||
// startPos = to
|
||||
|
||||
// return {
|
||||
// ...node,
|
||||
// from,
|
||||
// to,
|
||||
// }
|
||||
// })
|
||||
// .forEach(node => {
|
||||
// const decoration = Decoration.inline(node.from, node.to, {
|
||||
// class: node.classes.join(' '),
|
||||
// })
|
||||
// decorations.push(decoration)
|
||||
// })
|
||||
// })
|
||||
|
||||
// return DecorationSet.create(doc, decorations)
|
||||
// },
|
||||
// apply(tr, set) {
|
||||
// return set.map(tr.mapping, tr.doc)
|
||||
// },
|
||||
// },
|
||||
// props: {
|
||||
// decorations(state) {
|
||||
// console.log(this.getState(state))
|
||||
// return this.getState(state)
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
|
||||
new Plugin({
|
||||
props: {
|
||||
decorations({ doc }) {
|
||||
@@ -76,7 +222,12 @@ export default class CodeBlockHighlightNode extends Node {
|
||||
|
||||
blocks.forEach(block => {
|
||||
let startPos = block.pos + 1
|
||||
const nodes = low.highlightAuto(block.node.textContent).value
|
||||
const hightlight = low.highlightAuto(block.node.textContent)
|
||||
const nodes = hightlight.value
|
||||
|
||||
decorations.push(Decoration.node(block.pos, block.pos + block.node.nodeSize, {
|
||||
'data-language': hightlight.language,
|
||||
}))
|
||||
|
||||
flatten(parseNodes(nodes))
|
||||
.map(node => {
|
||||
|
||||
Reference in New Issue
Block a user