From: Thangalin <thangalin@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Converting XHTML captions to ConTeXt captions
Date: Sun, 26 Nov 2023 03:27:02 -0800 [thread overview]
Message-ID: <CAANrE7o6UtqF6NvLTLiakRE-0Oo3nqVK_m37nufgqwWjLAyeYg@mail.gmail.com> (raw)
[-- 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
___________________________________________________________________________________
reply other threads:[~2023-11-26 11:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAANrE7o6UtqF6NvLTLiakRE-0Oo3nqVK_m37nufgqwWjLAyeYg@mail.gmail.com \
--to=thangalin@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).