Philipp Gesang avatar Philipp Gesang committed 0a72f02

[cbk] fix handling of ligatures and multiple replacements

Comments (0)

Files changed (2)

doc/context/third/enigma/enigma_manual.tex

 
 \startdocchapter[title=Usage]
 
-\startdocsection[title=Loading the Module/Package]
+\startdocsection[title=Loading the Module / Package]
   The intention is for the \modulename{Enigma} codebase to integrate
   with the three most popular (as of 2012) \TEX\ formats:
     \CONTEXT,
 applied.
 
 \startcontexttyping
-\usemodule[enigma]              %% load the module
+\usemodule [enigma]             %% load the module
 \defineenigma [secretmessage]   %% generate and
 \setupenigma  [secretmessage] [ %% configure a machine
   day_key = B IV V II 01 01 01 AD CN ET FL GI JV KZ PU QY WX,

tex/context/third/enigma/enigma.lua

   if machine.spacing then -- auto-group output
     insert_encoded = function (head, n, replacement)
       local insertion = nodecopy(n)
+      local current_node = insertion -- needed for multi replacements
       if replacement then -- inefficient but bulletproof
         insertion.char = utf8byte(replacement)
         --print(utf8char(n.char), "=>", utf8char(insertion.char))
       mod_5 = mod_5 + 1
       if mod_5 >= 5 then
         mod_5 = 0
-        nodeinsert_after(head, insertion, nodecopy(space_node))
+        current_node = nodecopy(space_node)
+        nodeinsert_after(head, insertion, nodecopy(current_node))
       end
       noderemove(head, n)
+      return current_node -- so we know where to insert
     end
   else
     insert_encoded = function (head, n, replacement)
       end
       nodeinsert_before(head, n, insertion)
       noderemove(head, n)
+      return insertion
     end
   end
   local format_is_context_p = format_is_context_p
         elseif treplacement == "string" then
           insert_encoded(head, n, replacement)
         elseif treplacement == "table" then
+          local current = n
           for i=1, #replacement do
-            insert_encoded(head, n, replacement)
+            current = insert_encoded(head, current, replacement[i])
           end
         end
       elseif nid == GLUE_NODE then
       elseif nid == DISC_NODE then
         --- ligatures need to be resolved if they are characters
         local npre, npost = n.pre, n.post
-        if npre and npost then
-          local replacement_pre  = machine:encode(utf8char(npre.char))
-          local replacement_post = machine:encode(utf8char(npost.char))
-          insert_encoded(head,  npre, replacement_pre)
-          insert_encoded(head, npost, replacement_post)
+        if nodeid(npre)  == GLYPH_NODE and
+           nodeid(npost) == GLYPH_NODE then
+          if npre.char and npost.char then -- ligature between glyphs
+            local replacement_pre  = machine:encode(utf8char(npre.char))
+            local replacement_post = machine:encode(utf8char(npost.char))
+            insert_encoded(head,  npre, replacement_pre)
+            insert_encoded(head, npost, replacement_post)
+          else -- hlists or whatever
+            -- pass
+            --noderemove(head, npre)
+            --noderemove(head, npost)
+          end
         end
         noderemove(head, n)
       --else
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.