lang-url.mkxl /size: 5281 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=lang-url,
3%D        version=2008.01.22, % used to be lang-mis
4%D          title=\CONTEXT\ Language Macros,
5%D       subtitle=Language Options,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\registerctxluafile{lang-url}{autosuffix}
15
16\unprotect
17
18%D Traditionally this code is in the language namespace as
19%D hyphenation relates to languages.
20
21%D \macros
22%D   {hyphenatedurl}
23%D
24%D For those who want to put full \URL's in a text, we offer
25%D
26%D \startbuffer
27%D \hyphenatedurl{http://optimist.optimist/optimist/optimist.optimist#optimist}
28%D \stopbuffer
29%D
30%D \typebuffer
31%D
32%D which breaks at the appropriate places. Watch the \type{#}
33%D hack.
34%D
35%D When passed as argument, like in \type {\goto}, one needs
36%D to substitute a \type {\\} for each \type{#}.
37%D
38%D \startbuffer
39%D \hyphenatedurl{http://this.is.a.rather/strange/reference#indeed}
40%D \stopbuffer
41%D
42%D \typebuffer
43
44\newtoks\everyhyphenatedurl
45
46\appendtoks
47    \resetfontfeature
48    \resetcharacterspacing
49    %
50    \enforced\let\&\letterampersand
51    \enforced\let\#\letterhash
52    \enforced\let\~\lettertilde
53    \enforced\let\\\letterbackslash
54    \enforced\let\$\letterdollar
55    \enforced\let\^\letterhat
56    \enforced\let\_\letterunderscore
57    \enforced\let\{\letterleftbrace
58    \enforced\let\}\letterrightbrace
59    \enforced\let\|\letterbar
60  % \enforced\let~=\lettertilde
61  % \enforced\let|=\letterbar
62    \enforced\letcharcode\tildeasciicode\lettertilde
63    \enforced\letcharcode\barasciicode  \letterbar
64    \enforced\let\Ux\eUx
65\to \everyhyphenatedurl
66
67\mutable\lettonothing\hyphenatedurlseparator     % \periodcentered
68\mutable\lettonothing\hyphenatedurldiscretionary
69
70\setnewconstant\hyphenatedurllefthyphenmin \plusthree
71\setnewconstant\hyphenatedurlrighthyphenmin\plusthree
72
73\def\lang_url_more{\penalty\plustenthousand\hskip\scratchskipone\penalty\plustenthousand}
74\def\lang_url_less{\penalty\plustenthousand\hskip\scratchskiptwo\penalty\plustenthousand}
75\def\lang_url_trac{\penalty\plustenthousand\hsmash{\darkred\vl}\penalty\plustenthousand}
76
77\def\lang_url_a#1{\lang_url_more\char#1\lang_url_show\discretionary{}{\hyphenatedurlseparator}{}}
78\def\lang_url_b#1{\lang_url_more\discretionary{\hyphenatedurlseparator}{}{}\lang_url_show\char#1\relax}
79\def\lang_url_d  {\lang_url_more\discretionary{\lang_url_show}{\lang_url_show}{\lang_url_show}}
80\def\lang_url_l#1{\lang_url_less\char#1\relax}
81\def\lang_url_c#1{\lang_url_more\char#1\relax}
82\def\lang_url_L#1{\lang_url_less\char#1\relax}
83\def\lang_url_C#1{\lang_url_more\char#1\relax}
84
85\permanent\protected\def\showhyphenatedurlbreaks % for old times sake
86  {\let\lang_url_show\lang_url_trac}
87
88\installtextracker
89  {languages.url}
90  {\let\lang_url_show\lang_url_trac}
91  {\let\lang_url_show\relax}
92
93\let\lang_url_show\relax
94
95\permanent\protected\def\sethyphenatedurlnormal#1{\clf_sethyphenatedurlcharacters{#1}{\v!normal}}
96\permanent\protected\def\sethyphenatedurlbefore#1{\clf_sethyphenatedurlcharacters{#1}{\v!before}}
97\permanent\protected\def\sethyphenatedurlafter #1{\clf_sethyphenatedurlcharacters{#1}{\v!after }}
98
99% \sethyphenatedurlafter{ABCDEF}
100
101\permanent\protected\def\hyphenatedurl#1%
102  {\dontleavehmode
103   \begingroup
104   \expand\everyhyphenatedurl
105   \normallanguage\zerocount % \nohyphens in mkiv
106   \scratchskipone\zeropoint\s!plus\dimexpr\emwidth/12\s!minus\dimexpr\emwidth/24\relax % 1.00pt @ 12pt
107   \scratchskiptwo\zeropoint\s!plus\dimexpr\emwidth/48\s!minus\dimexpr\emwidth/96\relax % 0.25pt @ 12pt
108   \unprotect
109   \normalexpanded{\noexpand\clf_hyphenatedurl
110     {\noexpand\detokenize{#1}}%
111     \hyphenatedurllefthyphenmin
112     \hyphenatedurlrighthyphenmin
113     {\hyphenatedurldiscretionary}%
114   }%
115   \protect
116   \endgroup}
117
118%D \macros
119%D   {hyphenatedfilename}
120%D
121%D For the moment we treat filenames in a similar way,
122%D
123%D \starttyping
124%D \hyphenatedfilename{here/there/filename.suffix}
125%D \stoptyping
126
127\ifdefined\hyphenatedfilename \else \aliased\let\hyphenatedfilename\hyphenatedurl \fi
128
129% \def\test#1%
130%   {\dontleavehmode
131%    \begingroup
132%    \tttf
133%    \hyphenatedurl {%
134%      \letterampersand #1\letterampersand #1\letterampersand #1\letterampersand #1\letterampersand
135%      \letterhash      #1\letterhash      #1\letterpercent   #1\letterslash     #1\letterampersand
136%    }%
137%    \endgroup}
138
139% \dorecurse{100}{\test{a} \test{ab} \test{abc} \test{abcd} \test{abcde} \test{abcdef}}
140
141\protect \endinput
142
143% \setuppapersize[A7]
144%
145% \protected\def\WhateverA#1%
146%   {\dontleavehmode
147%    \begingroup
148%    \prehyphenchar"B7\relax
149%    \setbox\scratchbox\hbox{\tttf#1}%
150%    \prehyphenchar`-\relax
151%    \unhbox\scratchbox
152%    \endgroup}
153%
154% \protected\def\WhateverB#1%
155%   {\dontleavehmode
156%    \begingroup
157%    \tttf
158%    \prehyphenchar\minusone
159%  % \localrightbox{\llap{_}}%
160%    \localrightbox{\llap{\smash{\lower1.5ex\hbox{\char"2192}}}}%
161%    \setbox\scratchbox\hbox{#1}%
162%    \prehyphenchar`-\relax
163%    \unhbox\scratchbox
164%    \endgroup}
165%
166% \begingroup \hsize1cm
167%   \WhateverA{thisisaboringandverylongcommand}\par
168%   \WhateverB{thisisaboringandverylongcommand}\par
169% \endgroup
170