---
title: "mkblog Can Now Embed Source Files"
date: 2026-03-29
tags:
  - cli
  - unix
  - source
---

`mkblog` already knew how to embed local terminal recordings. Now it can do the same sort of thing for source files.

The new `source` shortcode reads from `content/snippets/`, applies syntax highlighting at build time, and lets a post pull in either a whole file or a specific line range. That keeps examples local to the repo instead of pasting stale copies into Markdown by hand.

The storage convention is simple: put a file under `content/snippets/` and reference it with a `/snippets/...` path.

Basic usage looks like this:

```text
{{< source "/snippets/mkblog-source-demo.go" >}}
```

And a ranged embed looks like this:

```text
{{< source "/snippets/mkblog-source-demo.go" lines="5-9" >}}
```

There are a few optional knobs as well:

```text
{{< source "/snippets/mkblog-source-demo.go" lines="5-11" title="summarize helper" hl="7-9" >}}
{{< source "/snippets/mkblog-source-demo.go" lang=go >}}
{{< source "/snippets/mkblog-source-demo.go" lines="8" >}}
```

The examples above are written with a space between the first two braces so they render as literal text in this post. Remove that space in a real post.

Here is the whole demo file embedded, with highlighting :
```text
{{< source "/snippets/mkblog-source-demo.go" hl="7-9" >}}
```
{{< source "/snippets/mkblog-source-demo.go" hl="7-9" >}}

And here is the function body as a range, with highlighting:
```text
{{< source "/snippets/mkblog-source-demo.go" lines="5-11" title="summarize helper" hl="7-9" >}}
```

{{< source "/snippets/mkblog-source-demo.go" lines="5-11" title="summarize helper" hl="7-9" >}}

Single-line embeds work too, which is useful when a post wants to point at one exact return path instead of a full block:

{{< source "/snippets/mkblog-source-demo.go" lines="10" title="single line example" >}}

That gives `mkblog` a second local-first embed path: casts for terminal sessions, snippets for source. Both keep the interesting material in the site tree, where it can be versioned, reviewed, and updated without chasing copies across old posts.
