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
101
102
103
104
105
106
107
108
109
110
|
%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 / Hans Hagen]
%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)
\def\blockparameter#1#2{\ifcsname\??tb#1#2\endcsname\csname\??tb#1#2\endcsname\fi}
\def\setupblockparameters{\dodoubleargument \dosetupblock} % fast one (for compatibility)
\def\setupblock {\dodoubleargumentwithset\dosetupblock} % handles set
\def\dosetupblock[#1]{\getparameters[\??tb#1]} % [#1][#2]}
\def\defineblock
{\dosingleargument\dodefineblock}
\def\dodefineblock[#1]%
{\getparameters
[\??tb#1]
[\c!before=\blank,
\c!after=\blank,
\c!inner=,
\c!style=,
\c!file=]% todo
\ctxlua{structure.blocks.define("#1")}%
\setvalue{\e!begin#1}{\dodoubleempty\dobeginofblock[#1]}%
\letvalue{\e!end#1}\relax}
\long\def\dobeginofblock[#1][#2]%
{\normalexpanded{\noexpand\dodowithbuffer{@block@}{\e!begin#1}{\e!end#1}}
{}{\ctxlua{structure.blocks.save("#1","#2","@block@")}}}% before after
\def\dostarthiddenblock
{\startnointerference
\dostartnormalblock}
\def\dostophiddenblock
{\dostopnormalblock
\stopnointerference}
% order matters: \c!before (think of: \c!before=\startitemize)
\let\doblocksetups\gobbleoneargument
\def\dostartnormalblock#1% name
{\bgroup
\visibletrue
\edef\currentblock{#1}%
\doblocksetups\currentblock
\let\doblocksetups\gobbleoneargument
\blockparameter\currentblock\c!before
\dosetfontattribute{\??tb\currentblock}\c!style
\dosetcolorattribute{\??tb\currentblock}\c!color
\blockparameter\currentblock\c!inner
\ignorespaces}
\def\dostopnormalblock
{\removeunwantedspaces
\blockparameter\currentblock\c!after
\par % todo: alternative = text, paragraph
\egroup}
\def\dosetblockstate[#1][#2][#3]% state name tag
{\ctxlua{structure.blocks.setstate("#1","#2","#3")}}
\def\doselectblocks[#1][#2][#3][#4]% state name tag setups
{\begingroup
\doifassignmentelse{#3}
{\getparameters[\??tb\??tb][\c!criterium=\v!text,#3]%
\def\doblocksetups##1{\getparameters[\??tb##1][#3]}%
\ctxlua{structure.blocks.select("#1","#2","","\@@tb@@tbcriterium")}}
{\getparameters[\??tb\??tb][\c!criterium=\v!text,#4]%
\def\doblocksetups##1{\getparameters[\??tb##1][#4]}%
\ctxlua{structure.blocks.select("#1","#2","#3","\@@tb@@tbcriterium")}}%
\endgroup}
% hide: save, if [+] also hidden execute
% keep: save and normal execute
\def\hideblocks{\dotripleempty\dosetblockstate[hide]}
\def\keepblocks{\dotripleempty\dosetblockstate[keep]}
% use : normal execute unless [-]
% process: hidden execute unless [-]
% select : idem use
\def\useblocks {\doquadrupleempty\doselectblocks[use]}
\def\processblocks{\doquadrupleempty\doselectblocks[process]}
\def\selectblocks {\doquadrupleempty\doselectblocks[use]}
\protect \endinput
|