# Source mode

> Edit a page's raw MDX, frontmatter included, in a code editor with syntax highlighting and code folding.

Source mode shows the page's raw MDX, frontmatter and all. Use it when you want exact control over the file.

## Switching modes

Click **Source** in the top bar to switch, and **Visual** to switch back. Both modes edit the same file, and your unsaved changes come with you.

Switching doesn't rewrite your page. When Typemark saves from visual mode, it keeps the parts you didn't edit byte for byte, so a page you also edit in your own editor or on GitHub doesn't pick up surprise diffs.

## What you get

- **Syntax highlighting** for Markdown and for the code inside fenced code blocks
- **Line numbers** and an active-line highlight
- **Code folding** from the gutter, to collapse sections under a heading
- **Bracket matching** and auto-closing brackets and quotes
- **Search** with `Cmd+F`, including replace
- **Undo and redo** with `Cmd+Z` and `Cmd+Shift+Z`
- **Tab** to indent

Saving works the same as in visual mode: Typemark saves three seconds after you stop typing, and `Cmd+S` saves right away. The undo and redo buttons in the top bar belong to visual mode, so use the keyboard here.

## What you see

A typical page in source mode:

````mdx
---
title: "Authentication"
description: "Secure your API with token-based auth."
---

All API requests require a Bearer token in the `Authorization` header.

<Callout type="warning">
  Never expose your API key in client-side code.
</Callout>

## Getting a token

```bash
curl -X POST https://api.acme.com/auth/token \
  -d '{"email": "user@acme.com", "password": "secret"}'
```
````

## Frontmatter

In source mode, frontmatter is part of the file. Edit the YAML between the `---` lines directly:

```yaml
---
title: "My page title"
description: "A brief description for search engines."
icon: "book-open"
---
```

This is the place for fields the visual editor doesn't show, like `icon`. Typemark saves your frontmatter exactly as you typed it, keeping your key order and quote style. Title and description changes show up in visual mode when you switch back.

## When a page opens here on its own

If the visual editor can't open a page safely, the page opens in source mode with a banner that explains why. Fix the MDX, then click **Visual** to try again.

## When to use which

<Tabs>
  <Tab title="Source mode">
    - You need precise control over the MDX
    - You're pasting content from another Markdown source
    - You want to edit frontmatter fields beyond the title and description
    - You're tracking down a rendering issue
    - You'd rather work in a code editor
  </Tab>
  <Tab title="Visual mode">
    - You're writing new content
    - You want to see how the page looks as you type
    - You're working with components like callouts, tabs, and cards
    - You'd rather not think about syntax
  </Tab>
</Tabs>

See [Keyboard shortcuts](https://docs.typemark.dev/editor/keyboard-shortcuts) for the full list.
