XaoDocs Accessible Linear Edition

Document Summary

Markdown Aggregation

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

Section
Framework Reference
Target audience
Content platform and CMS developers
Estimated reading time
2 minute(s) (250 words)
Major sections
4

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

Code example (php)
$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"):

Code example (php)
$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.