Public
Edited
Feb 12, 2023
Insert cell
Insert cell
function getlvl(line, left=0){
if (line[0] != ' ') return left
return getlvl(line.slice(1, line.length), left+1)
}
Insert cell
Insert cell
pluginListToGrid(txt)
Insert cell
function pluginListToGrid(txt){
let ret = {}

let txt2 = []
//txt = txt.split("\n")
let gridactive = false
let collimit = -1
let indentraw = 0
let space = 2
let indentstart = 0
txt.split("\n").map(line => {
if (line.trim() == "") return
if (line.includes('crash_grid')){
gridactive = true
collimit = +line.trim().split(" ")[1]
indentraw = getlvl(line)
indentstart = -1
console.log(gridactive, collimit, indentraw)
return
}

if (gridactive){
if (getlvl(line) < indentraw){
gridactive = false
txt2.push(line)
return
}
if (line.trim().startsWith('-')){
indentstart += 1
if (indentstart == collimit)
indentstart = 0
}
let pre = ''
for (let i = 0; i < indentraw+indentstart*space; i++)
pre += ' '
txt2.push(pre+line.trim())
}else{
txt2.push(line)
}
})
ret = txt2.join("\n")
return ret
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more