<?xml version="1.0" encoding="UTF-8"?>
<grammar
    xmlns="http://relaxng.org/ns/structure/1.0"
    xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
    xmlns:wp="urn:ns:yadt:dpml"
    datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
    <start>
        <ref name="document" />
    </start>
    <define name="document">
        <element name="document" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Root of a document.</p>
            </a:documentation>
            <ref name="document-properties" />
            <oneOrMore>
                <ref name="page" />
                <ref name="pdfobject" />
            </oneOrMore>
        </element>
    </define>
    <define name="document-properties">
        <element name="document-properties" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>The properties of the document.</p>
            </a:documentation>
            <optional>
                <attribute name="pdf">
                    <a:documentation>
                        <p>The path to the PDF file.</p>
                    </a:documentation>
                </attribute>
            </optional>
        </element>
    </define>
    <define name="page">
        <element name="page" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>A page.</p>
            </a:documentation>
            <ref name="page-properties" />
            <zeroOrMore>
                <ref name="block" />
            </zeroOrMore>
        </element>
    </define>
    <define name="page-properties">
        <element name="page-properties" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Defines the page properties for the pages in the section.</p>
            </a:documentation>
            <ref name="page-margins" />
            <ref name="page-size" />
        </element>
    </define>
    <define name="page-margins">
        <element name="page-margins" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Defines the page margins for the pages in the section.</p>
            </a:documentation>
            <optional>
                <attribute name="bottom">
                    <a:documentation>
                        <p>The the distance between the bottom of the text margins
                            for the main document and the bottom of the page.</p>
                    </a:documentation>
                    <ref name="auto-percentage-measurement" />
                </attribute>
            </optional>
            <optional>
                <attribute name="left">
                    <a:documentation>
                        <p>The the distance between the left edge of the page and
                            the left edge of the text extents.</p>
                    </a:documentation>
                </attribute>
            </optional>
            <optional>
                <attribute name="right">
                    <a:documentation>
                        <p>The the distance between the right edge of the page and
                            the right edge of the text extents.</p>
                    </a:documentation>
                    <ref name="auto-percentage-measurement" />
                </attribute>
            </optional>
            <optional>
                <attribute name="top">
                    <a:documentation>
                        <p>The the distance between the top edge of the page and
                            the top edge of the text extents.</p>
                    </a:documentation>
                </attribute>
            </optional>
        </element>
    </define>
    <define name="page-size">
        <element name="page-size" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Defines the page geometry details.</p>
            </a:documentation>
            <optional>
                <attribute name="code">
                    <a:documentation>
                        <p>The printer paper code. This code is stored solely to show a description
                            for the current paper size.</p>
                    </a:documentation>
                </attribute>
            </optional>
            <optional>
                <attribute name="orient">
                    <a:documentation>
                        <p>Specifies the orientation of all pages in this page.</p>
                    </a:documentation>
                    <choice>
                        <value>portrait</value>
                        <value>landscape</value>
                    </choice>
                </attribute>
            </optional>
            <ref name="width-height-atts" />
        </element>
    </define>
        <define name="width-height-atts">
        <optional>
            <attribute name="width">
                <a:documentation>
                    <p>The width in some unit. If no units are provided then the unit is pixels.</p>
                    <p>Unit support is processor dependent but processors should support at least:</p>
                    <ul>
                        <li>px - pixels</li>
                        <li>pt - points (72/inch)</li>
                        <li>in - inches</li>
                        <li>pc - picas (6/inch)</li>
                        <li>mm - millimeters</li>
                        <li>cm - centimeters</li>
                    </ul>
                </a:documentation>
            </attribute>
        </optional>
        <optional>
            <attribute name="height">
                <a:documentation>
                    <p>The height in some unit. If no units are provided then the unit is pixels.</p>
                    <p>Unit support is processor dependent but processors should support at least:</p>
                    <ul>
                        <li>px - pixels</li>
                        <li>pt - points (72/inch)</li>
                        <li>in - inches</li>
                        <li>pc - picas (6/inch)</li>
                        <li>mm - millimeters</li>
                        <li>cm - centimeters</li>
                    </ul>
                </a:documentation>
            </attribute>
        </optional>
    </define>
    <define name="block-attributes">
        <optional>
            <attribute name="offsetX">
                <a:documentation>
                    <p>The relative position of the block in the page</p>
                </a:documentation>
                <ref name="auto-percentage-measurement" />
            </attribute>
        </optional>
        <optional>
            <attribute name="offsetY">
                <a:documentation>
                    <p>The relative position of the block in the page</p>
                </a:documentation>
                <ref name="auto-percentage-measurement" />
            </attribute>
        </optional>
        <optional>
            <attribute name="width">
                <a:documentation>
                    <p>The relative width of the block in the page</p>
                </a:documentation>
                <ref name="auto-percentage-measurement" />
            </attribute>
        </optional>
        <optional>
            <attribute name="height">
                <a:documentation>
                    <p>The relative height of the block in the page</p>
                </a:documentation>
                <ref name="auto-percentage-measurement" />
            </attribute>
        </optional>
    </define>
    <define name="block">
        <a:documentation>
            <p>The content of a page.</p>
        </a:documentation>
        <choice>
            <ref name="p" />
            <ref name="table" />
            <ref name="object" />
        </choice>
    </define>
    <define name="p">
        <element name="p" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>A block of text organized into one or more runs or nested tables or objects.</p>
            </a:documentation>
            <oneOrMore>
                <choice>
                    <ref name="run" />
                </choice>
            </oneOrMore>
            <ref name="block-attributes" />
            <optional>
                <attribute name="align">
                    <a:documentation>
                        <p>The horizontal alignment of the paragraph contents.</p>
                        <p>The value "char" indicates alignment on a specific character, e.g., on
                            the decimal point in numbers.</p>
                    </a:documentation>
                    <choice>
                        <value>justify</value>
                        <value>center</value>
                        <value>right</value>
                        <value>start</value>
                    </choice>
                </attribute>
            </optional>
        </element>
    </define>
    <define name="run">
        <element name="run" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>A sequence of one or more characters to which a specific style is applied.
                    May contain inline elements such as bookmarks, symbols, etc.
                </p>
            </a:documentation>
            <zeroOrMore>
                <choice>
                    <text />
                    <ref name="break" />
                    <ref name="symbol" />
                    <ref name="math" />
                </choice>
            </zeroOrMore>
            <optional>
                <attribute name="color">
                    <a:documentation>
                        <p>Set foreground color. Must be a 6-digit hex RGB color value, e.g.
                            "C0C0C0".</p>
                    </a:documentation>
                    <ref name="hexcolor" />
                </attribute>
            </optional>
            <optional>
                <attribute name="font-family">
                    <a:documentation>
                        <p>The font family name to use for the run text.</p>
                    </a:documentation>
                </attribute>
            </optional>
            <optional>
                <attribute name="background-color">
                    <a:documentation>
                        <p>Set background color for the run. Must be a 6-digit hex RGB color value.</p>
                    </a:documentation>
                    <ref name="hexcolor" />
                </attribute>
            </optional>
        </element>
    </define>
    <define name="break">
        <element name="break" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Represents a literal break point: line, column</p>
            </a:documentation>
            <empty />
            <optional>
                <attribute name="type">
                    <choice>
                        <value>line</value>
                        <value>column</value>
                    </choice>
                </attribute>
            </optional>
        </element>
    </define>
    <define name="symbol">
        <element name="symbol" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>a simple as special character which can be distinguished by specific parser</p>
            </a:documentation>
            <attribute name="src">
                <a:documentation>
                    <p>the path to a svg or png file to be used as a symbol</p>
                </a:documentation>
            </attribute>
        </element>
    </define>
    <define name="math">
        <element name="math" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>a math expression usually expressed in mathjax</p>
            </a:documentation>
            <text />
        </element>
    </define>
    <define name="table">
        <element name="table" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Represents tabular data, i.e., rows and columns.</p>
                <p><b>NOTE:</b> Row spanning requires that all cells in the vertically-spanned
                    columns be present in the markup. See td element for details.</p>
            </a:documentation>
            <ref name="block-attributes" />
            <optional>
                <ref name="cols" />
            </optional>
            <optional>
                <ref name="thead" />
            </optional>
            <optional>
                <ref name="tbody" />
            </optional>
            <optional>
                <attribute name="frame">
                    <a:documentation>
                        <p>Indicates what kind of frame the table should have.</p>
                        <p>The default values for frame is implementation dependent, although "all"
                            is typical.</p>
                    </a:documentation>
                    <choice>
                        <value>all</value>
                        <value>topbot</value>
                        <value>sides</value>
                        <value>bottom</value>
                        <value>top</value>
                        <value>none</value>
                    </choice>
                </attribute>
            </optional>
            <optional>
                <attribute name="rowsep">
                    <a:documentation>
                        <p>Indicates whether or not there are rules between rows. 1=show rule, 0=no
                            rule.</p>
                    </a:documentation>
                    <choice>
                        <value>1</value>
                        <value>0</value>
                    </choice>
                </attribute>
            </optional>
            <optional>
                <attribute name="colsep">
                    <a:documentation>
                        <p>Indicates whether or not there are rules between columns. 1=show rule,
                            0=no rule.</p>
                    </a:documentation>
                    <choice>
                        <value>1</value>
                        <value>0</value>
                    </choice>
                </attribute>
            </optional>
            <optional>
                <attribute name="framestyle">
                    <a:documentation>
                        <p>Specifies the frame style. May be overridden by side-specific attributes.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="framestyleBottom">
                    <a:documentation>
                        <p>Specifies the bottom frame style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="framestyleTop">
                    <a:documentation>
                        <p>Specifies the top frame style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="framestyleLeft">
                    <a:documentation>
                        <p>Specifies the left frame style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="framestyleRight">
                    <a:documentation>
                        <p>Specifies the right frame style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
        </element>
    </define>

    <define name="cols">
        <element name="cols" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Holds the column definitions for a table.</p>
            </a:documentation>
            <oneOrMore>
                <ref name="col" />
            </oneOrMore>
        </element>
    </define>

    <define name="col">
        <element name="col" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Defines a single column within a table.</p>
            </a:documentation>
            <empty />
            <optional>
                <attribute name="colwidth">
                    <a:documentation>
                        <p>The width of the column. The value should specify appropriate units,
                            although units are implementation specific.</p>
                    </a:documentation>
                    <ref name="auto-percentage-measurement" />
                </attribute>
            </optional>
        </element>
    </define>

    <define name="thead">
        <element name="thead" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Contains the header rows for a table.</p>
            </a:documentation>
            <zeroOrMore>
                <ref name="tr" />
            </zeroOrMore>
        </element>
    </define>

    <define name="tbody">
        <element name="tbody" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Contains the body rows for a table.</p>
            </a:documentation>
            <zeroOrMore>
                <ref name="tr" />
            </zeroOrMore>
        </element>
    </define>

    <define name="tr">
        <element name="tr" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>A row within a table head or table body.</p>
            </a:documentation>
            <oneOrMore>
                <ref name="td" />
            </oneOrMore>
        </element>
    </define>

    <define name="td">
        <element name="td" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>A cell within a table row. Cells can consist of just runs and run content or
                    multiple paragraphs or objects.</p>
                <p>NOTE: For vertical spans, all the cells spanned must be present in the row and
                    must have the same @colspan value.
                    The first cell in the vertical span specifies @rowspan with a value greater than
                    1. The subsequent cells
                    must include the &lt;vspan&gt; marker.
                </p>
            </a:documentation>
            <choice>
                <zeroOrMore>
                    <choice>
                        <ref name="p" />
                        <ref name="table" />
                    </choice>
                </zeroOrMore>
                <ref name="vspan" />
            </choice>
            <optional>
                <attribute name="align">
                    <a:documentation>
                        <p>The horizontal alignment of the cell contents.</p>
                        <p>The value "char" indicates alignment on a specific character, e.g., on
                            the decimal point in numbers.</p>
                    </a:documentation>
                    <choice>
                        <value>left</value>
                        <value>center</value>
                        <value>right</value>
                        <value>justify</value>
                        <value>char</value>
                    </choice>
                </attribute>
            </optional>
            <optional>
                <attribute name="colspan">
                    <a:documentation>
                        <p>The number of columns spanned by the cell. 1=no span, 2=two columns
                            spanned, etc.</p>
                    </a:documentation>
                </attribute>
            </optional>
            <optional>
                <attribute name="rowspan">
                    <a:documentation>
                        <p>The number of rows spanned by the cell. 1=no span, 2=two rows spanned,
                            etc.</p>
                    </a:documentation>
                </attribute>
            </optional>
            <optional>
                <attribute name="rowsep">
                    <a:documentation>
                        <p>Indicates whether or not there are rules between rows. 1=show rule, 0=no
                            rule.</p>
                    </a:documentation>
                    <choice>
                        <value>1</value>
                        <value>0</value>
                    </choice>
                </attribute>
            </optional>
            <optional>
                <attribute name="colsep">
                    <a:documentation>
                        <p>Indicates whether or not there are rules between columns. 1=show rule,
                            0=no rule.</p>
                    </a:documentation>
                    <choice>
                        <value>1</value>
                        <value>0</value>
                    </choice>
                </attribute>
            </optional>
            <optional>
                <attribute name="borderstyle">
                    <a:documentation>
                        <p>Specifies the border style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="borderstylebottom">
                    <a:documentation>
                        <p>Specifies the bottom border style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="borderstyletop">
                    <a:documentation>
                        <p>Specifies the top border style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="borderstyleleft">
                    <a:documentation>
                        <p>Specifies the left border style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="borderstyleright">
                    <a:documentation>
                        <p>Specifies the right border style.</p>
                    </a:documentation>
                    <ref name="borderstyles" />
                </attribute>
            </optional>
            <optional>
                <attribute name="bordercolor">
                    <a:documentation>
                        <p>Specifies the border color for the cell's borders.</p>
                    </a:documentation>
                    <ref name="hexcolor" />
                </attribute>
            </optional>
            <optional>
                <attribute name="bordercolorbottom">
                    <a:documentation>
                        <p>Specifies the bottom border color.</p>
                    </a:documentation>
                    <ref name="hexcolor" />
                </attribute>
            </optional>
            <optional>
                <attribute name="bordercolortop">
                    <a:documentation>
                        <p>Specifies the top border color.</p>
                    </a:documentation>
                    <ref name="hexcolor" />
                </attribute>
            </optional>
            <optional>
                <attribute name="bordercolorleft">
                    <a:documentation>
                        <p>Specifies the left border color.</p>
                    </a:documentation>
                    <ref name="hexcolor" />
                </attribute>
            </optional>
            <optional>
                <attribute name="bordercolorright">
                    <a:documentation>
                        <p>Specifies the right border color.</p>
                    </a:documentation>
                    <ref name="hexcolor" />
                </attribute>
            </optional>
            <optional>
                <attribute name="shade">
                    <a:documentation>
                        <p>Specifies the background color (shading) for the cell.
                            Value must be a 6-digit hex number, e.g. "FFFF00"</p>
                    </a:documentation>
                    <ref name="hexcolor" />
                </attribute>
            </optional>
            <optional>
                <attribute name="colnum">
                    <a:documentation>
                        <p>The column number of the cell where "1" is the first column.
                            Used to capture cell position resulting from vertical spans when
                            converting from Word.
                        </p>
                    </a:documentation>
                </attribute>
            </optional>
        </element>
    </define>
    <define name="vspan">
        <element name="vspan" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>For use within &lt;td&gt;, marks a cell as being the continuation of a
                    vertically-spanned set of cells.</p>
                <p>For each row spanned after the first row in a vertical span, the cells must be
                    empty or contain only
                    a &lt;vspan&gt; element.</p>
            </a:documentation>
            <empty />
        </element>
    </define>

    <define name="hexcolor">
        <a:documentation>
            <p>See 17.18.38 ST_HexColor (Color Value)</p>
        </a:documentation>
        <data type="string">
            <param name="pattern">[0-9A-F]{6}|auto</param>
        </data>
    </define>
    <define name="borderstyles">
        <a:documentation>
            <p>Simplified border style values for better OCR compatibility</p>
        </a:documentation>
        <choice>
            <value>single</value>
            <value>double</value>
            <value>dotted</value>
            <value>dashed</value>
            <value>none</value>
        </choice>
    </define>
    <define name="auto-percentage-measurement">
        <a:documentation>
            <p>Defines measurement values that can be:</p>
            <p>- 'auto' for automatic sizing</p>
            <p>- percentage (e.g., '50%')</p>
            <p>- absolute measurements with units (pt, pc, mm, cm, in, em, px)</p>
            <p>- optional +/- prefix for relative measurements</p>
        </a:documentation>
        <data type="string">
            <param name="pattern">auto|(\+|\-)?[0-9]+(\.[0-9]+)?(pt|pc|mm|cm|in|em|px|%)</param>
        </data>
    </define>
    <define name="object">
        <element name="object" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Represents an special block of content</p>
            </a:documentation>
            <ref name="block-attributes" />
            <oneOrMore>
                <choice>
                    <ref name="figure" />
                    <ref name="codeblock" />
                    <ref name="pdfobject" />
                </choice>
            </oneOrMore>
        </element>
    </define>
    <define name="figure">
        <element name="figure" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Represents a figure, a base64 encoded image if src is not provided</p>
            </a:documentation>
            <zeroOrMore>
                <text />
            </zeroOrMore>
            <optional>
                <attribute name="src">
                    <a:documentation>
                        <p>the path to a svg or png file to be used as a symbol</p>
                    </a:documentation>
                </attribute>
                <attribute name="width">
                    <a:documentation>
                        <p>the width of the figure</p>
                    </a:documentation>
                    <ref name="auto-percentage-measurement" />
                </attribute>
                <attribute name="height">
                    <a:documentation>
                        <p>the height of the figure</p>
                    </a:documentation>
                    <ref name="auto-percentage-measurement" />
                </attribute>
            </optional>
            <optional>
                <attribute name="caption">
                    <a:documentation>
                        <p>A descriptive caption for the figure that appears below it</p>
                    </a:documentation>
                </attribute>
            </optional>
            <optional>
                <attribute name="title">
                    <a:documentation>
                        <p>A brief title or alternative text for the figure, important for
                            accessibility</p>
                    </a:documentation>
                </attribute>
            </optional>
        </element>
    </define>
    <define name="codeblock">
        <element name="codeblock" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Represents a code block</p>
            </a:documentation>
            <optional>
                <attribute name="language">
                    <a:documentation>
                        <p>the language of the code block</p>
                    </a:documentation>
                </attribute>
            </optional>
            <oneOrMore>
                <ref name="codeline" />
            </oneOrMore>
        </element>
    </define>

    <define name="codeline">
        <element name="codeline" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Represents a single line in a code block</p>
            </a:documentation>
            <text />
            <optional>
                <attribute name="number">
                    <a:documentation>
                        <p>The line number</p>
                    </a:documentation>
                    <data type="positiveInteger" />
                </attribute>
            </optional>
            <optional>
                <attribute name="highlight">
                    <a:documentation>
                        <p>Whether this line should be highlighted</p>
                    </a:documentation>
                    <choice>
                        <value>true</value>
                        <value>false</value>
                    </choice>
                </attribute>
            </optional>
        </element>
    </define>
    <define name="pdfobject">
        <element name="pdfobject" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Represents a pdf object</p>
            </a:documentation>
            <attribute name="type">
                <a:documentation>
                    <p>The type of the pdf object</p>
                </a:documentation>
                <choice>
                    <value>obj</value>
                    <value>trailer</value>
                    <value>metadata</value>
                </choice>
            </attribute>
            <attribute name="objectNumber">
                <a:documentation>
                    <p>The object number</p>
                </a:documentation>
            </attribute>
            <attribute name="generationNumber">
                <a:documentation>
                    <p>The generation number</p>
                </a:documentation>
            </attribute>
            <oneOrMore>
                <ref name="keyValuePair" />
            </oneOrMore>
        </element>
    </define>
    <define name="keyValuePair">
        <element name="keyValuePair" ns="urn:ns:yadt:dpml">
            <a:documentation>
                <p>Represents a key-value pair in JSON-like structure</p>
            </a:documentation>
            <attribute name="key">
                <a:documentation>
                    <p>The key of the pair</p>
                </a:documentation>
            </attribute>
            <choice>
                <!-- Simple value as attribute -->
                <optional>
                    <attribute name="value">
                        <a:documentation>
                            <p>The value for primitive types (string, number, boolean, null)</p>
                        </a:documentation>
                    </attribute>
                </optional>
                <!-- Complex values as child elements -->
                <optional>
                    <choice>
                        <zeroOrMore>
                            <ref name="keyValuePair"/>  <!-- For nested objects -->
                        </zeroOrMore>
                        <zeroOrMore>
                            <element name="arrayItem" ns="urn:ns:yadt:dpml">  <!-- For arrays -->
                                <choice>
                                    <attribute name="value"/>  <!-- For primitive array items -->
                                    <ref name="keyValuePair"/>  <!-- For complex array items -->
                                </choice>
                            </element>
                        </zeroOrMore>
                    </choice>
                </optional>
            </choice>
        </element>
    </define>
</grammar>
