Pablo Rodriguez schrieb am 27.08.2020 um 17:56:
On 8/27/20 5:30 PM, Taco Hoekwater wrote:
[...]
Using Lua gsub(), I need to replace something like:

  string.gsub([[\xmlraw{#1}{.}]], "%", "\\letterpercent")

Double it: %%

See also https://www.lua.org/manual/5.3/manual.html#6.4.1 , but the
mention of %% is a bit hidden.

Many thanks for your replies, Taco and Hans.

I’m afraid this doesn’t work (and I need \xmlraw there):

   \startbuffer[demo]
   <html>
    <body>
      <div id="First">
      <p>The <span class="special">% best</span> paragraph.</p>
      </div>
    </body>
   </html>
   \stopbuffer

   \startxmlsetups xml:initialize
     \xmlsetsetup{#1}{html}{xml:gen}
   \stopxmlsetups

   \xmlregistersetup{xml:initialize}

   \startxmlsetups xml:gen
     \startitemize
     \xmlfilter{#1}{/**/span[@class='special']/command(xml:special)}
     \stopitemize
   \stopxmlsetups

   \startxmlsetups xml:special
     \startitem
     \cldcontext{string.gsub([[\xmlraw{#1}{.}]], "%%",
        "\\letterpercent")}
     \stopitem
   \stopxmlsetups


This works fine with your example

\startxmlsetups xml:special
    \startitem
    \xmlflush{#1}
    \stopitem
\stopxmlsetups

and to escape special characters you can use context.escape()

\startxmlsetups xml:special
    \startitem
    \cldcontext{context.escape([[\xmlraw{#1}{.}]])}
    \stopitem
\stopxmlsetups

Wolfgang
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to