# Keep code blocks intact when you transform Markdown

> Agno's agno.utils.markdown.advance_code_fence exposes the rules Agno's page chunker uses to find code fences. Your own Markdown transforms can use it to leave code examples untouched.

- Published: 2026-09-08
- Author: Ashpreet Bedi
- Categories: Changelog
- Canonical: https://www.agno.com/articles/keep-code-blocks-intact-when-you-transform-markdown
- Markdown: https://www.agno.com/articles/keep-code-blocks-intact-when-you-transform-markdown.md

Agno now exposes `advance_code_fence` in `agno.utils.markdown`, the same fence tracking Agno's page chunker uses. A `sync_pages` transform sees every line of a page, code included, and `advance_code_fence` lets it change the prose and leave code examples exactly as written.

Feed `advance_code_fence` one line at a time with the state it returned for the previous line. This transform decodes HTML entities in prose and skips anything inside a fence. Agno calls a transform with the page's text and the page's `path` as a keyword argument, so the function accepts both.

```python
import html

from agno.utils.markdown import advance_code_fence

def normalize_prose(markdown: str, path: str = "") -> str:
    output, fence = [], None
    for line in markdown.splitlines(keepends=True):
        was_code = fence is not None
        fence, delimiter = advance_code_fence(line.rstrip("\r\n"), fence)
        output.append(line if was_code or delimiter else html.unescape(line))
    return "".join(output)

report = knowledge.sync_pages(url="https://docs.agno.com/llms.txt", transform=normalize_prose)
```

Given `Use <Agent> here.`, a Python block containing `x = a < b`, and `Done & dusted.`, `normalize_prose` returns `Use <Agent> here.` and `Done & dusted.` and leaves the code line as `x = a < b`.

In `advance_code_fence`, a closing fence has to use the same character as the opening fence and be at least as long. A four-backtick block can therefore show a three-backtick example safely. `advance_code_fence` also counts fences indented inside Markdown or MDX.

See the [cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/05_agent_os/27_public_pages/full_page.py), and learn more about [transforming published Markdown](https://docs.agno.com/knowledge/published-pages#synchronize-published-markdown) in the documentation.
