<?xml version="1.0" encoding="UTF-8"?>
<xao-docs>
  <site name="XaoDocs" product="Xao" version="1.0.0-dev" homepage="https://xao.ndx.au" repo="https://github.com/ndx-au/Xao" examples-repo="https://github.com/ndx-au/xao-example-apps"/>
  <request slug="markdown-aggregation" theme="atlas" path="/xml/markdown-aggregation" xml-url="/xml/markdown-aggregation"/>
  <themes>
    <theme id="atlas" name="Atlas" tagline="Three-column reference desk with persistent sidebar and sticky page outline" audience="API and framework developers browsing across sections" structure="3-column grid: left navigation sidebar, center article, right on-this-page outline" css="/assets/atlas.css" active="true"/>
    <theme id="folio" name="Folio" tagline="Editorial journal spread with XPath-grouped numbered chapters and collapsible library" audience="Architects and evaluators reading long-form conceptual chapters" structure="Editorial cover header, collapsible library drawer, and sibling-grouped numbered chapter sections" css="/assets/folio.css" active="false"/>
    <theme id="console" name="Console" tagline="Operations dashboard with telemetry strip and collapsible H2 module accordions" audience="SREs, operators, and runtime engineers scanning sections quickly" structure="Command header, telemetry bar, compact nav rail, and expandable &lt;details&gt; module accordions" css="/assets/console.css" active="false"/>
    <theme id="reader" name="Reader (A11y)" tagline="WCAG AAA single-column linear reader with upfront summary, numbered TOC, and zero JS" audience="Screen reader users, keyboard-only navigation, and low-vision / cognitive accessibility" structure="Multi-landmark skip links, upfront document summary, inline numbered TOC, figure-wrapped code blocks, directory after article, zero JS" css="/assets/reader.css" active="false"/>
    <theme id="handbook" name="Handbook" tagline="Single-column print-ready technical specification sheet with metadata ledger" audience="Technical reviewers, auditors, and print/PDF export workflows" structure="Single-column specification document with &lt;dl&gt; metadata ledger, numbered outline, and print stylesheet" css="/assets/handbook.css" active="false"/>
  </themes>
  <navigation>
    <section name="Start Here">
      <item slug="index" title="Xao Documentation" description="XML Application Objects for PHP 8 and PHC — zero-dependency XML content aggregation and XSLT 3.0 presentation." order="1" active="false"/>
      <item slug="getting-started" title="Getting Started" description="Set up PHC, autoload Xao with zero Composer packages, transform your first DomDoc with XSLT 3.0, and run phc serve." order="2" active="false"/>
    </section>
    <section name="Core Concepts">
      <item slug="architecture" title="Architecture &amp; XML Aggregation" description="How Xao builds a unified XML conglomeration document from databases, Markdown, and domain objects before delegating presentation to XSLT 3.0." order="3" active="false"/>
      <item slug="xslt-themes" title="XSLT 3.0 Themes vs CSS Skins" description="Why XSLT themes are structurally and semantically richer than CSS-only themes — including accessibility-first DOM transformations." order="4" active="false"/>
    </section>
    <section name="Framework Reference">
      <item slug="core-api" title="Core API Reference" description="Reference for Xao\\Runtime, Xao\\XaoRoot, Xao\\DomDoc, Xao\\DomFactory, Xao\\AppDoc, Xao\\Http\\Response, and Xao\\Exceptions." order="5" active="false"/>
      <item slug="database-aggregation" title="Database Aggregation (DbToXml)" description="Convert PDO queries, PDOStatement results, and PHP iterables directly into structured DomDoc XML fragments under PHC." order="6" active="false"/>
      <item slug="markdown-aggregation" title="Markdown Aggregation" description="Convert CommonMark and GFM into CommonMark XML 1.0 natively in PHC via comrak and graft it into Xao DomDoc trees." order="7" active="true"/>
      <item slug="xslt-drivers" title="XSLT 3.0 Drivers" description="Pluggable XsltDriverInterface strategies: PhcNativeXsltDriver (default in-process), SaxonHttpDriver (HTTP/distributed), and ClientSideXslDriver." order="8" active="false"/>
    </section>
    <section name="Operations &amp; Runtime">
      <item slug="phc-runtime" title="PHC Runtime &amp; Compatibility" description="Running Xao on PHC in isolate and worker modes, sandbox defaults, worker-safe autoloading, and P00–P05 compatibility findings." order="9" active="false"/>
      <item slug="security" title="Security Model" description="XXE rejection, realpath containment, strict slug allowlists, CSRF guards, gated debug output, and PHC sandbox enforcement." order="10" active="false"/>
    </section>
    <section name="Examples &amp; Design">
      <item slug="reference-apps" title="Reference Applications" description="Comparing Xao's built-in SQLite PDO catalog reference app with XaoDocs, the flat-file Markdown multi-theme CMS." order="11" active="false"/>
      <item slug="adr-0001-phc-xee-xslt" title="ADR 0001 &amp; Roadmap" description="Architecture Decision Record for pure-Rust xee-xslt in PHC plus the Xao v1.0.0 milestone and phase roadmap (M0–M3, P00–P06)." order="12" active="false"/>
    </section>
  </navigation>
  <page slug="markdown-aggregation" title="Markdown Aggregation" description="Convert CommonMark and GFM into CommonMark XML 1.0 natively in PHC via comrak and graft it into Xao DomDoc trees." section="Framework Reference" audience="Content platform and CMS developers" status="stable" words="250" reading-minutes="2" source-file="content/markdown-aggregation.md">
    <tags>
      <tag>markdown</tag>
      <tag>commonmark</tag>
      <tag>comrak</tag>
      <tag>phc</tag>
    </tags>
    <neighbors>
      <prev slug="database-aggregation" title="Database Aggregation (DbToXml)"/>
      <next slug="xslt-drivers" title="XSLT 3.0 Drivers"/>
    </neighbors>
    <body>
      <document xmlns="http://commonmark.org/xml/1.0">
        <heading level="1">
          <text xml:space="preserve">Markdown Aggregation</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">PHC's default build compiles the </text>
          <strong>
            <code xml:space="preserve">markdown-xml</code>
          </strong>
          <text xml:space="preserve"> extension (</text>
          <code xml:space="preserve">comrak</code>
          <text xml:space="preserve"> in safe Rust), providing </text>
          <code xml:space="preserve">phc_markdown_to_xml()</code>
          <text xml:space="preserve"> and </text>
          <code xml:space="preserve">phc_markdown_to_dom()</code>
          <text xml:space="preserve"> out of the box. Both emit </text>
          <strong>
            <text xml:space="preserve">CommonMark XML 1.0</text>
          </strong>
          <text xml:space="preserve"> (</text>
          <code xml:space="preserve">http://commonmark.org/xml/1.0</code>
          <text xml:space="preserve">) without </text>
          <code xml:space="preserve">DOCTYPE</code>
          <text xml:space="preserve"> declarations so Markdown parses straight into </text>
          <code xml:space="preserve">DOMDocument</code>
          <text xml:space="preserve">, </text>
          <code xml:space="preserve">DOMXPath</code>
          <text xml:space="preserve">, </text>
          <code xml:space="preserve">Xao\DomDoc</code>
          <text xml:space="preserve">, and </text>
          <code xml:space="preserve">XSLTProcessor</code>
          <text xml:space="preserve">.</text>
        </paragraph>
        <heading level="2">
          <text xml:space="preserve">Native PHC Functions &amp; Options</text>
        </heading>
        <code_block info="php" xml:space="preserve">$xml = phc_markdown_to_xml($markdown, [
    'gfm' =&gt; true,
    'sourcepos' =&gt; false,
    'unsafe_html' =&gt; false,
    'front_matter_delimiter' =&gt; '---',
]);

