summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/parse.py b/parse.py
new file mode 100644
index 0000000..4db14d4
--- /dev/null
+++ b/parse.py
@@ -0,0 +1,37 @@
+import copy
+import sys
+
+import CommonMark_bkrs as CommonMark
+
+text = sys.stdin.read()
+parser = CommonMark.DocParser()
+s = parser.parse(text)
+
+print(CommonMark.ASTtoJSON(s))
+sys.exit(0)
+
+def is_code_block(o):
+ prefix = "```fable\n"
+ return o.t == 'IndentedCode' and o.string_content.startswith(prefix)
+
+def is_heading(o):
+ return o.t =='ATXHeader'
+
+def walk(o):
+ if is_code_block(o):
+ yield {
+ 'type': 'fable',
+ 'text': copy.deepcopy(o.strings),
+ }
+ elif is_heading(o):
+ yield {
+ 'type': 'heading',
+ 'level': o.level,
+ 'text': copy.deepcopy(o.strings),
+ }
+ for c in o.children:
+ for oo in walk(c):
+ yield oo
+
+for o in walk(s):
+ print(o)