---
title: migrate
description: Convert Quarto sources and settings for Fastship
---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

`ship-migrate-quarto` converts a Quarto site or nbdev project in place. Read the migration instructions below before running it.

Python callers use `migrate_quarto(path)` and receive the source-to-destination rename mapping. Pass `extra_moves` for additional files to rename.

## Source conversion

Renaming a document also requires updating references to it. A page beside `guide.qmd` refers to it differently from a page in a subdirectory: `guide.qmd` versus `../guide.qmd`. Migration calculates replacement paths from the documentation root and from each source file’s directory.

The current implementation performs text replacement rather than parsing links. Matching text outside link destinations can also change.

The Markdown copy of each page also moves. Quarto published `page.html.md` beside `page.html`; Fastship publishes `page.md`. Hand-written indexes such as `llms.txt` often link these copies, so migration rewrites `.html.md` targets to `.md` in Markdown sources and `.txt` files.

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

### repl\_html\_md\_links

```python
def repl_html_md_links(
    txt
):
```

*Rewrite Quarto `.html.md` Markdown-copy targets to Fastship's `.md`*

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

### repl\_qmd\_links

```python
def repl_qmd_links(
    txt, moves, src, root
):
```

*Rewrite relative and root-relative `.qmd` link targets to `.md`*

Quarto lets authors mark a block of content for a particular output format—for example, HTML for the website or Markdown for a README. Migration replaces Quarto's `.content-visible` divs with [`mdhtml.fill`](https://AnswerDotAI.github.io/mdhtml/api/fill.html) mustache sections (`{{#html}}`, `{{#md}}`, `{{^html}}`, `{{^md}}`), keeping any remaining attributes as an inner div and preserving Markdown rendering inside both formats.

Migration also moves Quarto callout `title="..."` attributes onto a leading `## Title` heading inside the callout when no heading is present.

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

### repl\_callout\_titles

```python
def repl_callout_titles(
    s
):
```

*Move Quarto callout `title="..."` attributes into a leading `## Title` heading inside the callout*

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

### repl\_content\_visible

```python
def repl_content_visible(
    s
):
```

*Convert Quarto `::: {.content-visible when-format=... / unless-format=...}` to `{{#html}}` / `{{#md}}` / `{{^html}}` / `{{^md}}`*

Fastship reads Quarto's frontmatter keys as they are, such as `toc-depth`, `page-layout` and `categories`, so migration leaves them alone. It changes one thing: Fastship shows a page's `description` under its title, where Quarto shows `subtitle`, so a `subtitle`, or a legacy `summary`, becomes the description. A page that already has a description keeps it, and its `subtitle` is reported as unsupported.

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

### repl\_frontmatter\_keys

```python
def repl_frontmatter_keys(
    s
):
```

*Move Quarto's `subtitle`, or a legacy `summary`, to the `description` Fastship shows, unless the page has one*

