Skip to content

ButterIX v1 is out: versions, multiple languages, Ask AI, and a per-site MCP server, all built in. →

Code from files

<Code> reads a project file or URL at build time and highlights it.

Reads a file from your project (or a URL) at build time and highlights it, keeping docs in sync with real code:

<Code src="/docs.yml" lines="1-6" title="docs.yml (this site, first 6 lines)" />
docs.yml (this site, first 6 lines)
# ButterIX 官方文档站(本身就是一个 biti 项目,也是全部功能的验收样例)
# 配置参考:pages/configuration/docs-yml.mdx
title: ButterIX
description: 从 OpenAPI 与 MDX 生成精致的 API 文档站:纯静态产物、多版本、多语言、SEO 与 Agent 友好,可托管也可自托管。
instances:
  - url: https://docs.butterix.com
srcstringRequired
File path (a leading / means the project root; otherwise relative to the project root or the current page), or a public https:// URL (downloaded at build time, 8-second timeout; local and private-network addresses aren't allowed).
linesstring | array
Show only these lines, e.g. "1-6", {["1-3", 8]}.
languagestring
Language; inferred from the extension by default.

All CodeBlock props are supported too (title, highlight, focus, startLine, maxLines, wordWrap, showLineNumbers, for, links, collapsible). A missing file produces a code/src warning.

Use a string or an array of strings for line props. In lines={[1-3]}, 1-3 is a subtraction expression and is rejected by the safe subset (an mdx/attribute error).