ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* XML Processing with Verbatim (VIM-Typing)
@ 2015-02-10 16:59 Andreas Schneider
  2015-02-10 21:45 ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schneider @ 2015-02-10 16:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello,

as a few other topics on this Mailing List already discussed, it's not 
(easily?) possible to use \starttyping\stoptyping within XML setups. If 
it was "simple" verbatim, there would be a few workarounds.
However, I want to provide formatted verbatim (i.e. \startJSON 
\stopJSON, after having \definevimtyping[JSON][syntax=javascript]). That 
typing environment will be further customized (by adding text background 
with border, etc.).

I don't see a simple way to work around this without manually 
typesetting the code highlighting (which I don't want. I simply want 
<json>{someCode}</json> inside the XML file).

Is there anything I can do to make this work? Maybe with preparing a 
buffer? (with Lua?)

Thanks in advance, for any help you can provide :-)

-- Minimal Example:
\usemodule[vim]
\definevimtyping[JSON][syntax=javascript]

\starttext

\startluacode
   function xml.functions.processJSON(t)
     lxml.verbatim(t, "\\startJSON", "\\stopJSON")
   end
\stopluacode

\startbuffer[demo]
<test>
   <description>
     <json>{somecode}</json>
   </description>
</test>
\stopbuffer

\startxmlsetups xml:initialize
   \xmlsetsetup{#1}{test|description|json}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:initialize}

\startxmlsetups xml:test
   \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:description
   %\xmlsetsetup{xml}{json}{xml:*}
   \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:json
   \xmlfunction{#1}{processJSON}
\stopxmlsetups

\xmlprocessbuffer{main}{demo}{}

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

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

* Re: XML Processing with Verbatim (VIM-Typing)
  2015-02-10 16:59 XML Processing with Verbatim (VIM-Typing) Andreas Schneider
@ 2015-02-10 21:45 ` Hans Hagen
  2015-02-11 11:15   ` Andreas Schneider
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2015-02-10 21:45 UTC (permalink / raw)
  To: ntg-context

On 2/10/2015 5:59 PM, Andreas Schneider wrote:
> Hello,
>
> as a few other topics on this Mailing List already discussed, it's not
> (easily?) possible to use \starttyping\stoptyping within XML setups. If
> it was "simple" verbatim, there would be a few workarounds.
> However, I want to provide formatted verbatim (i.e. \startJSON
> \stopJSON, after having \definevimtyping[JSON][syntax=javascript]). That
> typing environment will be further customized (by adding text background
> with border, etc.).
>
> I don't see a simple way to work around this without manually
> typesetting the code highlighting (which I don't want. I simply want
> <json>{someCode}</json> inside the XML file).
>
> Is there anything I can do to make this work? Maybe with preparing a
> buffer? (with Lua?)


\startluacode
     function xml.functions.processJSON(t)
         buffers.assign("foo","\\startJSON\n" .. tostring(xml.text(t)) 
.. "\n\\stopJSON")
         context.getbuffer { "foo" }
     end
\stopluacode

\startxmlsetups xml:json
     \pushcatcodetable
     \setcatcodetable\ctxcatcodes
     \xmlfunction{#1}{processJSON}
     \popcatcodetable
\stopxmlsetups

(If needed I can make a better plugin for this ... remind me later this 
year.)

> Thanks in advance, for any help you can provide :-)
>
> -- Minimal Example:
> \usemodule[vim]
> \definevimtyping[JSON][syntax=javascript]
>
> \starttext
>
> \startluacode
>    function xml.functions.processJSON(t)
>      lxml.verbatim(t, "\\startJSON", "\\stopJSON")
>    end
> \stopluacode
>
> \startbuffer[demo]
> <test>
>    <description>
>      <json>{somecode}</json>
>    </description>
> </test>
> \stopbuffer
>
> \startxmlsetups xml:initialize
>    \xmlsetsetup{#1}{test|description|json}{xml:*}
> \stopxmlsetups
>
> \xmlregistersetup{xml:initialize}
>
> \startxmlsetups xml:test
>    \xmlflush{#1}
> \stopxmlsetups
>
> \startxmlsetups xml:description
>    %\xmlsetsetup{xml}{json}{xml:*}
>    \xmlflush{#1}
> \stopxmlsetups
>
> \startxmlsetups xml:json
>    \xmlfunction{#1}{processJSON}
> \stopxmlsetups
>
> \xmlprocessbuffer{main}{demo}{}
>
> \stoptext
> ___________________________________________________________________________________
>
> 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
> ___________________________________________________________________________________


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: XML Processing with Verbatim (VIM-Typing)
  2015-02-10 21:45 ` Hans Hagen
@ 2015-02-11 11:15   ` Andreas Schneider
  2015-02-12 14:44     ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schneider @ 2015-02-11 11:15 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 10.02.2015 22:45, schrieb Hans Hagen:
> 
> \startluacode
>     function xml.functions.processJSON(t)
>         buffers.assign("foo","\\startJSON\n" .. tostring(xml.text(t))
> .. "\n\\stopJSON")
>         context.getbuffer { "foo" }
>     end
> \stopluacode
> 
> \startxmlsetups xml:json
>     \pushcatcodetable
>     \setcatcodetable\ctxcatcodes
>     \xmlfunction{#1}{processJSON}
>     \popcatcodetable
> \stopxmlsetups
> 
> (If needed I can make a better plugin for this ... remind me later this 
> year.)
> 

Thank you very much, Hans!

That works like a charm!
 From my perspective, no changes are necessary. I personally like some 
technical trickery in my ConTeXt code, especially if it's as slim as 
your solution. (Mainly because that helps me understand the inner 
workings and hopefully makes me find solutions like this on my own :-))

So thanks again for that quick and very helpful answer!

Best regards,
Andreas
___________________________________________________________________________________
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
___________________________________________________________________________________

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

* Re: XML Processing with Verbatim (VIM-Typing)
  2015-02-11 11:15   ` Andreas Schneider
@ 2015-02-12 14:44     ` Hans Hagen
  2015-02-13  0:00       ` Aditya Mahajan
  2015-02-13  8:13       ` Andreas Schneider
  0 siblings, 2 replies; 6+ messages in thread
From: Hans Hagen @ 2015-02-12 14:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 2/11/2015 12:15 PM, Andreas Schneider wrote:
> Am 10.02.2015 22:45, schrieb Hans Hagen:
>>
>> \startluacode
>>     function xml.functions.processJSON(t)
>>         buffers.assign("foo","\\startJSON\n" .. tostring(xml.text(t))
>> .. "\n\\stopJSON")
>>         context.getbuffer { "foo" }
>>     end
>> \stopluacode
>>
>> \startxmlsetups xml:json
>>     \pushcatcodetable
>>     \setcatcodetable\ctxcatcodes
>>     \xmlfunction{#1}{processJSON}
>>     \popcatcodetable
>> \stopxmlsetups
>>
>> (If needed I can make a better plugin for this ... remind me later
>> this year.)
>>
>
> Thank you very much, Hans!
>
> That works like a charm!
>  From my perspective, no changes are necessary. I personally like some
> technical trickery in my ConTeXt code, especially if it's as slim as
> your solution. (Mainly because that helps me understand the inner
> workings and hopefully makes me find solutions like this on my own :-))

so then you have to wikify it (or add it to the t-vim module docu)

> So thanks again for that quick and very helpful answer!
>
> Best regards,
> Andreas
> ___________________________________________________________________________________
>
> 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
> ___________________________________________________________________________________


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: XML Processing with Verbatim (VIM-Typing)
  2015-02-12 14:44     ` Hans Hagen
@ 2015-02-13  0:00       ` Aditya Mahajan
  2015-02-13  8:13       ` Andreas Schneider
  1 sibling, 0 replies; 6+ messages in thread
From: Aditya Mahajan @ 2015-02-13  0:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, 12 Feb 2015, Hans Hagen wrote:

> On 2/11/2015 12:15 PM, Andreas Schneider wrote:
>> Am 10.02.2015 22:45, schrieb Hans Hagen:
>>>
>>> \startluacode
>>>     function xml.functions.processJSON(t)
>>>         buffers.assign("foo","\\startJSON\n" .. tostring(xml.text(t))
>>> .. "\n\\stopJSON")
>>>         context.getbuffer { "foo" }
>>>     end
>>> \stopluacode
>>>
>>> \startxmlsetups xml:json
>>>     \pushcatcodetable
>>>     \setcatcodetable\ctxcatcodes
>>>     \xmlfunction{#1}{processJSON}
>>>     \popcatcodetable
>>> \stopxmlsetups
>>>
>>> (If needed I can make a better plugin for this ... remind me later
>>> this year.)

t-filter provides a \process<filter>buffer macro. So, in principle,

   \processJSONbuffer[foo]

should have worked, but it did not due to a bug. I have fixed that and 
pushed the latest version to context garden. With this, the following 
should also work (untested)

>>> \startluacode
>>>     function xml.functions.processJSON(t)
>>>         buffers.assign("foo", tostring(xml.text(t)))
>>>         context.processJSONbuffer { "foo" }
>>>     end
>>> \stopluacode
>>>
>>> \startxmlsetups xml:json
>>>     \xmlfunction{#1}{processJSON}
>>> \stopxmlsetups


>> That works like a charm!
>>  From my perspective, no changes are necessary. I personally like some
>> technical trickery in my ConTeXt code, especially if it's as slim as
>> your solution. (Mainly because that helps me understand the inner
>> workings and hopefully makes me find solutions like this on my own :-))
>
> so then you have to wikify it (or add it to the t-vim module docu)

If others also need similar functionality, I can look into adding xml 
processing features or the appropriate lua functions to t-filter.

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

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

* Re: XML Processing with Verbatim (VIM-Typing)
  2015-02-12 14:44     ` Hans Hagen
  2015-02-13  0:00       ` Aditya Mahajan
@ 2015-02-13  8:13       ` Andreas Schneider
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schneider @ 2015-02-13  8:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 12.02.2015 15:44, schrieb Hans Hagen:
> 
> so then you have to wikify it (or add it to the t-vim module docu)

You are right ofcourse :-)
Done: http://wiki.contextgarden.net/Verbatim_XML
___________________________________________________________________________________
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
___________________________________________________________________________________

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

end of thread, other threads:[~2015-02-13  8:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-10 16:59 XML Processing with Verbatim (VIM-Typing) Andreas Schneider
2015-02-10 21:45 ` Hans Hagen
2015-02-11 11:15   ` Andreas Schneider
2015-02-12 14:44     ` Hans Hagen
2015-02-13  0:00       ` Aditya Mahajan
2015-02-13  8:13       ` Andreas Schneider

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