import { printTree } from 'tree-dump/lib/printTree';
import { Block } from './Block';
export class LeafBlock extends Block {
    text() {
        let str = '';
        for (let iterator = this.texts0(), inline = iterator(); inline; inline = iterator())
            str += inline.text();
        return str;
    }
    isLeaf() {
        return true;
    }
    // ------------------------------------------------------------------- export
    toJson() {
        const data = this.attr();
        const attr = data !== void 0 ? { data } : null;
        const node = [this.tag(), attr];
        for (const inline of this.texts()) {
            const child = inline.toJson();
            if (child)
                node.push(child);
        }
        return node;
    }
    // ---------------------------------------------------------------- Printable
    toStringName() {
        return 'LeafBlock';
    }
    toString(tab = '') {
        const header = this.toStringHeader();
        const texts = [...this.texts()];
        const hasSlices = !!texts.length;
        return (header +
            printTree(tab, [
                this.marker ? (tab) => this.marker.toString(tab) : null,
                !hasSlices
                    ? null
                    : (tab) => 'nodes' +
                        printTree(tab, texts.map((inline) => (tab) => inline.toString(tab))),
            ]));
    }
}
//# sourceMappingURL=LeafBlock.js.map