Back to Blog

living-documentation-transclusion

Ohai TeamDecember 29, 20256 min read

Self-Updating Documentation: How Transclusion Keeps Your Docs in Sync with Code

Stop fighting documentation drift. Learn how transclusion creates living documentation that updates automatically when your code changes.


If you maintain API documentation, SDK references, or technical guides, you know the pain: the moment you publish documentation, it starts drifting from reality. Methods get renamed. Parameters change. Examples break. Your carefully crafted docs become a liability rather than an asset.

What if your documentation could update itself?

This is the promise of living documentation powered by transclusion - a technique that embeds actual source files directly into your markdown. When the code changes, the docs change with it. Automatically. Instantly.

The Documentation Drift Problem

Every technical writer and API maintainer has experienced this scenario:

  1. You write comprehensive documentation with code examples
  2. A developer refactors the API, renaming fetchWeather() to getCurrentWeather()
  3. Six months later, a user files an issue: "The method in your docs doesn't exist"
  4. You scramble to find and fix every stale reference

Documentation drift is not a matter of if - it is a matter of when. Traditional documentation workflows treat code and docs as separate artifacts that must be manually synchronized. This approach has a 100% failure rate over time.

The statistics are sobering. Studies show that up to 70% of code comments and documentation become outdated within two years. For fast-moving projects with frequent releases, the decay is even faster.

What Is Transclusion?

Transclusion is the inclusion of external content by reference rather than by copying. Instead of pasting code snippets into your markdown files, you reference the source file directly:

## API Reference

Here is our complete WeatherAPI implementation:

![[src/WeatherAPI.swift]]

That ![[...]] syntax tells the markdown reader to pull in the actual Swift file. The documentation displays the real, current source code - syntax-highlighted and always accurate.

This is fundamentally different from traditional documentation approaches:

Traditional Docs Transclusion
Copy-paste code snippets Reference source files
Manual updates required Automatic synchronization
Single point in time Always current
Drift is inevitable Drift is impossible

How Living Documentation Works in Practice

Consider a real-world example: documenting a Weather API SDK. Your API reference needs to show the main class implementation, data models, and error types.

With transclusion, your API-Reference.md looks like this:

# Weather API Reference

## WeatherAPI Class

The main entry point for all weather data:

![[../src/WeatherAPI.swift]]

## Data Models

These structures represent the data returned by the API:

![[../src/Models.swift]]

Now, when a developer adds a new method to WeatherAPI.swift:

/// Fetch historical weather for a past date
public func getHistoricalWeather(for location: String, on date: Date) async throws -> WeatherData {
    // implementation
}

The documentation updates instantly. No manual intervention. No pull request to update docs. No risk of forgetting.

Benefits for Technical Documentation Teams

Single Source of Truth

With transclusion, the code is the documentation. There is no separate artifact that can drift out of sync. When developers ask "is this documentation accurate?" the answer is always yes.

Reduced Maintenance Burden

Documentation maintenance is often the first casualty when teams are under pressure. Transclusion eliminates the need to manually update docs after every code change, freeing technical writers to focus on explanation and context rather than copy-paste synchronization.

Developer Confidence

Users trust documentation that they know is accurate. When your API reference literally displays the production code, developers can rely on what they read. This reduces support burden and improves developer experience.

Faster Iteration Cycles

Teams that use living documentation can iterate faster because documentation is no longer a bottleneck. Ship a new API version, and the docs are ready immediately.

Beyond Source Code: What You Can Transclude

While embedding source code is the most common use case, transclusion works with any file type:

  • Configuration files: Keep your setup guides in sync with actual config
  • Schema definitions: Embed JSON schemas, OpenAPI specs, or Protocol Buffers
  • Test files: Show real, working test examples that you know compile
  • Sample data: Include actual fixtures and mock data
  • Other markdown files: Build modular documentation from reusable components

You can even nest transclusions - a getting started guide can transclude an API reference that itself transcludes source files.

Implementing Transclusion in Your Workflow

To adopt living documentation with transclusion:

  1. Organize your repository so source files are accessible from documentation directories
  2. Use relative paths in transclusion syntax: ![[../src/MyClass.swift]]
  3. Choose a reader that supports transclusion - not all markdown renderers handle this syntax
  4. Train your team to reference files instead of copying code

The initial investment is minimal, but the ongoing maintenance savings compound over time.

Common Objections Addressed

"What if we need to show only part of a file?"

Some transclusion implementations support line ranges or named sections. For example: ![[file.swift#L10-L25]] or using specially formatted comments to define sections.

"What about documentation for multiple versions?"

Use git branches or tags. Your documentation repository can reference specific versions of source files, giving you versioned living documentation.

"Does this work for generated documentation sites?"

Yes. Many static site generators support transclusion or can be extended with plugins. The key is processing transclusion references at build time.

Try Living Documentation Today

If documentation drift is a constant battle for your team, transclusion offers a way out. By making the code itself the source of truth, you eliminate an entire category of documentation bugs.

Ohai Markdown Reader supports transclusion natively with the ![[file]] syntax. Open any markdown file that references other files, and watch them render inline, with full syntax highlighting and live updates when source files change.

Whether you are maintaining API documentation, SDK references, internal wikis, or technical specifications, living documentation through transclusion can transform your workflow from constant catch-up to effortless accuracy.

Download Ohai Markdown Reader and experience documentation that never goes stale.


Ready to see transclusion in action? Check out our Living Documentation Demo to try it yourself with a sample Weather API SDK.