Hans Hagen <pra...@wxs.nl> writes:

> John Devereux wrote:
>> Hans Hagen <pra...@wxs.nl> writes:
>>
>>
>> [...]
>>
>> Hi Hans,
>>
>> Is there any possible way to use the wiki-style tables like:
>>
>> ^ Heading 1 ^ Heading 2 ^
>> | Item 1    | Item 2 |
>> | Item 3    | Item 4 |
>>
>> (Probably with some wrapper)
>>
>> Perhaps this boils down to asking if it is possible to (re)define
>> "special" characters, within a region of text.
>
> doing that in the running text is asking for troubles (catcode mess)
>
> if there is real interest in that kind of stuff we can make a module
> that does something
>
> \starttext
>
> \startluacode
> function commands.wiki_to_table(str) -- wrong namespace
>     str = string.gsub(str,"%^ *[\n\r]","\\NC\\NR\n")
>     str = string.gsub(str,"%^","\\NC ")
>     str = string.gsub(str,"| *[\n\r]","\\NC\\NR\n")
>     str = string.gsub(str,"|","\\NC ")
>     tex.sprint(tex.ctxcatcodes,"\\startTABLE")
>     tex.sprint(tex.ctxcatcodes,str)
>     tex.sprint(tex.ctxcatcodes,"\\stopTABLE")
> end
> \stopluacode
>
> \def\startwikitable
>   {\bgroup
>    \obeylines
>    \dostartwikitable}
>
> \long\def\dostartwikitable#1\stopwikitable
>   {\ctxlua{commands.wiki_to_table([[\detokenize{#1}]])}%
>    \egroup}
>
> \startwikitable
> ^ Heading 1 ^ Heading 2 ^
> | Item 1    | Item 2 |
> | Item 3    | Item 4 |
> \stopwikitable
>
> \startTABLE
> \NC Text 1 \NC Text 2 \NC \NR
> \NC Text 3 \NC Text 4 \NC \NR
> \stopTABLE
>
> \stoptext

That appears to be exactly what I was after!

(Sorry I don't have MKIV set up right now but will try it when I can).

I don't know if it is of general interest.

I find that writing documents for context - once you get used to it -
is much nicer than using a wordprocessor.

But the process of entering tables remains tedious and error prone,
compared to e.g. the Word equivalent that many will be used to.

-- 

John Devereux
___________________________________________________________________________________
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  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to