summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/strc-blk.mkiv
blob: bceb66beb1a5ea7334b0727dbcbe95b7a911a1e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
%D \module
%D   [       file=strc-blk,
%D        version=2008.10.20,
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=Blockmoves,
%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 Structure Macros / Blockmoves}

\registerctxluafile{strc-blk}{1.001}

\unprotect

% we run on top of buffers and sections
%
% todo: prefix numbers (needs further integration elsewhere)
%       check functionality
%       alternative files (needs further integration elsewhere)
%
% order matters: \c!before (think of: \c!before=\startitemize)
%
% no \endgroups

\installcorenamespace {block}
\installcorenamespace {blocktemp}

\installcommandhandler \??block {block} \??block

\appendtoks
    \ctxcommand{definestructureblock("\currentblock")}%
    \setuevalue{\e!begin\currentblock}{\dodoubleempty\strc_blocks_begin[\currentblock]}%
    \setuevalue{\e!end  \currentblock}{}%
\to \everydefineblock

\unexpanded\def\strc_blocks_begin[#1][#2]%
  {\normalexpanded{\buff_pickup{@block@}{\e!begin#1}{\e!end#1}}
     {}% before
     {\ctxcommand{savestructureblock("#1","#2","@block@")}}%
     \plusone}% after

\let\strc_blocks_setup\relax

\unexpanded\def\dostarthiddenblock % called at lua end
  {\startnointerference
   \dostartnormalblock}

\unexpanded\def\dostophiddenblock % called at lua end
  {\dostopnormalblock
   \stopnointerference}

\unexpanded\def\dostartnormalblock#1% called at lua end
  {\bgroup
   \visibletrue  % will change
   \edef\currentblock{#1}%
   \strc_blocks_setup
   \let\strc_blocks_setup\relax
   \blockparameter\c!before
   \useblockstyleandcolor\c!style\c!color % maybe moev one line up (font spacing)
   \blockparameter\c!inner % better \c!setups
   \ignorespaces}

\unexpanded\def\dostopnormalblock % called at lua end
  {\removeunwantedspaces
   \blockparameter\c!after
   \par % todo: alternative = text, paragraph
   \egroup}

\def\strc_blocks_set_state[#1][#2][#3]% state name tag
  {\ctxcommand{setstructureblockstate("#1","#2","#3")}}

\def\strc_blocks_select[#1][#2][#3][#4]% state name tag setups
  {\bgroup
   \doifassignmentelse{#3}
     {\getparameters[\??blocktemp][\c!criterium=\v!text,#3]%
      \def\strc_blocks_setup{\setupcurrentblock[#3]}%
      \ctxcommand{selectstructureblock("#1","#2","","\csname\??blocktemp\c!criterium\endcsname")}}
     {\getparameters[\??blocktemp][\c!criterium=\v!text,#4]%
      \def\strc_blocks_setup{\setupcurrentblock[#4]}%
      \ctxcommand{selectstructureblock("#1","#2","#3","\csname\??blocktemp\c!criterium\endcsname")}}%
   \egroup}

% hide   : save, if [+] also hidden execute
% keep   : save and normal execute
% use    : normal execute unless [-]
% process: hidden execute unless [-]
% select : idem use

\unexpanded\def\hideblocks   {\dotripleempty   \strc_blocks_set_state[hide]}
\unexpanded\def\keepblocks   {\dotripleempty   \strc_blocks_set_state[keep]}
\unexpanded\def\useblocks    {\doquadrupleempty\strc_blocks_select   [use]}
\unexpanded\def\processblocks{\doquadrupleempty\strc_blocks_select   [process]}
\unexpanded\def\selectblocks {\doquadrupleempty\strc_blocks_select   [use]}

\protect \endinput