diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lang-url.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/lang-url.lua | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/Master/texmf-dist/tex/context/base/lang-url.lua b/Master/texmf-dist/tex/context/base/lang-url.lua index e401e41484d..09a4e5d903f 100644 --- a/Master/texmf-dist/tex/context/base/lang-url.lua +++ b/Master/texmf-dist/tex/context/base/lang-url.lua @@ -9,7 +9,7 @@ if not modules then modules = { } end modules ['lang-url'] = { local utf = unicode.utf8 local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues -local utfbyte, utfgsub = utf.byte, utf.gsub +local utfbyte, utfchar, utfgsub = utf.byte, utf.char, utf.gsub context = context @@ -26,59 +26,69 @@ dealing with <l n='ascii'/> characters.</p> commands.hyphenatedurl = commands.hyphenatedurl or { } local hyphenatedurl = commands.hyphenatedurl -hyphenatedurl.characters = utilities.storage.allocate { - ["!"] = 1, - ["\""] = 1, - ["#"] = 1, - ["$"] = 1, - ["%"] = 1, - ["&"] = 1, - ["("] = 1, - ["*"] = 1, - ["+"] = 1, - [","] = 1, - ["-"] = 1, - ["."] = 1, - ["/"] = 1, - [":"] = 1, - [";"] = 1, - ["<"] = 1, - ["="] = 1, - [">"] = 1, - ["?"] = 1, - ["@"] = 1, - ["["] = 1, - ["\\"] = 1, - ["^"] = 1, - ["_"] = 1, - ["`"] = 1, - ["{"] = 1, - ["|"] = 1, - ["~"] = 1, - - ["'"] = 2, - [")"] = 2, - ["]"] = 2, - ["}"] = 2 +local characters = utilities.storage.allocate { + ["!"] = 1, + ["\""] = 1, + ["#"] = 1, + ["$"] = 1, + ["%"] = 1, + ["&"] = 1, + ["("] = 1, + ["*"] = 1, + ["+"] = 1, + [","] = 1, + ["-"] = 1, + ["."] = 1, + ["/"] = 1, + [":"] = 1, + [";"] = 1, + ["<"] = 1, + ["="] = 1, + [">"] = 1, + ["?"] = 1, + ["@"] = 1, + ["["] = 1, + ["\\"] = 1, + ["^"] = 1, + ["_"] = 1, + ["`"] = 1, + ["{"] = 1, + ["|"] = 1, + ["~"] = 1, + + ["'"] = 2, + [")"] = 2, + ["]"] = 2, + ["}"] = 2, } +local mapping = utilities.storage.allocate { +--~ [utfchar(0xA0)] = "~", -- nbsp (catch) +} + +hyphenatedurl.characters = characters +hyphenatedurl.mapping = mapping hyphenatedurl.lefthyphenmin = 2 hyphenatedurl.righthyphenmin = 3 hyphenatedurl.discretionary = nil -local chars = hyphenatedurl.characters +-- more fun is to write nodes -local function action(hyphenatedurl, str, left, right, disc) +local function action(hyphenatedurl,str,left,right,disc) local n = 0 local b = math.max( left or hyphenatedurl.lefthyphenmin, 2) local e = math.min(#str-(right or hyphenatedurl.righthyphenmin)+2,#str) local d = disc or hyphenatedurl.discretionary for s in utfcharacters(str) do n = n + 1 + s = mapping[s] or s + if n > 1 then + context.s() -- can be option + end if s == d then context.d(utfbyte(s)) else - local c = chars[s] + local c = characters[s] if not c or n<=b or n>=e then context.n(utfbyte(s)) elseif c == 1 then @@ -92,13 +102,13 @@ end -- hyphenatedurl.action = function(_,...) action(...) end -- sort of obsolete -table.setmetatablecall(hyphenatedurl,action) +table.setmetatablecall(hyphenatedurl,action) -- watch out: a caller -- todo, no interface in mkiv yet function hyphenatedurl.setcharacters(str,value) -- 1, 2 == before, after for s in utfcharacters(str) do - chars[s] = value or 1 + characters[s] = value or 1 end end |