char-fio.lua /size: 3313 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
char-fio
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to char-ini.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
-- % directives="filters.utf.reorder=false"
10 11 12
local
next
=
next
13 14
-- --
15 16
local
sequencers
=
utilities
.
sequencers
17
local
appendaction
=
sequencers
.
appendaction
18
local
enableaction
=
sequencers
.
enableaction
19
local
disableaction
=
sequencers
.
disableaction
20 21
local
utffilters
=
characters
.
filters
.
utf
22 23
local
textfileactions
=
resolvers
.
openers
.
helpers
.
textfileactions
24
local
textlineactions
=
resolvers
.
openers
.
helpers
.
textlineactions
25 26
appendaction
(
textfileactions
,
"
system
"
,
"
characters.filters.utf.reorder
"
)
27
disableaction
(
textfileactions
,
"
characters.filters.utf.reorder
"
)
28 29
appendaction
(
textlineactions
,
"
system
"
,
"
characters.filters.utf.reorder
"
)
30
disableaction
(
textlineactions
,
"
characters.filters.utf.reorder
"
)
31 32
appendaction
(
textfileactions
,
"
system
"
,
"
characters.filters.utf.collapse
"
)
-- not per line
33
disableaction
(
textfileactions
,
"
characters.filters.utf.collapse
"
)
34 35
appendaction
(
textfileactions
,
"
system
"
,
"
characters.filters.utf.decompose
"
)
-- not per line
36
disableaction
(
textfileactions
,
"
characters.filters.utf.decompose
"
)
37 38
local
report
=
logs
.
reporter
(
"
unicode filter
"
)
39
local
reporting
=
"
no
"
40 41
-- this is messy as for performance reasons i don't want this to happen
42
-- per line by default
43 44
local
enforced
=
{
45
[
"
characters.filters.utf.collapse
"
]
=
true
,
46
[
"
characters.filters.utf.decompose
"
]
=
true
,
47
[
"
characters.filters.utf.reorder
"
]
=
false
,
48
}
49 50
function
utffilters
.
enable
(
)
51
-- only used one time (normally)
52
for
k
,
v
in
next
,
enforced
do
53
if
v
then
54
if
reporting
=
=
"
yes
"
then
55
report
(
"
%a enabled
"
,
k
)
56
end
57
enableaction
(
textfileactions
,
k
)
58
else
59
if
reporting
=
=
"
yes
"
then
60
report
(
"
%a not enabled
"
,
k
)
61
end
62
end
63
end
64
reporting
=
"
never
"
65
end
66 67
local
function
configure
(
what
,
v
)
68
if
v
=
=
"
"
then
69
report
(
"
%a unset
"
,
what
)
70
elseif
v
=
=
"
line
"
then
71
disableaction
(
textfileactions
,
what
)
72
enableaction
(
textlineactions
,
what
)
73
elseif
not
toboolean
(
v
)
then
74
if
reporting
~
=
"
never
"
then
75
report
(
"
%a disabled
"
,
what
)
76
reporting
=
"
yes
"
77
end
78
enforced
[
what
]
=
false
79
disableaction
(
textfileactions
,
what
)
80
disableaction
(
textlineactions
,
what
)
81
else
-- true or text
82
enableaction
(
textfileactions
,
what
)
83
disableaction
(
textlineactions
,
what
)
84
end
85
end
86 87
-- first line:
88
--
89
-- % directives="filters.utf.collapse=true"
90 91
directives
.
register
(
"
filters.utf.reorder
"
,
function
(
v
)
configure
(
"
characters.filters.utf.reorder
"
,
v
)
end
)
92
directives
.
register
(
"
filters.utf.collapse
"
,
function
(
v
)
configure
(
"
characters.filters.utf.collapse
"
,
v
)
end
)
93
directives
.
register
(
"
filters.utf.decompose
"
,
function
(
v
)
configure
(
"
characters.filters.utf.decompose
"
,
v
)
end
)
94 95
utffilters
.
setskippable
{
96
"
mkiv
"
,
"
mkvi
"
,
97
"
mkix
"
,
"
mkxi
"
,
98
"
mkxl
"
,
"
mklx
"
,
99
}
100 101
interfaces
.
implement
{
102
name
=
"
enableutf
"
,
103
onlyonce
=
true
,
104
actions
=
utffilters
.
enable
105
}
106