Background
Markdown, having been converted to XHTML, is to have certain words stylized using ConTeXt. Consider:
1. Say, "ConTeXt is good."
1. Tap [Space]{.kbd} to continue (or quit with [Q]{.kbd}).
This is converted to:
<ol>
<li>Say, "ConTeXt is good."</li>
<li>Tap <span class="kbd">Space</span> to continue (or quit with <span class="kbd">Q</span>).</li>
</ol>
Problem
Space invaders have gobbled up spaces after the first kbd span:
Code
\startbuffer[test]
<?xml version="1.0"?>
<document>
<ol>
<li>Say, "ConTeXt is good."</li>
<li>Tap <span class="kbd">Space</span> to continue (or quit with <span class="kbd">Q</span>).</li>
</ol>
</document>
\stopbuffer
\startxmlsetups xml:setup
\xmlsetsetup{\xmldocument}{*}{-}
\xmlsetsetup{\xmldocument}{document}{xml:*}
\xmlsetsetup{\xmldocument}{ol|li|span}{xml:*}
\stopxmlsetups
\startxmlsetups xml:document
\startdocument \expandafter{\TextReplacement{\xmlflush{#1}}} \stopdocument
\stopxmlsetups
\startxmlsetups xml:ol
\startOrderedList \xmlflush{#1} \stopOrderedList
\stopxmlsetups
\startxmlsetups xml:li
\startitem \xmlflush{#1} \stopitem
\stopxmlsetups
\startxmlsetups xml:span
\setvariable{span}{\xmlatt{#1}{class}}{#1}
\start[\xmlatt{#1}{class}]{\xmlflush{#1}}\stop
\stopxmlsetups
\xmlregistersetup{xml:setup}
\defineitemgroup[OrderedList]
\setupitemgroup[OrderedList][1][packed, ListConversion1]
\definestartstop[kbd][
before={\inframed[]\bgroup},
after={\egroup},
]
\startluacode
userdata = userdata or {}
userdata.TextReplacements = {}
local function TextReplacement( text )
-- Escape hash symbols to avoid compile errors when using cross-references.
local s = string.gsub( text, "#", "#H" )
context( lpeg.replacer( userdata.TextReplacements ):match( s ) )
end
interfaces.implement {
name = "TextReplacement",
arguments = { "string" },
public = true,
actions = TextReplacement,
}
\stopluacode
\startluacode
userdata = userdata or {}
userdata.TextReplacements = {
[1] = { "TeX", "\\TeX{}" },
}
\stopluacode
\starttext
\xmlprocessbuffer{main}{test}{}
\stoptext
Question
How would you ensure that the space (after Space) isn't gobbled?
Ideas
I've tried a few approaches, including shifting the \TextReplacement call into the span (but that's not good because it means having to call \TextReplacement on every XHTML element containing text) and using \autoinsertnextspace. I could not get it to work, either.




\stopin yourxml:spansetup? I think Hans will look into this, because he is, as far as I understand, not so fond of empty braces solutions.\autoinsertedspaceafter the\stopcommand, which gives better results than\autoinsertnextspace.