ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* redefining xmlsetups inside a XML document
@ 2022-03-10 15:59 mf via ntg-context
  2022-03-10 16:52 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 5+ messages in thread
From: mf via ntg-context @ 2022-03-10 15:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: mf

[-- Attachment #1: Type: text/plain, Size: 815 bytes --]

Hello,
I'm trying to add new templates (xmlsetups) from the XML document itself.

See the attached MWE.

- the XML document is a simple XHTML file

- in the "head" element there's a "script" element with the "type" 
attribute set to "text/vnd.context", whose contents are then passed to 
\xmlcontext

- the "body" element has a "data-xmlsetups" attribute whose value should 
tell which xmlsetups is to be applied on the body contents (it's defined 
in the "script" element above)

If it worked, the resulting PDF should show the body element, followed 
by a "Hello world!" paragraph written in red.
But it does not work, because there's something I'm missing in the 
redefinition and application of xmlsetups.

To try the MWE, type:

context --environment=nested-xmlsetup.tex --forcexml nested-xmlsetup.xhtml

Massi

[-- Attachment #2: nested-xmlsetup.tex --]
[-- Type: text/x-tex, Size: 1021 bytes --]

\startxmlsetups html
  \xmlsetsetup{#1}{{html|head}}{html:flush}
  \xmlsetsetup{#1}{{html head script}}{html:script:context}
  \xmlsetsetup{#1}{{html body}}{html:body}
  \xmlsetsetup{#1}{p}{html:p}
\stopxmlsetups

\startxmlsetups html:flush
  \xmlflush{#1}
\stopxmlsetups

\startluacode
function xml.functions.parseScript(s)
  local mimetype = s and s.at and s.at.type
  if mimetype and mimetype == "text/vnd.context" then
    lxml.context(s)
  end
end
function xml.functions.flushBody(b)
  local xmlsetups = b and b.at and b.at["data-xmlsetups"]
  if xmlsetups then
    lxml.tobuffer(b, ".", "body")
    context("\\typebuffer[body]")
    context.xmlprocessbuffer("body", "body", xmlsetups)
  else
    lxml.flush(b)
  end
end
\stopluacode

\startxmlsetups html:script:context
  \xmlfunction{#1}{parseScript}
\stopxmlsetups

\startxmlsetups html:body
  \starttext
    \xmlfunction{#1}{flushBody}
  \stoptext
\stopxmlsetups

\startxmlsetups html:p
  \dontleavehmode\xmlflush{#1}\par
\stopxmlsetups

\xmlregistersetup{html}

[-- Attachment #3: nested-xmlsetup.xhtml --]
[-- Type: application/xhtml+xml, Size: 339 bytes --]

[-- Attachment #4: Type: text/plain, Size: 493 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: redefining xmlsetups inside a XML document
  2022-03-10 15:59 redefining xmlsetups inside a XML document mf via ntg-context
@ 2022-03-10 16:52 ` Hans Hagen via ntg-context
  2022-03-22 14:23   ` mf via ntg-context
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen via ntg-context @ 2022-03-10 16:52 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

On 3/10/2022 4:59 PM, mf via ntg-context wrote:
> Hello,
> I'm trying to add new templates (xmlsetups) from the XML document itself.
> 
> See the attached MWE.
> 
> - the XML document is a simple XHTML file
> 
> - in the "head" element there's a "script" element with the "type" 
> attribute set to "text/vnd.context", whose contents are then passed to 
> \xmlcontext
> 
> - the "body" element has a "data-xmlsetups" attribute whose value should 
> tell which xmlsetups is to be applied on the body contents (it's defined 
> in the "script" element above)
> 
> If it worked, the resulting PDF should show the body element, followed 
> by a "Hello world!" paragraph written in red.
> But it does not work, because there's something I'm missing in the 
> redefinition and application of xmlsetups.
> 
> To try the MWE, type:
> 
> context --environment=nested-xmlsetup.tex --forcexml nested-xmlsetup.xhtml
     <script type="text/vnd.context">
       \startxmlsetups myHtml
        \xmlsetsetup{#1}{p}{myHtml:p}
        % you're missing this
        \xmlsetup{#1}{xml:process}
        % which is
        %  \xmlregistereddocumentsetups{#1}{#1}
        %  \xmlmain{#1}
       \stopxmlsetups

       \startxmlsetups myHtml:p
          \dontleavehmode\red\xmlflush{#1}\par
       \stopxmlsetups
     </script>


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: redefining xmlsetups inside a XML document
  2022-03-10 16:52 ` Hans Hagen via ntg-context
@ 2022-03-22 14:23   ` mf via ntg-context
  2022-03-22 16:07     ` mf via ntg-context
  0 siblings, 1 reply; 5+ messages in thread
From: mf via ntg-context @ 2022-03-22 14:23 UTC (permalink / raw)
  To: Hans Hagen, mailing list for ConTeXt users; +Cc: mf

[-- Attachment #1: Type: text/plain, Size: 2270 bytes --]

I found the solution I was looking for. The command to run is still

context --environment=nested-xmlsetup.tex --forcexml nested-xmlsetup.xhtml

In the <script> element there's some tex code, which redefines the 
xmlsetups for <p> and <i> elements, coloring the first ones in red and 
the second ones in blue.

The key command is

\xmlsetsetup{\xmldocument}{p|i}{myHtml:*}

where \xmldocument instead of #1 applies the myHtml:* setups to the 
whole XHTML document and not only to the <script> element identified by #1.

I tried also this, to prevent redefining the setups of <html>, <head>, 
<script> elements:

\xmlsetsetup{\xmlfirst{\xmldocument}{body}}{p|i}{myHtml:*}

but it doesn't work, since \xmldocument seems to be the actual document 
instead of an id pointing to its root element.

Massi

Il 10/03/22 17:52, Hans Hagen ha scritto:
> On 3/10/2022 4:59 PM, mf via ntg-context wrote:
>> Hello,
>> I'm trying to add new templates (xmlsetups) from the XML document itself.
>>
>> See the attached MWE.
>>
>> - the XML document is a simple XHTML file
>>
>> - in the "head" element there's a "script" element with the "type" 
>> attribute set to "text/vnd.context", whose contents are then passed to 
>> \xmlcontext
>>
>> - the "body" element has a "data-xmlsetups" attribute whose value 
>> should tell which xmlsetups is to be applied on the body contents 
>> (it's defined in the "script" element above)
>>
>> If it worked, the resulting PDF should show the body element, followed 
>> by a "Hello world!" paragraph written in red.
>> But it does not work, because there's something I'm missing in the 
>> redefinition and application of xmlsetups.
>>
>> To try the MWE, type:
>>
>> context --environment=nested-xmlsetup.tex --forcexml 
>> nested-xmlsetup.xhtml
>      <script type="text/vnd.context">
>        \startxmlsetups myHtml
>         \xmlsetsetup{#1}{p}{myHtml:p}
>         % you're missing this
>         \xmlsetup{#1}{xml:process}
>         % which is
>         %  \xmlregistereddocumentsetups{#1}{#1}
>         %  \xmlmain{#1}
>        \stopxmlsetups
> 
>        \startxmlsetups myHtml:p
>           \dontleavehmode\red\xmlflush{#1}\par
>        \stopxmlsetups
>      </script>
> 

[-- Attachment #2: nested-xmlsetup.xhtml --]
[-- Type: application/xhtml+xml, Size: 575 bytes --]

[-- Attachment #3: nested-xmlsetup.tex --]
[-- Type: text/x-tex, Size: 863 bytes --]

\startxmlsetups html
  \xmlsetsetup{#1}{{html|head}}{html:flush}
  \xmlsetsetup{#1}{{html head script}}{html:script:context}
  \xmlsetsetup{#1}{{html body}}{html:body}
  \xmlsetsetup{#1}{p|i}{html:*}
\stopxmlsetups

\startxmlsetups html:flush
  \xmlflush{#1}
\stopxmlsetups

\startluacode
function xml.functions.parseScript(s)
  local mimetype = s and s.at and s.at.type
  if mimetype and mimetype == "text/vnd.context" then
    lxml.context(s)
  end
end
\stopluacode

\startxmlsetups html:script:context
  \xmlfunction{#1}{parseScript}
\stopxmlsetups

\startxmlsetups html:body
  \starttext
    \xmlflush{#1}
  \stoptext
\stopxmlsetups

% default setup for paragraphs
\startxmlsetups html:p
  \dontleavehmode\xmlflush{#1}\par
\stopxmlsetups

% default setup for italic inlines
\startxmlsetups html:i
  {\it\xmlflush{#1}}%
\stopxmlsetups

\xmlregistersetup{html}

[-- Attachment #4: Type: text/plain, Size: 493 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: redefining xmlsetups inside a XML document
  2022-03-22 14:23   ` mf via ntg-context
@ 2022-03-22 16:07     ` mf via ntg-context
  2022-03-24 13:34       ` embedding tex and lua code in <script> elements inside HTML - was: " mf via ntg-context
  0 siblings, 1 reply; 5+ messages in thread
From: mf via ntg-context @ 2022-03-22 16:07 UTC (permalink / raw)
  To: ntg-context; +Cc: mf

[-- Attachment #1: Type: text/plain, Size: 5049 bytes --]

I've added a <script type="text/x-lua"> in the <head> element (BTW,
"text/x-lua" is the mimetype proposed by freedesktop.org for lua scripts.

That element is managed by this code:

------------------------------
   if mimetype and mimetype == "text/x-lua" then
     local code = xml.text(s)
     context( "\\startluacode " .. code .. " \\stopluacode" )
   end
------------------------------

s is the table representing the script element.
That works, but it has a problem with one-line comments:

------------------------------
   <script type="text/x-lua">
     -- comment
     context.setuppapersize{ "A7" }
   </script>
------------------------------

The code above is considered a long comment as if it were written as
------------------------------
   <script type="text/x-lua">
     -- comment   context.setuppapersize{ "A7" }
   </script>
------------------------------

so the context.setuppapersize function call is ignored.

The workaround is:
------------------------------
   <script type="text/x-lua">
     --[[ comment --]]
     context.setuppapersize{ "A7" }
   </script>
------------------------------

A lua analogous of \xmlcontext (line-wise) would be great.

*  *  *

Here's another problem related to space in <script> elements.
This code:

------------------------------
   <script type="text/vnd.context">
     % default setup for paragraphs
     \startxmlsetups myHtml:p
       \dontleavehmode\red\xmlflush{#1}\par
     \stopxmlsetups

     % default setup for italic inlines
     \startxmlsetups myHtml:i
       {\it\blue\xmlflush{#1}}% <-- problem here
     \stopxmlsetups
   </script>
------------------------------

adds a space after an <i> element.
A solution could be this:

------------------------------
   \startxmlsetups myHtml:i
     {\it\blue\xmlflush{#1}}\stopxmlsetups
------------------------------

I prefer this one:

------------------------------
   \startxmlsetups myHtml:i
     {\it\blue\xmlflush{#1}}\relax
   \stopxmlsetups
------------------------------

You need to end the line with a macro eating up all the trailing spaces 
(newlines included).

Massi

Il 22/03/22 15:23, mf via ntg-context ha scritto:
> I found the solution I was looking for. The command to run is still
> 
> context --environment=nested-xmlsetup.tex --forcexml nested-xmlsetup.xhtml
> 
> In the <script> element there's some tex code, which redefines the 
> xmlsetups for <p> and <i> elements, coloring the first ones in red and 
> the second ones in blue.
> 
> The key command is
> 
> \xmlsetsetup{\xmldocument}{p|i}{myHtml:*}
> 
> where \xmldocument instead of #1 applies the myHtml:* setups to the 
> whole XHTML document and not only to the <script> element identified by #1.
> 
> I tried also this, to prevent redefining the setups of <html>, <head>, 
> <script> elements:
> 
> \xmlsetsetup{\xmlfirst{\xmldocument}{body}}{p|i}{myHtml:*}
> 
> but it doesn't work, since \xmldocument seems to be the actual document 
> instead of an id pointing to its root element.
> 
> Massi
> 
> Il 10/03/22 17:52, Hans Hagen ha scritto:
>> On 3/10/2022 4:59 PM, mf via ntg-context wrote:
>>> Hello,
>>> I'm trying to add new templates (xmlsetups) from the XML document 
>>> itself.
>>>
>>> See the attached MWE.
>>>
>>> - the XML document is a simple XHTML file
>>>
>>> - in the "head" element there's a "script" element with the "type" 
>>> attribute set to "text/vnd.context", whose contents are then passed 
>>> to \xmlcontext
>>>
>>> - the "body" element has a "data-xmlsetups" attribute whose value 
>>> should tell which xmlsetups is to be applied on the body contents 
>>> (it's defined in the "script" element above)
>>>
>>> If it worked, the resulting PDF should show the body element, 
>>> followed by a "Hello world!" paragraph written in red.
>>> But it does not work, because there's something I'm missing in the 
>>> redefinition and application of xmlsetups.
>>>
>>> To try the MWE, type:
>>>
>>> context --environment=nested-xmlsetup.tex --forcexml 
>>> nested-xmlsetup.xhtml
>>      <script type="text/vnd.context">
>>        \startxmlsetups myHtml
>>         \xmlsetsetup{#1}{p}{myHtml:p}
>>         % you're missing this
>>         \xmlsetup{#1}{xml:process}
>>         % which is
>>         %  \xmlregistereddocumentsetups{#1}{#1}
>>         %  \xmlmain{#1}
>>        \stopxmlsetups
>>
>>        \startxmlsetups myHtml:p
>>           \dontleavehmode\red\xmlflush{#1}\par
>>        \stopxmlsetups
>>      </script>
>>
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________

[-- Attachment #2: nested-xmlsetup.xhtml --]
[-- Type: application/xhtml+xml, Size: 714 bytes --]

[-- Attachment #3: nested-xmlsetup.tex --]
[-- Type: text/x-tex, Size: 1007 bytes --]

\startxmlsetups html
  \xmlsetsetup{#1}{{html|head}}{html:flush}
  \xmlsetsetup{#1}{{html head script}}{html:script:context}
  \xmlsetsetup{#1}{{html body}}{html:body}
  \xmlsetsetup{#1}{p|i}{html:*}
\stopxmlsetups

\startxmlsetups html:flush
  \xmlflush{#1}
\stopxmlsetups

\startluacode
function xml.functions.parseScript(s)
  local mimetype = s and s.at and s.at.type
  if mimetype and mimetype == "text/vnd.context" then
    lxml.context(s)
  end
  if mimetype and mimetype == "text/x-lua" then
    local code = xml.text(s)
    context( "\\startluacode " .. code .. " \\stopluacode" )
  end
end
\stopluacode

\startxmlsetups html:script:context
  \xmlfunction{#1}{parseScript}
\stopxmlsetups

\startxmlsetups html:body
  \starttext
    \xmlflush{#1}
  \stoptext
\stopxmlsetups

% default setup for paragraphs
\startxmlsetups html:p
  \dontleavehmode\xmlflush{#1}\par
\stopxmlsetups

% default setup for italic inlines
\startxmlsetups html:i
  {\it\xmlflush{#1}}%
\stopxmlsetups

\xmlregistersetup{html}

[-- Attachment #4: Type: text/plain, Size: 493 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: embedding tex and lua code in <script> elements inside HTML - was: redefining xmlsetups inside a XML document
  2022-03-22 16:07     ` mf via ntg-context
@ 2022-03-24 13:34       ` mf via ntg-context
  0 siblings, 0 replies; 5+ messages in thread
From: mf via ntg-context @ 2022-03-24 13:34 UTC (permalink / raw)
  To: ntg-context; +Cc: mf

[-- Attachment #1: Type: text/plain, Size: 6378 bytes --]

The attached MWE shows how to:

- embed tex code in <script type="text/vnd.context"> or <script 
type="text/vnd.lmtx"> HTML elements to be run by ConTeXt

- embed lua code in <script type="text/x-lua"> elements to be run by ConTeXt

- redefine xmlsetups from the HTML document itself

Massi

Il 22/03/22 17:07, mf via ntg-context ha scritto:
> I've added a <script type="text/x-lua"> in the <head> element (BTW,
> "text/x-lua" is the mimetype proposed by freedesktop.org for lua scripts.
> 
> That element is managed by this code:
> 
> ------------------------------
>    if mimetype and mimetype == "text/x-lua" then
>      local code = xml.text(s)
>      context( "\\startluacode " .. code .. " \\stopluacode" )
>    end
> ------------------------------
> 
> s is the table representing the script element.
> That works, but it has a problem with one-line comments:
> 
> ------------------------------
>    <script type="text/x-lua">
>      -- comment
>      context.setuppapersize{ "A7" }
>    </script>
> ------------------------------
> 
> The code above is considered a long comment as if it were written as
> ------------------------------
>    <script type="text/x-lua">
>      -- comment   context.setuppapersize{ "A7" }
>    </script>
> ------------------------------
> 
> so the context.setuppapersize function call is ignored.
> 
> The workaround is:
> ------------------------------
>    <script type="text/x-lua">
>      --[[ comment --]]
>      context.setuppapersize{ "A7" }
>    </script>
> ------------------------------
> 
> A lua analogous of \xmlcontext (line-wise) would be great.
> 


Hans prompted me to use xml.content() instead of xml.text(). The first 
one preserves newlines, so short comments don't extend to the next line.


> *  *  *
> 
> Here's another problem related to space in <script> elements.
> This code:
> 
> ------------------------------
>    <script type="text/vnd.context">
>      % default setup for paragraphs
>      \startxmlsetups myHtml:p
>        \dontleavehmode\red\xmlflush{#1}\par
>      \stopxmlsetups
> 
>      % default setup for italic inlines
>      \startxmlsetups myHtml:i
>        {\it\blue\xmlflush{#1}}% <-- problem here
>      \stopxmlsetups
>    </script>
> ------------------------------
> 
> adds a space after an <i> element.
> A solution could be this:
> 
> ------------------------------
>    \startxmlsetups myHtml:i
>      {\it\blue\xmlflush{#1}}\stopxmlsetups
> ------------------------------
> 
> I prefer this one:
> 
> ------------------------------
>    \startxmlsetups myHtml:i
>      {\it\blue\xmlflush{#1}}\relax
>    \stopxmlsetups
> ------------------------------
> 
> You need to end the line with a macro eating up all the trailing spaces 
> (newlines included).
> 
> Massi
> 
> Il 22/03/22 15:23, mf via ntg-context ha scritto:
>> I found the solution I was looking for. The command to run is still
>>
>> context --environment=nested-xmlsetup.tex --forcexml 
>> nested-xmlsetup.xhtml
>>
>> In the <script> element there's some tex code, which redefines the 
>> xmlsetups for <p> and <i> elements, coloring the first ones in red and 
>> the second ones in blue.
>>
>> The key command is
>>
>> \xmlsetsetup{\xmldocument}{p|i}{myHtml:*}
>>
>> where \xmldocument instead of #1 applies the myHtml:* setups to the 
>> whole XHTML document and not only to the <script> element identified 
>> by #1.
>>
>> I tried also this, to prevent redefining the setups of <html>, <head>, 
>> <script> elements:
>>
>> \xmlsetsetup{\xmlfirst{\xmldocument}{body}}{p|i}{myHtml:*}
>>
>> but it doesn't work, since \xmldocument seems to be the actual 
>> document instead of an id pointing to its root element.
>>
>> Massi
>>
>> Il 10/03/22 17:52, Hans Hagen ha scritto:
>>> On 3/10/2022 4:59 PM, mf via ntg-context wrote:
>>>> Hello,
>>>> I'm trying to add new templates (xmlsetups) from the XML document 
>>>> itself.
>>>>
>>>> See the attached MWE.
>>>>
>>>> - the XML document is a simple XHTML file
>>>>
>>>> - in the "head" element there's a "script" element with the "type" 
>>>> attribute set to "text/vnd.context", whose contents are then passed 
>>>> to \xmlcontext
>>>>
>>>> - the "body" element has a "data-xmlsetups" attribute whose value 
>>>> should tell which xmlsetups is to be applied on the body contents 
>>>> (it's defined in the "script" element above)
>>>>
>>>> If it worked, the resulting PDF should show the body element, 
>>>> followed by a "Hello world!" paragraph written in red.
>>>> But it does not work, because there's something I'm missing in the 
>>>> redefinition and application of xmlsetups.
>>>>
>>>> To try the MWE, type:
>>>>
>>>> context --environment=nested-xmlsetup.tex --forcexml 
>>>> nested-xmlsetup.xhtml
>>>      <script type="text/vnd.context">
>>>        \startxmlsetups myHtml
>>>         \xmlsetsetup{#1}{p}{myHtml:p}
>>>         % you're missing this
>>>         \xmlsetup{#1}{xml:process}
>>>         % which is
>>>         %  \xmlregistereddocumentsetups{#1}{#1}
>>>         %  \xmlmain{#1}
>>>        \stopxmlsetups
>>>
>>>        \startxmlsetups myHtml:p
>>>           \dontleavehmode\red\xmlflush{#1}\par
>>>        \stopxmlsetups
>>>      </script>
>>>
>>
>> ___________________________________________________________________________________ 
>>
>> 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
>> ___________________________________________________________________________________
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________

[-- Attachment #2: nested-xmlsetup.tex --]
[-- Type: text/x-tex, Size: 1027 bytes --]

\startxmlsetups html
  \xmlsetsetup{#1}{{html|head}}{html:flush}
  \xmlsetsetup{#1}{{html head script}}{html:script:context}
  \xmlsetsetup{#1}{{html body}}{html:body}
  \xmlsetsetup{#1}{p|i}{html:*}
\stopxmlsetups

\startxmlsetups html:flush
  \xmlflush{#1}
\stopxmlsetups

\startluacode
function xml.functions.parseScript(s)
  local mimetype = s and s.at and s.at.type
  if mimetype then
    if mimetype == "text/vnd.context" or mimetype == "text/vnd.lmtx" then
      lxml.context(s)
    elseif mimetype == "text/x-lua" then
      local luacode = xml.content(s)
      context( loadstring(luacode) )
    end
  end
end
\stopluacode

\startxmlsetups html:script:context
  \xmlfunction{#1}{parseScript}
\stopxmlsetups

\startxmlsetups html:body
  \starttext
    \xmlflush{#1}
  \stoptext
\stopxmlsetups

% default setup for paragraphs
\startxmlsetups html:p
  \dontleavehmode\xmlflush{#1}\par
\stopxmlsetups

% default setup for italic inlines
\startxmlsetups html:i
  {\it\xmlflush{#1}}%
\stopxmlsetups

\xmlregistersetup{html}

[-- Attachment #3: nested-xmlsetup.xhtml --]
[-- Type: application/xhtml+xml, Size: 703 bytes --]

[-- Attachment #4: Type: text/plain, Size: 493 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-24 13:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10 15:59 redefining xmlsetups inside a XML document mf via ntg-context
2022-03-10 16:52 ` Hans Hagen via ntg-context
2022-03-22 14:23   ` mf via ntg-context
2022-03-22 16:07     ` mf via ntg-context
2022-03-24 13:34       ` embedding tex and lua code in <script> elements inside HTML - was: " mf via ntg-context

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).