---
title: theme
description: Default styles, icons, and page layout
---
`fastship.theme` supplies the HTML layout, styles, icons, and browser interactions used by `fastship.site`. Normal site builds use it automatically. To customize a site's appearance, add stylesheets with `css` in `ship.toml`; you do not need to edit the bundled theme.

When rendering an article directly, use [`code_wrap`](theme.md#code_wrap) to add code-copy buttons and [`page_body`](theme.md#page_body) to place the rendered content in the page layout:

```python
from fastship.core import md2doc
from fastship.theme import code_wrap, page_body

article = md2doc('# Welcome\n\nMy project documentation.').to_html(code_wrap=code_wrap)
body = page_body(content=article, side=article.toc)
```

[`page_body`](theme.md#page_body) returns a tuple of `fastcore.xml` `FT` elements to put inside a page’s `<body>` (render with `to_xml(body, indent=False)`). It does not create a complete HTML document or load stylesheets and scripts. [`Site.build`](site.md#site.build) handles that assembly; you normally don’t need to call these helpers yourself.

Fastship's own CSS and JavaScript are bundled locally, while the AnswerUI stylesheet is loaded from a CDN.

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Stylesheets and scripts

The site build writes Fastship's shared styles and browser interactions once, rather than embedding them in every page. `ASSETS` maps the output paths `_fastship/fastship.css` and `_fastship/fastship.js` to their text. The original files live beside the Python module.

Use these output paths when linking pages to the bundled assets. [`head_tags`](theme.md#head_tags), shown below, makes the links relative to each page.

## Icons

`ICONS` maps bundled icon names to SVG markup. For example, `ICONS['github']` returns SVG you can insert into HTML. The icons use `currentColor`, so they inherit the surrounding text colour.

To use these icons as header links, configure `tools` in `ship.toml` as described in [fastship.site](site.md).

The brand marks (`github`, `x`, `discord`, `markdown`) come from [Simple Icons](https://simpleicons.org), released under CC0. The `rss` and `search` icons come from [Lucide](https://lucide.dev). Its ISC licence is reproduced in Fastship's `LICENSE`.

Available icon names:

```python
test_eq(sorted(ICONS), ['discord', 'github', 'markdown', 'rss', 'search', 'x'])
assert all(v.startswith('<svg') and 'currentColor' in v for v in ICONS.values())
sorted(ICONS)
```

```output
['discord', 'github', 'markdown', 'rss', 'search', 'x']
```

## Code-copy buttons

Normal site builds add Copy buttons to code blocks automatically. When rendering markdown directly, pass `code_wrap=code_wrap` to [`Doc.to_html`](core.md#doc.to_html) to use the same buttons. The generated page must load `fastship.js` for copying to work.

[`code_wrap`](theme.md#code_wrap) receives the highlighted HTML and wraps it with a button. Mermaid blocks take a different path: they use mdhtml's diagram renderer, without a Copy button.

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/theme.py#L44)

### code\_wrap

```python
def code_wrap(
    html:str, # The highlighted block
    lang:str, # Its language, or None for a bare fence
    text:str, # Its source, unescaped
    highlight=None, # Optional `(text, lang) -> inner_html | None` highlighter
):
```

*Add a copy button to code blocks, preserving Mermaid rendering*

Wrapping an ordinary code block adds the button markup; wrapping a Mermaid block leaves diagram rendering to mdhtml.

```python
wrapped = code_wrap('<pre><code>x = 1</code></pre>', 'python', 'x = 1')
assert 'vm-copy' in wrapped
assert 'vm-copy' not in code_wrap('<pre><code>graph TD</code></pre>', 'mermaid', 'graph TD')
assert 'data-lang="python"' in wrapped
assert 'data-lang=' not in code_wrap('<pre><code>plain</code></pre>', None, 'plain')
hl = lambda txt, lang: f'<span class="hl-keyword">{txt}</span>' if lang=='bpl' else None
assert '<span class="hl-keyword">1+2</span>' in code_wrap('<pre><code class="language-bpl">1+2</code></pre>', 'bpl', '1+2', highlight=hl)
wrapped
```

```output
'<div class="vm-code" data-lang="python"><pre><code>x = 1</code></pre><button class="vm-copy" type="button">Copy</button></div>'
```

[`regex_highlighter`](theme.md#regex_highlighter) compiles a mapping of `{lang: [(pattern, css_class_or_None), ...]}` into a highlighter callable for [`code_wrap`](theme.md#code_wrap) and [`Site`](site.md#site).

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/theme.py#L55)

### regex\_highlighter

```python
def regex_highlighter(
    langs:dict, # Mapping from fence language name to `[(pattern, css_class_or_None), ...]`
):
```

*Compile regex token rules per language into a `(text, lang) -> inner_html | None` highlighter*

```python
rhl = regex_highlighter({'bpl': [(r'\d+', 'hl-number'), (r'[a-z]+', None)]})
test_eq(rhl('x<1+2', 'bpl'), 'x&lt;<span class="hl-number">1</span>+<span class="hl-number">2</span>')
test_eq(rhl('x', 'python'), None)
```

## Tabsets

Use a `panel-tabset` fenced div to present alternatives as tabs. For example, show two ways to set a site's title:

````markdown
::: {.panel-tabset}
### Python

```python
site = Site.from_dir('docs', title='My project')
```

### ship.toml

```toml
title = "My project"
```
:::
````

Rendered with the theme, this becomes:

### Python

```python
site = Site.from_dir('docs', title='My project')
```

### ship.toml

```toml
title = "My project"
```

Each heading at the first heading's level starts a tab. Its content continues until the next heading at that level; lower-level headings remain inside the panel. Tabsets can also be nested.

The first tab opens initially. The theme's JavaScript switches panels when a tab is selected. Without JavaScript, all panels remain readable.

## Margin notes

Use a `column-margin` fenced div, Quarto's syntax, for a note beside the text:

```markdown
::: {.column-margin}
A margin note holds an aside that would interrupt the paragraph.
:::
```

Rendered with the theme, the note sits beside this paragraph on a wide screen:

A margin note holds an aside that would interrupt the paragraph.

On wide screens a margin note sits in the right-hand column, level with the top of the block written before it, as in Quarto. Consecutive notes stack. A note taller than the space before the next note overlaps that note. That column also holds the table of contents. While a note scrolls past the table of contents, the table of contents folds to its heading. Readers can still open it while it is folded. On narrow screens a margin note stays in the text as a small aside. A note inside a list, callout or other block always does.

The side panel's background, `--oct-bg`, covers notes that scroll behind it. `--oct-bg` is also the page background and defaults to AnswerUI's `--color-background`. To change the page background, set `--oct-bg` in your site's stylesheet.

## Page layout

[`page_body`](theme.md#page_body) assembles `fastcore.xml` `FT` elements (or raw HTML strings) for the header, navigation, article, table of contents, and footer into a tuple of `FT` elements. It does not render markdown or generate navigation links; the caller supplies those parts.

Standard pages place site navigation and a table of contents beside the article. Empty navigation and an empty table of contents are omitted. Both sidebars are collapsible, starting open in the HTML and collapsing on narrow screens through the theme's JavaScript.

Pass `custom=True` for a full-width article without either sidebar or the default `prose` typography attribute. In a site build, page frontmatter `page-layout: custom` selects this option. The supplied header, footer, and search dialog remain outside the article grid.

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/theme.py#L78)

### page\_body

```python
def page_body(
    header=None, # Site brand, tools, and search trigger (`FT` or HTML)
    navigation=None, # Site navigation (`FT` or HTML)
    content=None, # Article content (`FT`, HTML, or sequence of them)
    side=None, # Right-hand panel: a table of contents (HTML str) or category filters (`FT`)
    side_label:str='On this page', # Heading for the right-hand panel
    footer=None, # Site footer (`FT` or HTML)
    custom:bool=False, # Use the full-width custom layout without sidebars or prose typography
    actions=None, # Page actions, such as the Markdown link, shown below the side panel
    full:bool=False, # Use the full-width article layout (keeps sidebars and prose typography)
    discoverable:bool=True, # Include `<main>` in Pagefind search?
):
```

*Assemble the page body as a tuple of `FT` elements with collapsible navigation and side panel*

## Page styles and scripts

[`head_tags`](theme.md#head_tags) returns stylesheet, script, and optional favicon `FT` elements to put in a page's `<head>`. Pass the output page path as `dest`, and a function such as [`fastship.site.relhref`](site.md#relhref) to calculate relative links. Custom stylesheet, script and favicon paths are relative to the site root, not the page's directory.

Stylesheets load in this order: AnswerUI, Fastship (`@layer app`), Pagefind search, then custom CSS. Because Fastship's rules live in AnswerUI's `app` cascade layer, unlayered custom CSS overrides both without fighting specificity.

Custom scripts load as `<script type="module">`, after Fastship's own `fastship.js`. Like `defer` scripts, modules run in page order once the page has been read. A module can use `import` and top-level `await`, runs in strict mode, and keeps its top-level names to itself: to share a value with other scripts, assign it to a property of `window`.

AnswerUI is loaded from a CDN; its stylesheet is not copied into the site. When calling [`head_tags`](theme.md#head_tags) directly, pass `answerui=False` to omit that link, and supply local styles if needed. This is a [`head_tags`](theme.md#head_tags) argument, not a `ship.toml` setting.

The tags reference files; they do not write them. [`Site.build`](site.md#site.build) writes the Fastship assets and generates the Pagefind search files.

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/theme.py#L108)

### head\_tags

```python
def head_tags(
    dest:str, # Output page path relative to the site root
    rel, # `relhref`, or anything that makes one address relative to another
    css=None, # The site's own stylesheets, after fastship's
    js=None, # The site's own module scripts, after fastship's
    favicon=None, # The site's favicon icon path (relative to site root)
    answerui:bool=True, # Link the AnswerUI stylesheet?
):
```

*Return stylesheet, script, and favicon `FT` elements for a page*

For `api/config.html`, a stylesheet supplied as `styles.css` becomes `../styles.css`. Scripts, the favicon and bundled assets follow the same rule, so nested pages load the same files as the homepage.

```python
tags = head_tags('api/config.html', relhref, css='styles.css', js='site.js', favicon='favicon.png')
s = [str(t) for t in tags]
assert ANSWERUI_CSS in s[0]
order = [i for i,t in enumerate(s) if 'fastship.css' in t or 'pagefind-component-ui.css' in t or '../styles.css' in t]
test_eq(order, sorted(order))
assert '../_fastship/fastship.css' in s[1]
assert '../pagefind/pagefind-component-ui.css' in s[2]
assert any('new URL("../pagefind/pagefind-component-ui.js", document.baseURI)' in t for t in s)
assert '<link rel="icon" href="../favicon.png">' in s
assert s.index('<script type="module" src="../site.js"></script>') > next(i for i,t in enumerate(s) if 'fastship.js' in t)
L(tags)
```

```output
[<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@answerdotai/answerui@0/answerui/assets/styles.css">, <link rel="stylesheet" href="../_fastship/fastship.css">, <link rel="stylesheet" href="../pagefind/pagefind-component-ui.css">, <link rel="stylesheet" href="../styles.css">, <link rel="icon" href="../favicon.png">, <script type="module">
const scriptUrl = new URL("../pagefind/pagefind-component-ui.js", document.baseURI);
const bundleUrl = new URL(".", scriptUrl).href;
const config = document.createElement("pagefind-config");
config.setAttribute("bundle-path", bundleUrl);
document.body.prepend(config);
await import(scriptUrl.href);
</script>, <script defer src="../_fastship/fastship.js"></script>, <script type="module" src="../site.js"></script>]
```
