[Top][All Lists]

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

[ANN] guile-commonmark 0.1 (A markdown parser)

From: Erik Edrosa
Subject: [ANN] guile-commonmark 0.1 (A markdown parser)
Date: Sun, 24 Jul 2016 22:33:45 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1

Hello everyone,

Awhile back for the potluck I posted a CommonMark[0] parser I written in
pure Guile Scheme which outputs SXML. Today I have decided to release
version 0.1, it currently supports parsing almost the entire CommonMark
spec besides block and inline HTML. guile-commonmark will not support
block and inline HTML as the spec allows malformed HTML to be written
which can't be transformed to SXML. guile-commonmark also follows a
slightly older version of the spec and one of the major differences are
tabs are expanded into spaces(including tabs in code blocks).

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

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

    1. A list
    2. Another item in a list

    Read more about [CommonMark](")

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

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

Which outputs(formatted for readability):

    <h1>A CommonMark Document</h1>
    <p>Here is some <em>scheme</em> <code>code</code></p>
      <code class="language-scheme">(display &quot;Hello, World!&quot;)
      <li>A list</li>
      <li>Another item in a list</li>
    <p>Read more about <a href="";>CommonMark</a></p>

You may download the release at

GNU Guix users can install guile-commonmark using the attached guix.scm file

guile-commonmark is still a young project, so expect plenty of bugs.
Please report any bugs to

As a bonus for haunt users, here is an example using guile-commonmark as
a reader to generate a blog written in markdown.

    (use-modules (haunt asset)
                 (haunt builder blog)
                 (haunt builder atom)
                 (haunt reader)
                 (haunt site)
                 (haunt post)

    (define commonmark-reader
      (make-reader (make-file-extension-matcher "md")
                   (lambda (file)
                     (call-with-input-file file
                       (lambda (port)
                         (values (read-metadata-headers port)
                                 (commonmark->sxml port)))))))

    (site #:title "Built with Guile"
          #:domain ""
          '((author . "Eva Luator")
            (email  . "address@hidden"))
          #:readers (list commonmark-reader)
          #:builders (list (blog)

Now just save the above as haunt.scm and put your markdown blog posts in
the posts directory with a .md extension and run `haunt build`. Here is
an example blog post:

    title: Hello World!
    date: 2016-07-24 10:00
    tags: guile, commonmark, scheme

    A CommonMark Document
    Here is some *scheme* `code`
    (display "Hello, World!")

    1. A list
    2. Another item in a list

    Read more about [CommonMark](

Please note the header on top portion of the post which allows you to
add metadata to your blog posts for haunt.



Attachment: guix.scm
Description: Text Data

reply via email to

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