4

I have the following example, where one <Line> is blank and one has leading spaces. ConTeXt is ignoring the blank line and trimming the leading spaces. How do I turn this off?

\startbuffer[demo]
<?xml version="1.0" encoding="UTF-8"?>
<Reading>
<Header>Foo</Header>
<Line>Line #1</Line>
<Line>Line #2</Line>
<Line></Line>
<Line>  Line #3</Line>
</Reading>
\stopbuffer

\startxmlsetups xml:initialize
  \xmlsetsetup{#1}{*}{-}
  \xmlsetsetup{#1}{Book|Reading|Header|Line}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:initialize}

\startxmlsetups xml:Reading
  \startdocument
    \xmlflush{#1}
  \stopdocument
\stopxmlsetups

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

\xmlprocessbuffer{main}{demo}{}

Normalized lines

6

Use \xmlflushspacewise to obey spaces and newline inside the nodes and use \dontleavehmode before so that successive \par can't be collapsed.

\startbuffer[demo]
<?xml version="1.0" encoding="UTF-8"?>
<Reading>
<Header>Foo</Header>
<Line>Line #1</Line>
<Line>Line #2</Line>
<Line></Line>
<Line>  Line #3</Line>
</Reading>
\stopbuffer

\startxmlsetups xml:initialize
  \xmlsetsetup{#1}{*}{-}
  \xmlsetsetup{#1}{Book|Reading|Header|Line}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:initialize}

\startxmlsetups xml:Reading
  \startdocument
    \xmlflush{#1}
  \stopdocument
\stopxmlsetups

\startxmlsetups xml:Line
    \dontleavehmode\xmlflushspacewise{#1}\par
\stopxmlsetups

\xmlprocessbuffer{main}{demo}{}

enter image description here

  • Thank you so much, Henri! I really tried to figure this out on my own, but I just couldn't! :) – Neil Mussett Jan 20 at 0:23
  • @NeilMussett No worries, I'm always happy to help, especially when the question is well-prepared, like this one. – Henri Menke Jan 20 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.