diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-bkm.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/strc-bkm.lua | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-bkm.lua b/Master/texmf-dist/tex/context/base/strc-bkm.lua index 8f8a3ca246a..f34d83ec557 100644 --- a/Master/texmf-dist/tex/context/base/strc-bkm.lua +++ b/Master/texmf-dist/tex/context/base/strc-bkm.lua @@ -1,6 +1,6 @@ if not modules then modules = { } end modules ['strc-bkm'] = { version = 0.200, - comment = "companion to strc-bkm.tex", + comment = "companion to strc-bkm.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files" @@ -59,21 +59,35 @@ local function stripped(str) -- kind of generic return str end +-- todo: collect specs and collect later i.e. multiple places + function bookmarks.place() if names ~= "" then local list = lists.filter(names,"all",nil,lists.collected) + local lastlevel = 1 if #list > 0 then local opened, levels = aux.settings_to_set(opened), { } for i=1,#list do local li = list[i] local metadata = li.metadata local name = metadata.name - if not metadata.nolist and levelmap[name] then + if not metadata.nolist then -- and levelmap[name] then local titledata = li.titledata if titledata then + local structural = levelmap[name] + lastlevel = structural or lastlevel + local title = titledata.bookmark + if not title or title == "" then + if not structural then + -- placeholder, todo: bookmarklabel + title = name .. ": " .. (titledata.title or "?") + else + title = titledata.title or "?" + end + end levels[#levels+1] = { - levelmap[name], - stripped(titledata.bookmark or titledata.title or "?"), + lastlevel, + stripped(title), li.references, -- has internal and realpage allopen or opened[name] } @@ -85,3 +99,33 @@ function bookmarks.place() function bookmarks.place() end -- prevent second run end end + +lpdf.registerdocumentfinalizer(function() structure.bookmarks.place() end,1) + +-- bkm +--~ function nodes.toutf(list) +--~ local t= { } +--~ for n in node.traverse(list) do +--~ local id = n.id +--~ if id == node.id("glyph") then +--~ local c = n.char +--~ local f = fonts.ids[n.font] +--~ if f then +--~ local u = f.characters[c].tounicode +--~ if u then +--~ for s in string.gmatch(u,"..") do +--~ t[#t+1] = utf.char(tonumber(s,16)) +--~ end +--~ else +--~ t[#t+1] = utf.char(c) +--~ end +--~ else +--~ t[#t+1] = utf.char(c) +--~ end +--~ elseif id == node.id("glue") then +--~ t[#t+1] = " " +--~ end +--~ end +--~ return table.concat(t,"") +--~ end +--~ print(nodes.toutf(tex.box[999].list)) |