While building an Laravel snippet plugin for the Atom text editor, I thought it would be helpful to produce human-friendly documentation for all the snippets contained in my plugin. This post is a quick tutorial demonstrating how to parse CSON files and produce documentation for your Atom plugin.

Atom’s snippets use CSON (CoffeeScript-Object-Notation), which is a readable enough format, but I wanted to combine all snippets into a generated, human-readable markdown document.

You can see the docs.js script in my Larasnippets plugin:

This script defines a Snippet object, and then loops through all .cson files. The cson module parses each snippet file into an Object which is then pushed into an array of Snippet objects. Finally, I used lodash to templatize the documentation block and loop through the snippets.

You can check out the example markdown output generated from the Node.js script script.