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

**URL:** <https://discourse.gohugo.io/t/is-it-possible-to-get-the-ast-for-a-markdown-file/42843>\
**Category:** support\
**Created:** [February 8, 2023, 1:03am UTC](https://discourse.gohugo.io/t/is-it-possible-to-get-the-ast-for-a-markdown-file/42843 "2023-02-08T01:03:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![verdverm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/verdverm/32/18748_2.png) [@verdverm](https://discourse.gohugo.io/u/verdverm)\
**Post date:** [February 8, 2023, 1:03am UTC](https://discourse.gohugo.io/t/is-it-possible-to-get-the-ast-for-a-markdown-file/42843/1 "2023-02-08T01:03:55Z")

</div>

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

Context:

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](https://gohugo.io/templates/output-formats/) is the way to go? I could in theory create a JSON output, but would like sections nested by heading size if possible

* * *

updates:

I am using a custom JSON layout as follows

### layouts/\_default/baseof.json

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

```

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

```auto
{{ define "main" }}
{{ $page := .Page }}
"uri": "{{ $page.Permalink }}"
"title": {{ $page.Title | jsonify }}
"tags": {{ $page.Params.tags | jsonify }}
"description": {{ $page.Description | jsonify }}
"resources": {{ $page.Resources }}
"content": ###"""
{{$page.RawContent}}
"""###
{{ 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
