---
title: GitHub Markdown export
description: Export `md` source or semantic `Document` trees as GitHub-flavored Markdown
  (GFM).
order: 3
---
Both [`md2gfm`](md.md#md2gfm) and [`mdhtml2gfm`](md.md#mdhtml2gfm) resolve cross-references, numbering, captions, and citations through the shared Rust index without mutating their input, retaining complete YAML frontmatter.

```python
gfm = md2gfm("# Intro\n\nSee [@sec-a].\n\n## Details {#sec-a}\n\nDone.")
assert "Details" in gfm and not gfm.warnings
```

Invalid reference targets, heading-numbering schemes, or `cite_style` values raise `ValueError`.

## md2gfm

```python
def md2gfm(
    src:str, # Source text in the `md` dialect
    dest:str | Path | None=None, # Optional output file path
    reftypes:dict | None=None, # Override reference-type prefixes
    number_headings:str | dict | bool | None=None, # Heading numbering scheme, `False`, or `None`
    math:"Literal['brackets', 'dollars', 'off']"='brackets', # Math syntax mode
    implicit_figures:bool=False, # Promote image-only paragraphs to figures?
    templates=None, # Optional `TemplateDelimiter` sequence
    tmpl=None, # Optional `(node) -> str | None` renderer for semantic operations
    raw:tuple[str, ...]=('md', 'gfm'), # Raw block/inline formats to pass through verbatim
    imgdir:str | Path | None=None, # Optional directory to extract `data:` URI images into
    link=None, # Optional `(url) -> str | None` URL rewriter
    cite_style:"Literal['author-year', 'numeric'] | None"=None, # Citation style (`None` inherits metadata)
)->Md: # Exported GFM (`str` subclass) carrying `.warnings`
```

*Convert `md` source directly to GitHub-flavored Markdown through the shared [`Document`](parse.md#document) representation.*

## mdhtml2gfm

```python
def mdhtml2gfm(
    src, # `Document`, symbolic MDHTML string, or `fast5ever` DOM
    dest:str | Path | None=None, # Optional output file path
    reftypes:dict | None=None, # Override reference-type prefixes
    number_headings:str | dict | bool | None=None, # Heading numbering scheme, `False`, or `None`
    tmpl=None, # Optional `(node) -> str | None` renderer for semantic operations
    raw:tuple[str, ...]=('md', 'gfm'), # Raw block/inline formats to pass through verbatim; others are omitted
    imgdir:str | Path | None=None, # Optional directory to extract `data:` URI images into
    link=None, # Optional `(url) -> str | None` URL rewriter for non-extracted URLs
    cite_style:"Literal['author-year', 'numeric'] | None"=None, # Citation style (`None` inherits metadata, defaulting to `'author-year'`)
)->Md: # Exported GFM (`str` subclass) carrying `.warnings`
```

*Export a [`Document`](parse.md#document) or symbolic MDHTML as GitHub-flavored Markdown with shared Rust numbering, citations, and reference text.*

## Md

```python
def Md(
    s:str, warnings:list
):
```

*Exported Markdown (`str` subclass) carrying the export's `.warnings` list.*
