5

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

Zarko
  • 296,517

1 Answers1

7

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

Henri Menke
  • 109,596