+++ Bodhi [Apr 20 10 21:59 ]:> Hi all
>
> I've started writing an OS X Markdown "editor"[1] that
semi-formats your markdown document as you write it. I just wanted to put
something together, so went with a regexp-based setup for parsing -- Not ideal!
I'd really like to use an existing parser, but I need to get access to the
parse-tree *with* character offets, rather than just html output, as I'm
adding attributes to the string so it renders in a wyswig-esque manner, rather
than actually transforming it.
>
> I've looked briefly at discount and peg-markdown -- I'd prefer a
C-based parser as the app is Objective-C -- but I'm not sure if it's
possible to get a detailed parse-tree out of either of them? I thought I'd
ask before digging around and hacking up either of them...
peg-markdown does construct a parse tree. If you apply the following
patch, then 'make', then run 'markdown', you'll see the
parse tree
instead of the converted HTML. The parse tree doesn't include character
offsets. I think it may be possible to change the code to include them;
you'd have to check the peg/leg documentation.
John
diff --git a/markdown_lib.c b/markdown_lib.c
index 88fd0e8..6891efc 100644
--- a/markdown_lib.c
+++ b/markdown_lib.c
@@ -160,7 +160,7 @@ GString * markdown_to_g_string(char *text, int extensions, i
g_string_free(formatted_text, TRUE);
- print_element_list(out, result, output_format, extensions);
+ print_tree(result, 0);
free_element_list(result);
free_element_list(references);