%D \module
%D   [       file=node-par,
%D        version=2008.09.30,
%D          title=\CONTEXT\ Node Macros,
%D       subtitle=Paragraph Building,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%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 Node Macros / Paragraph Building}

%D This is very experimental, undocumented, subjected to changes, etc. just as
%D the underlying interfaces.

% \enableparbuilders
%
% \startparbuilder[default]
%     \input tufte \par
%     \startparbuilder[oneline]
%         \input tufte \par
%     \stopparbuilder
%     \input tufte \par
% \stopparbuilder

\unprotect

\registerctxluafile{node-par}{1.001}

\definesystemattribute[parbuilder]

\newcount\nofparbuilders

\def\defineparbuilder[#1]%
  {\global\advance\nofparbuilders\plusone
   \ctxlua{parbuilders.register("#1",\number\nofparbuilders)}%
   \setxvalue{\??ng:#1}{\dosetattribute{parbuilder}{\number\nofparbuilders}}}

\def\startparbuilder[#1]%
  {\edef\@@currentparbuilder{\number\dogetattribute{parbuilder}}%
   \globalpushmacro\@@currentparbuilder
   \getvalue{\??ng:#1}}

\def\stopparbuilder
  {\globalpopmacro\@@currentparbuilder
   \dosetattribute{parbuilder}{\@@currentparbuilder}}

% no high level interface, after all implementing a linebreaker is not something that
% the average user will do

\defineparbuilder[default] % just for testing
\defineparbuilder[oneline] % just for testing

\def\enableparbuilders {\ctxlua{callback.register('linebreak_filter', parbuilders.main)}}
\def\disableparbuilders{\ctxlua{callback.register('linebreak_filter', nil)}}

\protect \endinput