$dom = phc_markdown_to_dom($markdown, ['gfm' =&gt; true, 'unsafe_html' =&gt; false]);
</code_block>
        <table>
          <table_header>
            <table_cell>
              <text xml:space="preserve">Option</text>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Type</text>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Default</text>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Behavior</text>
            </table_cell>
          </table_header>
          <table_row>
            <table_cell>
              <code xml:space="preserve">gfm</code>
            </table_cell>
            <table_cell>
              <code xml:space="preserve">bool</code>
            </table_cell>
            <table_cell>
              <code xml:space="preserve">false</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Enables GFM tables, strikethrough, task lists, and autolinks</text>
            </table_cell>
          </table_row>
          <table_row>
            <table_cell>
              <code xml:space="preserve">sourcepos</code>
            </table_cell>
            <table_cell>
              <code xml:space="preserve">bool</code>
            </table_cell>
            <table_cell>
              <code xml:space="preserve">false</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Adds </text>
              <code xml:space="preserve">sourcepos</code>
              <text xml:space="preserve"> attributes to XML elements</text>
            </table_cell>
          </table_row>
          <table_row>
            <table_cell>
              <code xml:space="preserve">unsafe_html</code>
            </table_cell>
            <table_cell>
              <code xml:space="preserve">bool</code>
            </table_cell>
            <table_cell>
              <code xml:space="preserve">false</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Strips/escapes raw HTML blocks and inline HTML when </text>
              <code xml:space="preserve">false</code>
            </table_cell>
          </table_row>
          <table_row>
            <table_cell>
              <code xml:space="preserve">front_matter_delimiter</code>
            </table_cell>
            <table_cell>
              <code xml:space="preserve">string</code>
            </table_cell>
            <table_cell>
              <code xml:space="preserve">null</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Strips leading frontmatter fenced by the delimiter</text>
            </table_cell>
          </table_row>
        </table>
        <heading level="2">
          <text xml:space="preserve">Preserving the CommonMark Namespace in </text>
          <code xml:space="preserve">DomDoc</code>
        </heading>
        <paragraph>
          <text xml:space="preserve">When grafting a </text>
          <code xml:space="preserve">phc_markdown_to_dom()</code>
          <text xml:space="preserve"> tree into a larger </text>
          <code xml:space="preserve">Xao\DomDoc</code>
          <text xml:space="preserve"> conglomeration, use </text>
          <strong>
            <code xml:space="preserve">ndImportNode()</code>
          </strong>
          <text xml:space="preserve"> rather than </text>
          <code xml:space="preserve">ndConsumeNode()</code>
          <text xml:space="preserve"> so </text>
          <code xml:space="preserve">xmlns="http://commonmark.org/xml/1.0"</code>
          <text xml:space="preserve"> is preserved for namespaced XSLT templates (</text>
          <code xml:space="preserve">xmlns:cm="http://commonmark.org/xml/1.0"</code>
          <text xml:space="preserve">):</text>
        </paragraph>
        <code_block info="php" xml:space="preserve">$mdDoc = new DomDoc(phc_markdown_to_dom($markdownBody, [
    'gfm' =&gt; true,
    'unsafe_html' =&gt; false,
]));

