00%
blog.info()
← Back to Home
SEQUENCE // Building The Blog

Displaying Abstract Syntax Trees

Author Thorn Hall
0

The AST for each article can now be found at the end of the page.

What is an Abstract Syntax Tree?

To understand ASTs, let's put it in context of this blog.

My blog is a static site generator (SSG). That means it generates the HTML you're seeing based on raw data, usually markdown files. In my case, I do indeed use markdown files for my posts. What does markdown look like?

 1---
 2title: Displaying Abstract Syntax Trees 
 3slug: building-ast
 4date: Nov 26, 2025
 5category: Engineering
 6excerpt: Rendering ASTs at the bottom of each article.
 7---
 8## What is an Abstract Syntax Tree?
 9To understand ASTs, let's put it in context of this blog.
10
11My blog is a static site generator. That means it generates the HTML you're seeing based on raw data, usually markdown files.
12In my case, I do indeed use markdown files for my posts. What does markdown look like?

This is what the markdown files look like. Notice that it's very simple - no HTML, CSS, or JavaScript. This allows the writer (me) to focus only on writing the story, not the details of how the story is displayed for every article. It keeps the style consistent across articles as well.

But how does my SSG know how to convert the markdown files into HTML? Enter the AST.

Abstract Syntax Tree

An AST is a representation of the article's content. Each piece of data is a node on the tree.

Let's look at a simple example.

1## Simple Example
2I wanted to show a simple example.
3
4Here's some more simple words:
5- Food
6- Drinks
7- Animals

The AST for this markdown looks like this:

1// Document
2// -- Heading -------> ## Simple Example
3// -- Paragraph --------> I wanted to show a simple example.
4// -- Paragraph --------> Here's some more simple words:
5// -- List
6// -- -- ListItem --------> Food
7// -- -- ListItem --------> Drinks
8// -- -- ListItem --------> Animals

Why it's Useful

ASTs allow us to infer information about the structure of code (or markdown, in this case.) That structure can be used to then determine things like:

  • How a program is interpreted
  • What colors to display for different and related parts of the content
  • What HTML and CSS properties are applied to each part of the content (our SSG's use case)

How This Blog Displays the AST

My blog has two steps:

  • A build phase, where all the HTML is pre-built/rendered before the server even starts
  • A run phase, where the server is actively running and serving those files over the internet

To show the AST, I used the build-time phase to pre-render the HMTL of the AST. This means less work for your browser to do. A less optimal implementation would have generated the ASTs dynamically when your browser fetched the web page.

Conclusion

Now you can see the AST of every page I've written, giving you direct insight into the internals of how a SSG works.

View Abstract Syntax Tree (Build-Time Generated)
Document
Paragraph
Text "The AST for each article ca..."
Text " page."
Heading
Text "What is an Abstract Syntax"
Text " Tree?"
Paragraph
Text "To understand ASTs, let's p..."
Text " blog."
Paragraph
Text "My blog is a static site ge..."
Text " files."
Text "In my case, I do indeed use..."
Text " like?"
FencedCodeBlock code: "--- "
Paragraph
Text "This is what the markdown f..."
Text "(me)"
Text "to focus only on writing th..."
Text " across"
Text "articles as"
Text " well."
Paragraph
Text "But how does my SSG know ho..."
Text " AST."
Heading
Text "Abstract Syntax"
Text " Tree"
Paragraph
Text "An AST is a representation ..."
Text " tree."
Paragraph
Text "Let's look at a simple"
Text " example."
FencedCodeBlock code: "## Simple Example "
Paragraph
Text "The AST for this markdown l..."
Text " this:"
FencedCodeBlock code: "// Document "
Heading
Text "Why it's"
Text " Useful"
Paragraph
Text "ASTs allow us to infer info..."
Text " like:"
List
ListItem
TextBlock
Text "How a program is"
Text " interpreted"
ListItem
TextBlock
Text "What colors to display for ..."
Text " content"
ListItem
TextBlock
Text "What HTML and CSS propertie..."
Text " case)"
Heading
Text "How This Blog Displays the"
Text " AST"
Paragraph
Text "My blog has two"
Text " steps:"
List
ListItem
TextBlock
Text "A build phase, where all th..."
Text " starts"
ListItem
TextBlock
Text "A run phase, where the serv..."
Text " internet"
Paragraph
Text "To show the AST, I used the..."
Text " optimal"
Text "implementation would have g..."
Text " page."
Heading
Text "Conclusion"
Paragraph
Text "Now you can see the AST of ..."
Text " works."