ewintr.nl

AsciiDoc parser

It started with some lines of throwaway code, held together by staples and duct tape in my little Shitty SSG project and it kept evolving. A long time ago I decided that I liked [AsciiDoc](AsciiDoc parser) better than [Markdown](AsciiDoc parser) when it comes to simple markup languages.

On the surface they are very similar, both are very easy to write and read and can be used in their "raw" form. You don't need to render a page before you can read it comfortably, unlike, for instance, HTML.

The difference becomes clear when you write texts that longer than the typical short comment or snippet. AsciiDoc is much more complete. You can write a whole book in it. I never did that, but I did notice that I started using it everywhere I could. Unfortunately there wasn't a really good library for Go available.

So I started one myself. The AsciiDoc specification is big and I started implementation with the features I use myself. It's far from complete, but here is the code.

Example

Run the snippet below on the Go Playground

package main

import (
  "fmt"
  "strings"

  "ewintr.nl/adoc"
)

func main() {
  sourceDoc := `= This is the title

And this is the first paragraph. With some text. Lists are supported too:

* Item 1
* Item 2
* Item 3

And we also have things like *bold* and _italic_.`

  par := adoc.NewParser(strings.NewReader(sourceDoc))
  doc := par.Parse()

  htmlDoc := adoc.NewHTMLFormatter().Format(doc)
  fmt.Println(htmlDoc)

  // output:
  //
  // <!DOCTYPE html>
  // <html>
  // <head>
  // <title>This is the title</title>
  // </head>
  // <body>
  // <p>And this is the first paragraph. With some text. Lists are supported too:</p>
  // <ul>
  // <li>Item 1</li>
  // <li>Item 2</li>
  // <li>Item 3</li>
  // </ul>
  // <p>And we also have things like <strong>bold</strong> and <em>italic</em>.</p>
  // </html>
}