Is it possible to get the AST for a Markdown file?

Is it possible to get the Markdown AST using some Go?


  1. I’d like to do some manual processing on these files outside the scope of Hugo.
  2. I have some shortcodes that inject code from files, being able to get at these is also needed, but before turning them into html, I’d prefer their original contents so I can run tools on them

Alternatively, maybe a Custom Output Format is the way to go? I could in theory create a JSON output, but would like sections nested by heading size if possible


I am using a custom JSON layout as follows


{{- block "main" . }}{{- end }}

layouts/_default/single.json (I’m actually generating CUE)

{{ define "main" }}
{{ $page := .Page }}
"uri": "{{ $page.Permalink }}"
"title": {{ $page.Title | jsonify }}
"tags": {{ $page.Params.tags | jsonify }}
"description": {{ $page.Description | jsonify }}
"resources": {{ $page.Resources }}
"content": ###"""
{{ end }}

Now I should be able to parse the content by hand, or maybe with remark.js, tbd

The main issue I have now is the custom shortcodes, which I am probably going to handle with some regex