stoplightio/markdown

View on GitHub
src/builder.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { MDAST } from './ast-types';
import { Reader } from './reader';
import { stringify } from './stringify';

export class Builder {
  public root: MDAST.Root;

  constructor(public reader = new Reader()) {
    this.root = {
      type: 'root',
      children: [],
    };
  }

  public addMarkdown(markdown: string) {
    this.root.children.push(...this.reader.fromLang(markdown).children);

    return this;
  }

  public addChild(node: MDAST.Content) {
    this.root.children.push(node);

    return this;
  }

  public toString() {
    return stringify(this.root);
  }
}