Skip to content
Snippets Groups Projects
Commit f6a24dd9 authored by marihachi's avatar marihachi
Browse files

add api doc

parent bce61eb5
No related branches found
No related tags found
No related merge requests found
......@@ -4,16 +4,25 @@ import { stringifyNode, stringifyTree } from './util';
const parser: peg.Parser = require('./parser');
/**
* generate a node tree from the MFM string.
*/
export function parse(input: string): MfmNode[] {
const nodes = parser.parse(input, { startRule: 'fullParser' });
return nodes;
}
/**
* generate a node tree of plain from the MFM string.
*/
export function parsePlain(input: string): MfmPlainNode[] {
const nodes = parser.parse(input, { startRule: 'plainParser' });
return nodes;
}
/**
* generate a MFM string from the node tree.
*/
export function toString(tree: MfmNode[]): string
export function toString(node: MfmNode): string
export function toString(node: MfmNode | MfmNode[]): string {
......@@ -25,6 +34,9 @@ export function toString(node: MfmNode | MfmNode[]): string {
}
}
/**
* Inspects the node tree.
*/
export function inspect(nodes: MfmNode[], action: (node: MfmNode) => void): void {
for (const node of nodes) {
action(node);
......@@ -34,6 +46,10 @@ export function inspect(nodes: MfmNode[], action: (node: MfmNode) => void): void
}
}
/**
* Inspects the node tree and returns as an array the nodes that match the conditions
* of the predicate function.
*/
export function extract(nodes: MfmNode[], predicate: (node: MfmNode) => boolean): MfmNode[] {
const dest = [] as MfmNode[];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment