2024-01-24 02:27:12 +00:00
|
|
|
import React, { ReactNode, useState } from "react";
|
2024-01-24 03:06:47 +00:00
|
|
|
import { parse_org } from "../../organic/target/wasm32-unknown-unknown/js/wasm";
|
2024-01-24 02:27:12 +00:00
|
|
|
import styles from "./OrgAst.module.css";
|
|
|
|
|
2024-01-24 03:06:47 +00:00
|
|
|
const OrgAst = (props: { addHighlight: Function; value: string }) => {
|
2024-01-24 02:27:12 +00:00
|
|
|
console.log(styles);
|
|
|
|
const ast_tree = parse_org(props.value);
|
|
|
|
console.log(JSON.stringify(ast_tree));
|
|
|
|
|
|
|
|
if (ast_tree.status !== "success") {
|
2024-01-24 03:06:47 +00:00
|
|
|
return <div className={styles.OrgAst}>Error! {ast_tree.content}</div>;
|
2024-01-24 02:27:12 +00:00
|
|
|
} else {
|
|
|
|
return (
|
2024-01-24 03:06:47 +00:00
|
|
|
<div className={styles.OrgAst}>
|
|
|
|
<OrgAstNode node={ast_tree.content} />
|
|
|
|
</div>
|
2024-01-24 02:27:12 +00:00
|
|
|
);
|
|
|
|
}
|
2024-01-24 03:06:47 +00:00
|
|
|
};
|
2024-01-24 02:27:12 +00:00
|
|
|
|
2024-01-24 03:06:47 +00:00
|
|
|
const OrgAstNode = (props: { node: any }) => {
|
2024-01-24 02:27:12 +00:00
|
|
|
return (
|
|
|
|
<div className={styles.OrgAstNode}>
|
|
|
|
<div className={styles.OrgAstNodeType}>{props.node["ast-node"]}</div>
|
2024-01-24 03:06:47 +00:00
|
|
|
{Array.isArray(props.node.children) && props.node.children.length > 0 ? (
|
|
|
|
<>Has children</>
|
|
|
|
) : null}
|
2024-01-24 02:27:12 +00:00
|
|
|
</div>
|
|
|
|
);
|
2024-01-24 03:06:47 +00:00
|
|
|
};
|
2024-01-24 02:27:12 +00:00
|
|
|
|
|
|
|
export default OrgAst;
|