From 5e0104a73591dcfa71887d129ff4ca69f9164e0e Mon Sep 17 00:00:00 2001 From: kwaroran Date: Mon, 10 Jun 2024 22:07:12 +0900 Subject: [PATCH] feat: add mly --- src/ts/textsynt.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/ts/textsynt.ts diff --git a/src/ts/textsynt.ts b/src/ts/textsynt.ts new file mode 100644 index 00000000..9010403e --- /dev/null +++ b/src/ts/textsynt.ts @@ -0,0 +1,33 @@ + +interface TextSyntSyntaxTree { + name: string; + children: TextSyntSyntaxTree[]; +} + +function parseMarkdownLikeYaml(text:string){ + + const lines = text.split('\n'); + const root: TextSyntSyntaxTree = {name: 'root', children: []}; + let rootHashIndentation = -1; + let currentIndentation = 0; + + for(let i = 0; i < lines.length; i++){ + const line = lines[i]; + + if(line.startsWith('#')){ + let indentations = 0; + while(line[indentations] === '#'){ + indentations++; + } + + if(currentIndentation === 0 && rootHashIndentation === -1){ + rootHashIndentation = indentations; + indentations = 1; + } + else{ + indentations -= (rootHashIndentation - 1) + } + } + + } +} \ No newline at end of file