Documentation conversion must not rewrite executable notebook code or discard saved outputs. [`migrate_md_file`](migrate.md#migrate_md_file) applies the text processors to a Markdown, QMD, or text file in place, while [`convert_quarto_nb`](migrate.md#convert_quarto_nb) converts only raw frontmatter and Markdown cells.

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

### migrate\_md\_file

```python
def migrate_md_file(
    path, procs
):
```

*Apply `procs` to a Markdown, QMD or text file in-place*

[`read_quarto_config`](migrate.md#read_quarto_config) reads a YAML mapping and rejects scalars and lists. [`quarto_config`](migrate.md#quarto_config) copies basic website and HTML settings (`title`, `description`, `site-url`, `favicon`, `open-graph`, `twitter-card`, `image`, `toc`, `toc-depth`, `output`) and enables `math = "dollars"`.

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

### quarto\_config

```python
def quarto_config(
    qy, root:str='.', overrides=None
):
```

*Convert basic Quarto website and HTML keys (`title`, `description`, `site-url`, `favicon`, `open-graph`, `twitter-card`, `image`, `toc`, `output`) to Fastship settings.*

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

### read\_quarto\_config

```python
def read_quarto_config(
    path
):
```

*Read a Quarto YAML mapping; missing or empty files give empty settings*

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

### parse\_quarto\_config

```python
def parse_quarto_config(
    text:str, path:str='_quarto.yml'
):
```

*Parse Quarto YAML `text` into a mapping; empty text gives empty settings*

## Applying the migration

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

### migrate\_quarto\_source

```python
def migrate_quarto_source(
    path, procs
):
```

*Convert one Markdown/QMD document or notebook in place using `procs`.*

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

### convert\_quarto\_nb

```python
def convert_quarto_nb(
    nb, procs, path:str='notebook.ipynb'
):
```

*Convert a leading raw YAML frontmatter cell to Markdown and apply `procs` to Markdown cells in place.*

[`migrate_quarto_source`](migrate.md#migrate_quarto_source) applies the text processors to a Markdown/QMD file or notebook Markdown cells, converting any leading `raw` frontmatter cell in a notebook to Markdown without touching code cells or saved outputs.

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

### migrate\_pyproject

```python
def migrate_pyproject(
    proj_root:pathlib._local.Path, extra_cfg:dict=None, write_table:bool=True
)->bool:
```

*Migrate `[project.entry-points.nbdev]` -\> `fastship` (preserving custom providers) and `[tool.nbdev]` -\> `[tool.fastship]`*

For a standalone Quarto site, migration writes `ship.toml` unless the site already has Fastship settings. For nbdev, it merges basic Quarto and `nbdev.yml` site settings into `[tool.fastship]` in `pyproject.toml`.

`extra_moves` maps source Paths to destination Paths, using filesystem paths just like the returned rename map. These pairs join document renames for conflict checks, link updates, and renaming. Extra files outside the document formats are not read or converted.

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

### migrate\_quarto

```python
def migrate_quarto(
    path, # Source directory or project root
    extra_moves=None, # Additional source-to-destination Path pairs
):
```

*Convert Quarto or nbdev sources and basic settings in place, returning the source rename mapping.*

The notebook below contains a saved result and code that must not execute during migration.

```python
migration_tmp = tempfile.TemporaryDirectory()
root = Path(migration_tmp.name)/'docs'
root.mkdir()
(root/'_quarto.yml').write_text('''project:
  output-dir: ../_site
website:
  title: Demo
''')
(root/'guide.qmd').write_text('''---
subtitle: A guide
---

[Notebook](index.ipynb)

::: {.content-visible when-format="html"}
Web note
:::

::: {.callout-note title="Heads up"}
Check links after migrating.
:::
''')
code = mk_cell('raise RuntimeError("do not run")')
code.outputs = [dict(output_type='stream', name='stdout', text='Saved result\n')]
book = new_nb([mk_cell('See [Guide](guide.qmd) and [API](api.html.md)', 'markdown'), code])
write_nb(book, root/'index.ipynb')
```

Migration renames the static `.qmd` guide, moves `subtitle` to `description`, converts `.content-visible` and callout `title=`, and writes basic settings to `ship.toml`:

```python
moves = migrate_quarto(root)
test_eq(moves, {root/'guide.qmd': root/'guide.md'})
guide = (root/'guide.md').read_text()
test_eq(frontmatter(guide)[0]['description'], 'A guide')
assert '{{#html}}\nWeb note\n{{/html}}' in guide
assert '## Heads up\n\nCheck links after migrating.' in guide
```

Notebook Markdown links change, while executable code and saved outputs remain intact.

```python
migrated = read_nb(root/'index.ipynb')
test_eq(migrated.cells[0].source, 'See [Guide](guide.md) and [API](api.md)')
test_eq(migrated.cells[1].source, code.source)
test_eq(migrated.cells[1].outputs, code.outputs)
```

Quarto notebooks usually keep frontmatter in a raw first cell. Migration converts it to Markdown, the only form Fastship reads, and converts its keys like any other frontmatter.

```python
post = new_nb([mk_cell('---\ntitle: Post\n---', 'raw'), mk_cell('Text.', 'markdown')])
with capture_output() as fm_report: assert convert_quarto_nb(post, [repl_frontmatter_keys], 'post.ipynb')
test_eq(post.cells[0].cell_type, 'markdown')
test_eq(frontmatter(post.cells[0].source)[0]['title'], 'Post')
assert 'converted raw frontmatter cell' in fm_report.stdout
```

A second migration has no files to rename and preserves the existing Fastship configuration.

```python
before = (root/'ship.toml').read_text()
test_eq(migrate_quarto(root), {})
test_eq((root/'ship.toml').read_text(), before)
test_eq(tomllib.loads(before)['title'], 'Demo')
```

The converted configuration preserves the output directory relative to the project.

```python
cfg = tomllib.loads(before)
test_eq(cfg['output'], '../_site')
```

```python
migration_tmp.cleanup()
```

Callers can supply additional renames. Their contents are not converted, but document links follow the new filenames. Existing destinations are rejected before source changes.

```python
with tempfile.TemporaryDirectory() as d:
    root = Path(d)
    manifest = root/'pyproject.toml'
    manifest.write_text('[tool.fastship]\ntitle="Keep me"\n')
    old,new = root/'old.bin',root/'new.bin'
    old.write_bytes(b'opaque payload')
    new.touch()
    (root/'guide.qmd').write_text('[Asset](old.bin)')
    with expect_fail(FileExistsError): migrate_quarto(root, extra_moves={old:new})
    test_eq((root/'guide.qmd').read_text(), '[Asset](old.bin)')
    new.unlink()
    moves = migrate_quarto(root, extra_moves={old:new})
    test_eq(moves[old], new)
    test_eq(new.read_bytes(), b'opaque payload')
    test_eq((root/'guide.md').read_text(), '[Asset](new.bin)')
    assert not (root/'ship.toml').exists()
    test_eq(manifest.read_toml()['tool']['fastship']['title'], 'Keep me')
```

A destination collision must stop migration before an existing file can be overwritten.

```python
with tempfile.TemporaryDirectory() as d:
    p = Path(d)
    (p/'_quarto.yml').touch()
    (p/'page.qmd').touch()
    (p/'page.md').touch()
    with expect_fail(FileExistsError, contains='page.md'): migrate_quarto(p)
```

Malformed YAML must fail before any source rename. This differs from a valid YAML value of the wrong type.

```python
with tempfile.TemporaryDirectory() as d:
    p = Path(d)
    (p/'guide.qmd').write_text('# Guide')
    (p/'_quarto.yml').write_text('website: [invalid')
    with expect_fail(yaml.YAMLError): migrate_quarto(p)
    assert (p/'guide.qmd').exists() and not (p/'guide.md').exists()
```

Valid YAML is not always valid configuration. Lists, booleans, and numbers must fail before source changes, whether they came from Quarto or an existing Fastship configuration.

```python
for invalid in ('[]', 'false', '0'):
    with expect_fail(ValueError): parse_ship_cfg(invalid)
    with expect_fail(ValueError, contains='mapping'): parse_quarto_config(invalid)
with tempfile.TemporaryDirectory() as d:
    nbs = Path(d)
    (nbs/'guide.qmd').write_text('# Guide')
    (nbs/'_quarto.yml').write_text('website:\n  title: Demo\n')
    (nbs/'ship.toml').write_text('[]')
    with expect_fail(ValueError): migrate_quarto(nbs)
    assert (nbs/'guide.qmd').exists() and (nbs/'_quarto.yml').exists()
    (nbs/'ship.toml').unlink()
    (nbs/'_quarto.yml').write_text('[]')
    with expect_fail(ValueError, contains='mapping'): migrate_quarto(nbs)
    assert (nbs/'guide.qmd').exists() and not (nbs/'guide.md').exists()
```

## Command line

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

### ship\_migrate\_quarto

```python
def ship_migrate_quarto(
    path:str='.', # Source directory or project root containing `_quarto.yml` or `nbdev.yml`
):
```

*Convert a Quarto or Quarto-nbdev project to Fastship in place; commit or back up first*

`ship-migrate-quarto [path]` calls [`ship_migrate_quarto`](migrate.md#ship_migrate_quarto); the source path defaults to the current directory. See `ship-migrate-quarto --help` for usage and the instructions below for the migration workflow.

Navbars, sidebars, drafts, `freeze`, CSS, bibliographies, profiles, and render scripts are left for manual review.

## Migration guide

`ship-migrate-quarto` handles the mechanical Quarto and `nbdev` conversions in place (commit or back up first):

- Renames static `.qmd` files (without `{python}` fences) to `.md` and updates relative `.qmd` and `.html.md` links to `.md`.
- Converts `::: {.content-visible when-format=... / unless-format=...}` blocks to `{{#html}}` / `{{#md}}` / `{{^...}}` conditionals and callout `title="..."` attributes to leading `## Title` headings.
- Moves `subtitle` or legacy `summary` frontmatter keys to `description` and converts leading notebook `raw` YAML frontmatter cells to Markdown.
- Copies basic `_quarto.yml` / `nbdev.yml` settings (`title`, `description`, `site-url`, `favicon`, `open-graph`, `twitter-card`, `image`, `toc`, `toc-depth`, `output`, `math = "dollars"`) into `ship.toml` or `[tool.fastship]`.
- Migrates `[tool.nbdev]` and `[project.entry-points.nbdev]` in `pyproject.toml` to `fastship` (preserving custom providers and refusing to overwrite an existing `ship.toml`).

Review and update these manually after running `ship-migrate-quarto`:

- **Layout:** rename `nbs/` or `docs/` to `ship/` (the default source directory), or set explicit `ship-path` in `ship.toml` or `[tool.fastship]`.
- **Navigation and styling:** port custom Quarto navbars (`nav-links`, `tools`), explicit sidebars (`sidebar-links`), and site stylesheets (`css`, without Bootstrap).
- **Execution and publishing:** review `.qmd` files with `{python}` fences (Fastship executes `{python}` in `.qmd` at build time and has no Quarto `freeze`), convert disabled fences to plain `python`, and set `draft-mode = "unlinked"` or `exclude` globs where drafts or private files exist.
- **Quarto-only features:** replace unsupported shortcodes (such as `{{< include >}}`), inline `bibliography` entries (see `mdhtml` citations), merge any Quarto profiles or `_metadata.yml` into directory `index.md` frontmatter, and switch CI workflows to `AnswerDotAI/workflows/ship-docs@master` and `ship-ci@master`.
- **Verify:** run `ship-docs --strict` and `ship-preview`, compare rendered HTML and `.md` pages against the original site, then remove legacy `_quarto.yml` / `nbdev.yml` / `sidebar.yml` files.
