XAO SPECIFICATION HANDBOOK

Xao Framework Specification · Release 1.0.0-dev

Markdown Aggregation

Convert CommonMark and GFM into CommonMark XML 1.0 natively in PHC via comrak and graft it into Xao DomDoc trees.

Document Slug
markdown-aggregation
Section
Framework Reference
Audience
Content platform and CMS developers
Status
stable
Source File
content/markdown-aggregation.md
XML Contract
/xml/markdown-aggregation

PHC's default build compiles the markdown-xml extension (comrak in safe Rust), providing phc_markdown_to_xml() and phc_markdown_to_dom() out of the box. Both emit CommonMark XML 1.0 (http://commonmark.org/xml/1.0) without DOCTYPE declarations so Markdown parses straight into DOMDocument, DOMXPath, Xao\DomDoc, and XSLTProcessor.

Native PHC Functions & Options

$xml = phc_markdown_to_xml($markdown, [
    'gfm' => true,
    'sourcepos' => false,
    'unsafe_html' => false,
    'front_matter_delimiter' => '---',
]);

$dom = phc_markdown_to_dom($markdown, ['gfm' => true, 'unsafe_html' => false]);
OptionTypeDefaultBehavior
gfmboolfalseEnables GFM tables, strikethrough, task lists, and autolinks
sourceposboolfalseAdds sourcepos attributes to XML elements
unsafe_htmlboolfalseStrips/escapes raw HTML blocks and inline HTML when false
front_matter_delimiterstringnullStrips leading frontmatter fenced by the delimiter

Preserving the CommonMark Namespace in DomDoc

When grafting a phc_markdown_to_dom() tree into a larger Xao\DomDoc conglomeration, use ndImportNode() rather than ndConsumeNode() so xmlns="http://commonmark.org/xml/1.0" is preserved for namespaced XSLT templates (xmlns:cm="http://commonmark.org/xml/1.0"):

$mdDoc = new DomDoc(phc_markdown_to_dom($markdownBody, [
    'gfm' => true,
    'unsafe_html' => false,
]));

$page = new DomDoc('xao-docs');
$bodyNode = $page->ndAppendToRoot('body');
$page->ndImportNode($mdDoc->getRoot(), true, $bodyNode);

CommonMark XML Elements for XSLT Authors

CommonMark + GFM emits clean, predictable XML elements:

Roadmap (P06)

Phase P06 in Xao's roadmap builds first-class Xao\MarkdownToXml and DomDoc::ndConsumeMarkdown() / ndConsumeMarkdownFile() helpers on top of this PHC primitive and integrates Markdown articles directly into the built-in catalog reference app alongside SQLite DbToXml.

Complete Handbook Index