On 6/18/2025 11:41 AM, mf wrote:
Hello list,
I remember having read something about this, but I can't remember where:
I need to prevent the next \par.

The context (lowercase) is XML typesetting, where sometimes I want to concatenate two paragraphs in a particular typesetting, while keeping the original structure of the document (two distinct paragraphs).

To give you an idea, in XHTML it could be something like this:
-----------
<p>This is a paragraph.<?injecttex \preventpar ?></p>
<p>This is the next paragraph.</p>
-----------

Here is a weekend solution ...

% Let's borrow some mwe as that was not provided:

\startbuffer[test]
<something>
    <what samepar="true">
        one
    </what>
    <what>
        two
    </what>
    <what>
        three
    </what>
    <what>
        four
    </what>
</something>
\stopbuffer

% some trivial mapping

\startxmlsetups xml:mysetups
    \xmlsetsetup{#1}{something|what}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:mysetups}

\startxmlsetups xml:something
    \xmlflush{#1}
\stopxmlsetups

% variant 1:

\startxmlsetups xml:what
\doifelse {\xmlattribute{#1}{./preceding-sibling::[-1]}{samepar}} {true} {
        \removeunwantedspaces
        \space
        \xmlflush{#1}
    } {
        \bpar
        \xmlflush{#1}
        \epar
    }
\stopxmlsetups

% variant 2:

\startxmlsetups xml:what
    \xmldoifelse {#1} {./preceding-sibling::[-1][@samepar='true']} {
        \removeunwantedspaces
        \space
        \xmlflush{#1}
    } {
        \bpar
        \xmlflush{#1}
        \epar
    }
\stopxmlsetups

% variant 3:

\startxmlsetups xml:what
    \ifxml {#1} {./preceding-sibling::[-1][@samepar='true']}
        \removeunwantedspaces
        \space
        \xmlflush{#1}
    \else
        \bpar
        \xmlflush{#1}
        \epar
    \fi
\stopxmlsetups

% let's test

\starttext
    \xmlprocessbuffer{main}{test}{}
\stoptext

so, you can go verbose (variant 1), more efficient (variant 2), and even more effcicient in natural (emulated) tex speak.

Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
\startbuffer[test]
<something>
    <what samepar="true">
        one
    </what>
    <what>
        two
    </what>
    <what>
        three
    </what>
    <what>
        four
    </what>
</something>
\stopbuffer

\startxmlsetups xml:mysetups
    \xmlsetsetup{#1}{something|what}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:mysetups}

\startxmlsetups xml:something
    \xmlflush{#1}
\stopxmlsetups

% variant 1:

\startxmlsetups xml:what
    \doifelse {\xmlattribute{#1}{./preceding-sibling::[-1]}{samepar}} {true} {
        \removeunwantedspaces
        \space
        \xmlflush{#1}
    } {
        \bpar
        \xmlflush{#1}
        \epar
    }
\stopxmlsetups

% variant 2:

\startxmlsetups xml:what
    \xmldoifelse {#1} {./preceding-sibling::[-1][@samepar='true']} {
        \removeunwantedspaces
        \space
        \xmlflush{#1}
    } {
        \bpar
        \xmlflush{#1}
        \epar
    }
\stopxmlsetups

% variant 3:

\startxmlsetups xml:what
    \ifxml {#1} {./preceding-sibling::[-1][@samepar='true']}
        \removeunwantedspaces
        \space
        \xmlflush{#1}
    \else
        \bpar
        \xmlflush{#1}
        \epar
    \fi
\stopxmlsetups

\starttext
    \xmlprocessbuffer{main}{test}{}
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to