guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[potluck dish] A CommonMark parser


From: Erik Edrosa
Subject: [potluck dish] A CommonMark parser
Date: Tue, 16 Feb 2016 17:36:09 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1

Hello,

I've been working on a parser for CommonMark[0], a specified version of
Markdown[1] being worked on (still not 1.0). It currently does not parse
the full spec, but it works so far for all block structures except for
HTML blocks. The code is still pretty rough and I welcome any feedback
to improve it. I am following their suggested strategy of parsing
CommonMark in two steps by parsing the block level structure and then
inline.

The code can be found at https://github.com/OrangeShark/guile-commonmark

Here is an example usage:
(use-modules (commonmark)
             (sxml simple))

(define doc
  "A CommonMark Document
===============
Here is some scheme code
```scheme
(display \"Hello, World!\")
```

1. A list
2. Another item")

;; Parse the CommonMark document into sxml
(define doc-sxml (commonmark->sxml doc))

;; Writes to current output port
(sxml->xml doc-sxml)
(newline)


which outputs(formatted for readability):
<h1>A CommonMark Document</h1>
<p>Here is some scheme code</p>
<pre>
  <code class="language-scheme">
(display &quot;Hello, World!&quot;)
  </code>
</pre>
<ol>
  <li>
    <p>A list</p>
  </li>
  <li>
    <p>Another item</p>
  </li>
</ol>


I plan to have the 0.1 release cover both blocks and inlines and as much
of the current spec as possible. This will include parsing HTML in
CommonMark documents, but I am unsure if whether the default behavior
should be unsafe (does not escape any HTML) with a safe flag or the
opposite. Any suggestions to improve is appreciated.

Thanks
Erik - OrangeShark


[0]: http://commonmark.org/
[1]: http://daringfireball.net/projects/markdown/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]