Writing Content
Master MDX authoring, content organization, and best practices
Writing Content in Specra
Specra uses MDX (Markdown + JSX) for documentation, giving you the simplicity of Markdown with the power of React components. This guide covers everything you need to write great documentation.
MDX Basics
MDX files look like regular Markdown but let you use React components anywhere in your content.
Standard Markdown
All standard Markdown syntax works as expected:
Headings:
1# Heading 12## Heading 23### Heading 3Text formatting:
1**Bold text**2*Italic text*3~~Strikethrough~~4`Inline code`Lists:
1- Unordered list2- Another item3 - Nested item4 51. Ordered list62. Second item7 1. Nested ordered itemLinks and images:
1[Link text](https://example.com)2Code blocks:
1```javascript2function hello() {3 console.log("Hello, world!")4}5```Tables:
1| Column 1 | Column 2 | Column 3 |2|----------|----------|----------|3| Data 1 | Data 2 | Data 3 |4| More | Info | Here |Blockquotes:
1> This is a quote.2> It can span multiple lines.Horizontal rules:
1---Using Components
Components are used with JSX syntax directly in your MDX:
1<Callout type="info">2This is a callout component!3</Callout>All components are automatically available - no imports needed.
Component Examples
Alert readers to important information:
1<Callout type="warning">2Make sure to backup your data before proceeding.3</Callout>Create tabbed content:
1<Tabs defaultValue="option1">2<Tab label="Option 1">3Content for the first tab4</Tab>5<Tab label="Option 2">6Content for the second tab7</Tab>8</Tabs>Guide users through steps:
1<Steps>2<Step title="Install dependencies">3Run `npm install` to get started.4</Step>5<Step title="Configure your app">6Edit the config file with your settings.7</Step>8</Steps>See the Components section for all available components.
Content Organization
File Structure Best Practices
Organize files logically to make content easy to find:
1docs/v1.0.0/2├── getting-started.mdx # Top level: essential pages3├── installation.mdx4├── guides/ # Group related content5│ ├── _category_.json6│ ├── basics.mdx7│ ├── advanced.mdx8│ └── examples/ # Further nesting for sub-topics9│ ├── _category_.json10│ ├── example-1.mdx11│ └── example-2.mdx12└── api/13 ├── _category_.json14 └── reference.mdxTips:
- Keep the top level for critical pages users need first
- Use folders to group related content
- Limit nesting to 2-3 levels max
- Name files descriptively (
authentication.mdxnotauth.mdx)
Controlling Page Order
Use sidebar_position in frontmatter to control ordering:
1---2title: Installation3sidebar_position: 14---Lower numbers appear first. Pages without a position are sorted alphabetically.
For folders, use _category_.json:
1{2 "label": "Getting Started",3 "position": 14}Working with Images
Adding Images
Place images in the public/ folder:
1public/2├── images/3│ ├── screenshot.png4│ └── diagram.svgReference them in MDX:
1Image Best Practices
Use descriptive alt text:
1Optimize image sizes:
- Use WebP format when possible
- Compress images before adding to repo
- Keep images under 500KB
Use the Image component for advanced features:
1<Image2 src="/images/hero.png"3 alt="Hero image"4 caption="The main dashboard view"5 width={800}6 height={400}7/>Code Examples
Syntax Highlighting
Specify the language after the opening backticks:
1```javascript2const greeting = "Hello, world!"3console.log(greeting)4```5 6```python7def greet():8 print("Hello, world!")9```10 11```bash12npm install specra13```Supported languages include: javascript, typescript, python, bash, json, yaml, markdown, html, css, and many more.
Highlighting Lines
Highlight specific lines to draw attention:
1```javascript {2,4-6}2function calculateTotal(items) {3 const subtotal = items.reduce((sum, item) => sum + item.price, 0)4 const tax = subtotal * 0.15 const shipping = 5.996 const total = subtotal + tax + shipping7 return total8}9```File Names
Show which file the code belongs to:
1```javascript title="src/utils.js"2export function formatDate(date) {3 return date.toLocaleDateString()4}5```Use the CodeBlock Component
For more control:
1<CodeBlock2 language="javascript"3 title="src/app.js"4 highlightLines={[3, 5]}5 showLineNumbers={true}6>7{`function app() {8const config = loadConfig()9const server = createServer(config)10server.listen(3000)11console.log("Server running")12}`}13</CodeBlock>Links and Navigation
Internal Links
Link to other pages in your docs:
1See the [Configuration guide](/docs/v1.0.0/configuration/overview) for details.Use relative paths from the site root, including the version.
External Links
External links open in a new tab automatically:
1Check out the [SvelteKit documentation](https://svelte.dev/docs/kit).Anchor Links
Link to headings on the same page:
1Jump to [Installation](#installation) below.Heading anchors are auto-generated from the heading text in lowercase with hyphens.
Frontmatter Reference
Every MDX file needs frontmatter. Here's a complete example:
1---2title: Advanced Topics3description: Deep dive into advanced Specra features4sidebar_position: 105tab_group: guides6icon: zap7tags: [advanced, configuration, optimization]8draft: false9---10 11# Your content starts hereRequired fields:
title: Page title
Recommended fields:
description: SEO description (150-160 characters)
Optional fields:
sidebar_position: Number for sidebar orderingtab_group: Assign to a tab groupicon: Lucide icon nametags: Array of tagsdraft: Hide in production if true
Advanced MDX Features
Importing Components
While built-in components work automatically, you can import custom ones:
1import { MyCustomComponent } from '@/components/custom'2 3<MyCustomComponent data="example" />Using JavaScript Expressions
Embed JavaScript expressions:
1The current year is {new Date().getFullYear()}.Conditional Content
Use JavaScript for conditional rendering:
1{process.env.NODE_ENV === 'development' && (2 <Callout type="info">3You're viewing the development version.4 </Callout>5)}Version Management
When you need multiple doc versions:
1docs/2├── v1.0.0/3│ └── getting-started.mdx4├── v2.0.0/5│ └── getting-started.mdx6└── next/7 └── getting-started.mdxSet the active version in specra.config.json:
1{2 "site": {3 "activeVersion": "v2.0.0"4 }5}Users can switch versions with the version dropdown in the UI.