From: massifr@fastwebnet.it
To: ntg-context@ntg.nl
Subject: Re: XML expression to read HTML classes
Date: Wed, 26 Aug 2015 15:16:34 +0200 [thread overview]
Message-ID: <4095856.TvCssukQiQ@max> (raw)
In-Reply-To: <2314073.gCWnhbtjGW@max>
A working example to clarify my request:
\startluacode
-- splits the attribute class using spaces as classes' separator
-- returns an array of strings
function xml.functions.classes(classAttr)
local classes = {}
if classAttr then
for c in string.gmatch(classAttr, "%S+") do
if (string.len(c) > 0) then classes[c] = true end
end
end
return classes
end
function xml.expressions.hasClass(classAttr, className)
if classAttr and className then
return xml.functions.classes(classAttr)[className] ~= nil
end
return false
end
\stopluacode
\startbuffer[test]
<text>
<p>Generic paragraph (no class).</p>
<p class="myClass1">Emphasized paragraph (<tt>class="myClass1"</tt>).</p>
<p class="otherClass myClass1">Another emphasized paragraph
(but <tt>myClass1</tt> is not the only class specified).
</p>
<p class="myClass12">Another not emphasized paragraph
(<tt>class="myClass12"</tt>) showing why <br/>
<tt>p[hasClass(@class, "myClass1")]</tt><br/>
is better than <br/>
<tt>p[@class="myClass1"]</tt><br/>
or <br/>
<tt>p[contains(@class, "myClass1")]</tt>.
</p>
<p><tt>p[hasClass("myClass1")]</tt> would be better
since it's obvious that the classes are specified
in the <tt>class</tt> attribute, but this means that
the lua expression needs to access the current selected element
(<tt>ll</tt>?).
</p>
</text>
\stopbuffer
\startxmlsetups xml:somesetups
\xmlsetsetup{#1}{text}{xml:text}
\xmlsetsetup{#1}{p}{xml:p}
\xmlsetsetup{#1}{p[hasClass(@class, 'myClass1')]}{xml:p:myClass1}
\xmlsetsetup{#1}{tt}{xml:tt}
\xmlsetsetup{#1}{br}{xml:br}
\stopxmlsetups
\xmlregistersetup{xml:somesetups}
\startxmlsetups xml:text
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:p
\xmlflush{#1}\par\blank[line]
\stopxmlsetups
\startxmlsetups xml:p:myClass1
{\em\xmlflush{#1}}\par\blank[line]
\stopxmlsetups
\startxmlsetups xml:br
\\
\stopxmlsetups
\startxmlsetups xml:tt
\dontleavehmode{\tt\xmlflush{#1}}
\stopxmlsetups
\starttext
\xmlprocessbuffer{main}{test}{}
\stoptext
Thanks in advance for any help,
Massi
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2015-08-26 13:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-25 15:05 massifr
2015-08-26 13:16 ` massifr [this message]
2015-08-27 20:57 ` Hans Hagen
2015-08-27 21:16 ` Hans Hagen
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=4095856.TvCssukQiQ@max \
--to=massifr@fastwebnet.it \
--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).