% macros=mkvi

%D \module
%D   [       file=tabl-xtb,
%D        version=2011.10.28,
%D          title=\CONTEXT\ Table Macros,
%D       subtitle=Natural to Xtreme Tables,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Table Macros / Natural to Xtreme Tables}

\unprotect

%D Don't expect wonders but it might come in handy:
%D
%D \starttyping
%D \mapTABLEtoxtable
%D \restoreTABLEfromxtable
%D \stoptyping
%D
%D We stick to a simple example:
%D
%D \startbuffer
%D \bTABLE
%D   \bTR
%D     \bTD[width=1cm,background=color,backgroundcolor=red] one \eTD
%D     \bTD[width=2cm] two \eTD
%D   \eTR
%D   \bTR
%D     \bTD alpha \eTD
%D     \bTD beta  \eTD
%D   \eTR
%D \eTABLE
%D \stopbuffer
%D
%D \typebuffer
%D
%D \startbuffer
%D \startlinecorrection
%D \getbuffer
%D \stoplinecorrection
%D
%D \startlinecorrection
%D \mapTABLEtoxtable \getbuffer
%D \stoplinecorrection
%D \stopbuffer
%D
%D \typebuffer \getbuffer

\let\tabl_x_normal_bTABLEhead\bTABLEhead
\let\tabl_x_normal_eTABLEhead\eTABLEhead
\let\tabl_x_normal_bTABLEnext\bTABLEnext
\let\tabl_x_normal_eTABLEnext\eTABLEnext
\let\tabl_x_normal_bTABLEfoot\bTABLEfoot
\let\tabl_x_normal_eTABLEfoot\eTABLEfoot
\let\tabl_x_normal_bTABLEbody\bTABLEbody
\let\tabl_x_normal_eTABLEbody\eTABLEbody
\let\tabl_x_normal_bTR       \bTR
\let\tabl_x_normal_eTR       \eTR
\let\tabl_x_normal_bTD       \bTD
\let\tabl_x_normal_eTD       \eTD
\let\tabl_x_normal_bTH       \bTH
\let\tabl_x_normal_eTH       \eTH
\let\tabl_x_normal_setupTABLE\setupTABLE
\let\tabl_x_normal_bTABLE    \bTABLE
\let\tabl_x_normal_eTABLE    \eTABLE

\unexpanded\def\restoreTABLEfromxtable
  {\let\bTABLEhead\tabl_x_normal_bTABLEhead
   \let\eTABLEhead\tabl_x_normal_eTABLEhead
   \let\bTABLEnext\tabl_x_normal_bTABLEnext
   \let\eTABLEnext\tabl_x_normal_eTABLEnext
   \let\bTABLEfoot\tabl_x_normal_bTABLEfoot
   \let\eTABLEfoot\tabl_x_normal_eTABLEfoot
   \let\bTABLEbody\tabl_x_normal_bTABLEbody
   \let\eTABLEbody\tabl_x_normal_eTABLEbody
   \let\bTR       \tabl_x_normal_bTR
   \let\eTR       \tabl_x_normal_eTR
   \let\bTD       \tabl_x_normal_bTD
   \let\eTD       \tabl_x_normal_eTD
   \let\bTH       \tabl_x_normal_bTH
   \let\eTH       \tabl_x_normal_eTH
   \let\setupTABLE\tabl_x_normal_setupTABLE
   \let\bTABLE    \tabl_x_normal_bTABLE
   \let\eTABLE    \tabl_x_normal_eTABLE}

\unexpanded\def\mapTABLEtoxtable
  {\let\bTABLEhead\startxtablehead
   \let\eTABLEhead\stopxtablehead
   \let\bTABLEnext\startxtablefoot
   \let\eTABLEnext\stopxtablefoot
   \let\bTABLEfoot\startxtablefoot
   \let\eTABLEfoot\stopxtablefoot
   \let\bTABLEbody\startxtablebody
   \let\eTABLEbody\stopxtablebody
   \let\bTR       \startxrow
   \let\eTR       \stopxrow
   \let\bTD       \startxcell
   \let\eTD       \stopxcell
   \let\bTH       \tabl_x_TABLE_TH_start_cell
   \let\eTH       \tabl_x_TABLE_TH_stop_cell
   \let\setupTABLE\tabl_x_TABLE_setup
   \let\bTABLE    \tabl_x_TABLE_start
   \let\eTABLE    \tabl_x_TABLE_stop}

\unexpanded\def\tabl_x_TABLE_setup{\dosingleempty\tabl_x_TABLE_setup_indeed}
\unexpanded\def\tabl_x_TABLE_start{\dosingleempty\tabl_x_TABLE_start_indeed}
\unexpanded\def\tabl_x_TABLE_stop {\stopxtable}

\unexpanded\def\tabl_x_TABLE_TH_start_cell
  {\startxcellgroup[\c!foregroundstyle=\v!bold]%
   \startxcell}

\unexpanded\def\tabl_x_TABLE_TH_stop_cell
  {\stopxcell
   \stopxcellgroup}

\unexpanded\def\tabl_x_TABLE_setup_indeed[#settings]%
  {\iffirstargument
     \setupxtable[#settings]%
   \fi}

\unexpanded\def\tabl_x_TABLE_start_indeed[#settings]%
  {\bgroup
   \tabl_x_prepare{#settings}%
   \edef\tabl_x_current_buffer{\tabl_x_default_buffer}%
   \buff_pickup\tabl_x_current_buffer{bTABLE}{eTABLE}\relax\tabl_x_process\zerocount}

\protect \endinput
