ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Converting XHTML captions to ConTeXt captions
@ 2023-11-26 11:27 Thangalin
  0 siblings, 0 replies; only message in thread
From: Thangalin @ 2023-11-26 11:27 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1682 bytes --]

I'd like to capture a caption and apply it to the block-level element that
immediately follows. In the MWE, is there a more "ConTeXt way" to
accomplish the task of adding captions to tables, figures, blockquotes, etc?

% SOT
\startbuffer[demo]
<body>
<p><span class="caption">Caption 1 <a data-type="tbl"
name="lbl-1"/></span></p>
<table>table 1 with caption</table>
<table>table 2 without caption</table>
<p><span class="caption">Caption 3 <a data-type="tbl"
name="lbl-2"/></span></p>
<table>table 3 with caption</table>
</body>
\stopbuffer

\startxmlsetups xml:demo
  \xmlsetsetup{\xmldocument}{*}{-}
  \xmlsetsetup{\xmldocument}{a|p|body|table}{xml:*}
  \xmlsetsetup{\xmldocument}{span[@class='caption']}{xml:span}

  \define\CaptionText{}
  \define\AnchorXref{}
\stopxmlsetups

\startxmlsetups xml:span
  \define\CaptionText{\xmlflush{#1}}
\stopxmlsetups

\startxmlsetups xml:a
  \define\AnchorXref{\xmlatt{#1}{data-type}-\xmlatt{#1}{name}}
\stopxmlsetups

\startxmlsetups xml:body \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:p \xmlflush{#1}\par \stopxmlsetups
\startxmlsetups xml:table
  \blank
  \doifelsetext{\CaptionText}{%
    \startplacetable[
      title={\ignorespaces\CaptionText{}\removeunwantedspaces.},
      reference={\AnchorXref}
    ]

    \define\CaptionText{}
    \define\AnchorXref{}
  }{
    \startplacetable
  }

    \startembeddedxtable
      \startxtablebody[body]
        \startxrow
          \startxcell
            \xmlflush{#1}
          \stopxcell
        \stopxrow
      \stopxtablebody
    \stopembeddedxtable
  \stopplacetable
  \blank
\stopxmlsetups

\xmlregistersetup{xml:demo}

\starttext
  \xmlprocessbuffer{demo}{demo}{}
\stoptext
% EOT

[-- Attachment #1.2: Type: text/html, Size: 2172 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-26 11:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-26 11:27 [NTG-context] Converting XHTML captions to ConTeXt captions Thangalin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).