$page = new DomDoc('xao-docs');
$bodyNode = $page-&gt;ndAppendToRoot('body');
$page-&gt;ndImportNode($mdDoc-&gt;getRoot(), true, $bodyNode);
</code_block>
        <heading level="2">
          <text xml:space="preserve">CommonMark XML Elements for XSLT Authors</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">CommonMark + GFM emits clean, predictable XML elements:</text>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <text xml:space="preserve">Blocks: </text>
              <code xml:space="preserve">cm:heading[@level]</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:paragraph</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:code_block[@info]</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:block_quote</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:thematic_break</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <text xml:space="preserve">Lists: </text>
              <code xml:space="preserve">cm:list[@type, @start, @tasklist]</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:item</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:taskitem[@completed]</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <text xml:space="preserve">Inline: </text>
              <code xml:space="preserve">cm:text</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:emph</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:strong</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:code</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:strikethrough</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:link[@destination, @title]</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:image[@destination, @title]</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:softbreak</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:linebreak</code>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <text xml:space="preserve">Tables: </text>
              <code xml:space="preserve">cm:table</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:table_header</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:table_row</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">cm:table_cell</code>
            </paragraph>
          </item>
        </list>
        <heading level="2">
          <text xml:space="preserve">Roadmap (</text>
          <code xml:space="preserve">P06</code>
          <text xml:space="preserve">)</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">Phase </text>
          <code xml:space="preserve">P06</code>
          <text xml:space="preserve"> in Xao's roadmap builds first-class </text>
          <code xml:space="preserve">Xao\MarkdownToXml</code>
          <text xml:space="preserve"> and </text>
          <code xml:space="preserve">DomDoc::ndConsumeMarkdown()</code>
          <text xml:space="preserve"> / </text>
          <code xml:space="preserve">ndConsumeMarkdownFile()</code>
          <text xml:space="preserve"> helpers on top of this PHC primitive and integrates Markdown articles directly into the built-in catalog reference app alongside SQLite </text>
          <code xml:space="preserve">DbToXml</code>
          <text xml:space="preserve">.</text>
        </paragraph>
      </document>
    </body>
  </page>
</xao-docs>
