ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: <denis.maier@unibe.ch>
To: <ntg-context@ntg.nl>
Subject: [NTG-context] Re: XML: flush to lua function
Date: Tue, 12 Sep 2023 06:56:20 +0000	[thread overview]
Message-ID: <ZRAP278MB04953D59207AAC7D002D4E4383F1A@ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <ZRAP278MB0495B13D1D006D388CE799BA83F2A@ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM>

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

Ok, I've found a way, see below.
But maybe someone has some nice lua (or other) tricks to share... (I'm not sure accessing t.dt[1] is particularly safe when operating on nested structures.)


<?xml version="1.0" encoding="UTF-8"?>
    <title>A short title</title>
    <p>asdf asdf asdf jklö jklö jklö</p>
    <title>A longer title bla bla bla bla bla bla bla bla</title>
    asdf asdf asdf jklö jklö jklö

\startxmlsetups xml:test


\startxmlsetups xml:doc

\setuphead[chapter][expansion=yes] % make sure the stuff gets expanded on time
\startxmlsetups xml:chapter

\startxmlsetups xml:p

                function xml.functions.getMarking(t)
                _,n = t.dt[1]:gsub("%S+","")
                if n > 10 then
                  local words = {}
                  for word in t.dt[1]:gmatch("%S+") do table.insert(words, word) end
                  local resWords = {}
                  resWords =  { unpack( words, 1, 7 ) }
                  res = table.concat(resWords, " ") .. " ..."
                  res = t.dt[1]

\startxmlsetups xml:chapter:title:marking

\startxmlsetups xml:chapter:title





Von: denis.maier@unibe.ch <denis.maier@unibe.ch>
Gesendet: Montag, 11. September 2023 16:47
An: ntg-context@ntg.nl
Betreff: [NTG-context] XML: flush to lua function

I have the following xml setup with a lua function:

                function markingLength(s)
                _,n = s:gsub("%S+","")
                if n > 3 then
                context("yes" .. " ...") else context("no") end

\startxmlsetups xml:ink:ink-title:marking
                %\ctxlua{markingLength(\xmlflush{#1})}  % does not work
                \ctxlua{markingLength{"1 2 3 4"}}

While the function works, I cannot use xmlflush here. How can I properly pass the xml content to the lua function?


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

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

If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net

  reply	other threads:[~2023-09-12  6:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 14:47 [NTG-context] " denis.maier
2023-09-12  6:56 ` denis.maier [this message]
2023-09-12  7:52   ` [NTG-context] " Taco Hoekwater

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZRAP278MB04953D59207AAC7D002D4E4383F1A@ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM \
    --to=denis.maier@unibe.ch \
    --cc=ntg-context@ntg.nl \


* 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