typo-wrp.lua /size: 3377 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
typo-wrp
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to typo-wrp.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
-- begin/end par wrapping stuff ... more to come
10 11
local
nodecodes
=
nodes
.
nodecodes
12
local
gluecodes
=
nodes
.
gluecodes
13
local
penaltycodes
=
nodes
.
penaltycodes
14
local
boundarycodes
=
nodes
.
boundarycodes
15 16
local
glue_code
=
nodecodes
.
glue
17
local
penalty_code
=
nodecodes
.
penalty
18
local
boundary_code
=
nodecodes
.
boundary
19 20
local
parfillskip_code
=
gluecodes
.
parfillskip
21 22
local
userpenalty_code
=
penaltycodes
.
userpenalty
23
local
linepenalty_code
=
penaltycodes
.
linepenalty
24
local
linebreakpenalty_code
=
penaltycodes
.
linebreakpenalty
25 26
local
wordboundary_code
=
boundarycodes
.
word
27 28
local
nuts
=
nodes
.
nuts
29 30
local
find_node_tail
=
nuts
.
tail
31
local
getprev
=
nuts
.
getprev
32
local
getid
=
nuts
.
getid
33
local
getsubtype
=
nuts
.
getsubtype
34
local
getpenalty
=
nuts
.
getpenalty
35
local
remove_node
=
nuts
.
remove
36 37
local
enableaction
=
nodes
.
tasks
.
enableaction
38 39
local
wrappers
=
{
}
40
typesetters
.
wrappers
=
wrappers
41 42
local
trace_wrappers
=
trackers
.
register
(
"
typesetters.wrappers
"
,
function
(
v
)
trace_wrappers
=
v
end
)
43 44
local
report
=
logs
.
reporter
(
"
paragraphs
"
,
"
wrappers
"
)
45 46
-- we really need to pass tail too ... but then we need to check all the plugins
47
-- bah ... slowdown
48 49
-- This check is very tight to the crlf definition. We check for:
50
--
51
-- [break -10000] [wordboundary] [line(break)penalty] [parfillskip]
52
--
53
-- If needed we can extend this checker for other cases but then we will also
54
-- use attributes.
55 56
local
function
remove_dangling_crlf
(
head
,
tail
)
57
if
head
and
tail
and
getid
(
tail
)
=
=
glue_code
and
getsubtype
(
tail
)
=
=
parfillskip_code
then
58
tail
=
getprev
(
tail
)
59
if
tail
and
getid
(
tail
)
=
=
penalty_code
then
60
local
subtype
=
getsubtype
(
tail
)
61
if
subtype
=
=
linepenalty_code
or
subtype
=
=
linebreakpenalty_code
then
62
tail
=
getprev
(
tail
)
63
if
tail
and
getid
(
tail
)
=
=
boundary_code
and
getsubtype
(
tail
)
=
=
wordboundary_code
then
64
tail
=
getprev
(
tail
)
65
if
tail
~
=
head
and
getid
(
tail
)
=
=
penalty_code
and
getsubtype
(
tail
)
=
=
userpenalty_code
and
getpenalty
(
tail
)
=
=
-10000
then
66
if
trace_wrappers
then
67
report
(
"
removing a probably unwanted end-of-par break in line %s (guess)
"
,
tex
.
inputlineno
)
68
end
69
remove_node
(
head
,
tail
,
true
)
70
return
head
,
tail
71
end
72
end
73
end
74
end
75
end
76
return
head
,
tail
77
end
78 79
function
wrappers
.
handler
(
head
)
80
if
head
then
81
local
tail
=
find_node_tail
(
head
)
82
head
,
tail
=
remove_dangling_crlf
(
head
,
tail
)
-- will be action chain
83
end
84
return
head
85
end
86 87
interfaces
.
implement
{
88
name
=
"
enablecrlf
"
,
89
onlyonce
=
true
,
90
actions
=
function
(
)
91
enableaction
(
"
processors
"
,
"
typesetters.wrappers.handler
"
)
92
end
93
}
94