Files
nodejs.esm-library/experiments/text-nodes.mjs

69 lines
1.0 KiB
JavaScript

import * as CF from '@efforting.tech/data/field-configuration-factories';
import { inspect } from 'node:util';
import { Text_Tree_Node, Text_Tree_Settings } from '@efforting.tech/text/basic-tree';
const ts = Text_Tree_Settings.load({
text: {
indention_mode: 'TABULATORS',
},
});
const example_string =
`branch1
leaf1
leaf2
branch2
sub-branch1
leaf3
leaf4
sub-branch2
leaf5
branch3
dual-indented
`;
const root = Text_Tree_Node.from_string(ts, example_string);
function debug_dump(node, level=0) {
console.log(`${" ".repeat(level)}[${node.line_no ?? '-'}] ${inspect(node.line)}`);
for (const child of node.children) {
debug_dump(child, level+1);
}
}
debug_dump(root);
/*
[-] undefined
[1] 'branch1'
[2] 'leaf1'
[3] 'leaf2'
[4] ''
[5] 'branch2'
[6] 'sub-branch1'
[7] 'leaf3'
[8] 'leaf4'
[9] ''
[10] ''
[11] 'sub-branch2'
[12] 'leaf5'
[13] ''
[14] 'branch3'
[-] undefined
[15] 'dual-indented'
[16] ''
[17] ''
*/