Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (28 sloc) 805 Bytes
import {
TextNode,
AnnotNode,
BlockNode,
} from "./modules";
export interface NodeMapper {
visitTextNode: (node: TextNode) => TextNode;
visitAnnotNode: (node: AnnotNode) => AnnotNode;
visitBlockNode: (node: BlockNode) => BlockNode;
}
export class IdNodeMapper implements NodeMapper {
public visitTextNode(node: TextNode): TextNode {
return node;
}
public visitAnnotNode(node: AnnotNode): AnnotNode {
return node;
}
public visitBlockNode(node: BlockNode): BlockNode {
return node;
}
}
export class NodeWhiteSpaceCleaner extends IdNodeMapper {
public visitBlockNode(node: BlockNode): BlockNode {
return node
.filterChildren(child => !(child.isTextNode() && (<TextNode>child).isWhiteSpace()))
.mapChildren(child => child.acceptNodeMapper(this));
}
}
You can’t perform that action at this time.