-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
render to json #4
Conversation
@pi0 please take a look, i did not add testings for all scenarios, but i think it should work now (may have bugs of course) |
Rendering to JSONmd4w also provides a const traverse = (node) => {
if (typeof node === "string") {
// text node
console.log(node);
return;
}
// element type
console.log(node.type);
// element attributes (may be undefined)
console.log(node.props);
// element children (may be undefined)
node.children?.forEach(traverse);
};
const tree = mdToJSON("Stay _foolish_, stay **hungry**!");
traverse(tree); Node TypeThe node type is a number that represents the type of the node. You can import import { NodeType } from "md4w";
console.log(NodeType.P); // 9
console.log(NodeType.IMG); // 103
if (node.type === NodeType.IMG) {
console.log("This is an image node, `src` is", node.props.src);
}
|
@pi0 ^ FYI, updated docs |
closes #3
wasm change: 52kb -> 55kb