% \enabletrackers[context*]

\usemodule[cals]

\startxmlsetups xml:whatever:a
    \xmlsetsetup {#1} {
        article|
        section|
        simpara|
        itemizedlist|orderedlist|listitem|
        emphasis|guibutton|
        literal|programlisting|
        superscript|subscript|
        equation|inlineequation|
        figure|mediaobject|informalfigure
    } {xml:*}
    \xmlsetsetup {#1} {
        imageobject/imagedata
    } {xml:image}
    \xmlsetsetup {#1} {
        imageobject
    } {+}
    \xmlsetfunction {#1} {table} {moduledata.cals.table}
\stopxmlsetups

\xmlregisterdocumentsetup{main}{xml:whatever:a}

\startxmlsetups xml:article
    \startbodymatter
        \xmlfilter{#1}{/section/command(xml:section)}
    \stopbodymatter
\stopxmlsetups

\startxmlsetups xml:section
    \startsectionlevel[title={\xmltext{#1}{/title}}]
        \xmlall{#1}{/!title}
        %\xmlall{#1}{}
    \stopsectionlevel
\stopxmlsetups

\startxmlsetups xml:simpara
    \xmlflush{#1}\par
\stopxmlsetups

\startxmlsetups xml:itemizedlist
    \startitemize
        \xmlflush{#1}
    \stopitemize
\stopxmlsetups

\defineitemgroup[ordered]
\setupitemgroup[ordered][1][symbol=n]
\setupitemgroup[ordered][2][symbol=a]
\setupitemgroup[ordered][3][symbol=i]

\startxmlsetups xml:orderedlist
    \startitemgroup[ordered]
        \xmlflush{#1}
    \stopitemgroup
\stopxmlsetups

\startxmlsetups xml:listitem
    \startitem
        \xmlflush{#1}
    \stopitem
\stopxmlsetups

\xmlmapvalue{emphasis}{strong}{\bf}
\xmlmapvalue{emphasis}{normal}{\em}

\startxmlsetups xml:emphasis
    \dontleavehmode
    \start
    \xmlvalue{emphasis}{\xmlattdef{#1}{role}{normal}}{normal}
    \xmlflush{#1}
    \stop
\stopxmlsetups

\startxmlsetups xml:literal
    \dontleavehmode
    \start
    \tt
    \xmlflush{#1}
    \stop
\stopxmlsetups

\startxmlsetups xml:programlisting
    \dontleavehmode
    \startframedtext[background=color,backgroundcolor=lightgray]
    \obeylines
    \tt
    \xmlflush{#1}
    \stopframedtext
\stopxmlsetups

\startluacode
    function xml.finalizers.tex.cdatatocontext(c)
        context(xml.cdata(c[1]))
    end
\stopluacode

\setupbodyfont
    [dejavu,10pt]

\setuplayout
    [middle]

\setupwhitespace
    [big]
