<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/topiary-formatting-forests-a2qg3hip8" -->

---
title: Topiary: Formatting Forests | daily.dev
description: Topiary, a multi-language code formatter built on Tree-sitter, now supports Language Injections — the ability to format embedded languages within host...
canonical: https://daily.dev/posts/topiary-formatting-forests-a2qg3hip8
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Topiary: Formatting Forests | daily.dev
og:description: Topiary, a multi-language code formatter built on Tree-sitter, now supports Language Injections — the ability to format embedded languages within host...
og:url: https://daily.dev/posts/topiary-formatting-forests-a2qg3hip8
og:image: https://api.daily.dev/og/posts/A2qg3Hip8.png
og:image:alt: Topiary: Formatting Forests
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Topiary: Formatting Forests

**[Planet Haskell](https://daily.dev/sources/phaskell)** · 10 min read · 0 upvotes · 0 comments

## Summary

Topiary, a multi-language code formatter built on Tree-sitter, now supports Language Injections — the ability to format embedded languages within host documents. For example, OCaml code inside OCamllex files, or fenced code blocks in Markdown, are now formatted correctly and recursively. The feature works by running injection queries against the host AST to discover embedded spans, treating them as leaves during host formatting, then delegating each span to the appropriate inner language formatter. A LanguageResolver hook (using Arc for caching) ensures grammars are compiled only once per language, keeping performance sublinear in the number of injections. Known limitations include stateless formatting (cross-fence fragments can't share layout context) and grammars that require full source files. The feature is available now via Nix and will ship in an upcoming release.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://tweag.io/blog/2026-07-09-topiary-formatting-forests>

## Similar posts on daily.dev

- [Syntax Highlighting Demo](https://daily.dev/posts/syntax-highlighting-demo-ikao8rcnd) · Hacker News · 0 upvotes · 0 comments
- [My gift to the rustdoc team](https://daily.dev/posts/my-gift-to-the-rustdoc-team-7z6vzgbhb) · fasterthanli.me · 43 upvotes · 1 comments
- [A Better R Programming Experience Thanks to Tree-sitter](https://daily.dev/posts/a-better-r-programming-experience-thanks-to-tree-sitter-fd9e27ify) · Hacker News · 1 upvotes · 0 comments
- [Graphify: Unifying Codebase Context to Streamline Agentic Software Engineering](https://daily.dev/posts/graphify-unifying-codebase-context-to-streamline-agentic-software-engineering-lrwfsq2ei) · InfoQ · 1 upvotes · 0 comments
- [In situ Syntax Highlighting in macOS Applications Like Keynote](https://daily.dev/posts/in-situ-syntax-highlighting-in-macos-applications-like-keynote-p4p7zceki) · Eric Meyer — meyerweb.com · 0 upvotes · 0 comments

---

Tags: [#rust](https://daily.dev/tags/rust)

[View this post on daily.dev](https://daily.dev/posts/topiary-formatting-forests-a2qg3hip8)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Topiary: Formatting Forests","url":"https://daily.dev/posts/topiary-formatting-forests-a2qg3hip8","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/topiary-formatting-forests-a2qg3hip8"},"datePublished":"2026-07-09T15:19:06.926Z","dateModified":"2026-07-09T15:25:46.945Z","description":"Topiary, a multi-language code formatter built on Tree-sitter, now supports Language Injections — the ability to format embedded languages within host...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/022ae1f163e3837faf7572f4d1b4761b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/022ae1f163e3837faf7572f4d1b4761b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Planet Haskell","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Planet Haskell","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/cd3e48fb3b974d10993a5b5b8dcb8a08","url":"https://daily.dev/sources/phaskell"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/topiary-formatting-forests-a2qg3hip8","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"rust","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Planet Haskell","item":"https://daily.dev/sources/phaskell"},{"@type":"ListItem","position":3,"name":"Topiary: Formatting Forests"}]}
```

