Open main menu

Changes

1,068 bytes added ,  10:55, 12 March 2009
new from ML posts
< [[Tables_Overview]] | [[TABLE]] >

In March 2009 on [http://archive.contextgarden.net/message/20090308.180323.7e318b07.en.html request from John Devereux], [http://archive.contextgarden.net/message/20090308.183617.4c84cba3.en.html Hans Hagen provided us] with another syntax for tables:

<texcode>
\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

</texcode>