Format the code.

This commit is contained in:
Tom Alexander
2024-01-23 22:06:47 -05:00
parent 4847ec07d8
commit d1ce90ac42
11 changed files with 46 additions and 54 deletions

View File

@@ -15,7 +15,7 @@ function Editor({ defaultValue = "I have a text value." }) {
function addHighlight(start: number, end: number) {
let new_highlights = [...highlights, new Highlight(start, end)];
new_highlights.sort(function (a,b) {
new_highlights.sort(function (a, b) {
if (a.start < b.start) return -1;
if (a.start > b.start) return 1;
return 0;

View File

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

View File

@@ -9,7 +9,10 @@ function buildShadow(highlights: Highlight[], text: string): ReactNode[] {
let buffer = "";
for (let chr of text) {
if (state == ShadowState.Text) {
if (remaining_highlights.length > 0 && i == remaining_highlights[0].start) {
if (
remaining_highlights.length > 0 &&
i == remaining_highlights[0].start
) {
// Start a span
output.push(buffer);
buffer = chr;
@@ -35,9 +38,9 @@ function buildShadow(highlights: Highlight[], text: string): ReactNode[] {
if (buffer.length > 0) {
if (state == ShadowState.Text) {
output.push(buffer);
output.push(buffer);
} else if (state == ShadowState.Highlight) {
output.push(<span className="highlighted">{buffer}</span>);
output.push(<span className="highlighted">{buffer}</span>);
}
}
return output;
@@ -64,6 +67,4 @@ const enum ShadowState {
Highlight,
}
export {
buildShadow
}
export { buildShadow };