c&d: po4a, book index, reinstate
[software/sisu] / lib / sisu / current / po4a.rb
index 097fb2c66f9030160b8937585c4384b365e3edc0..f7d89c2d618da7d42f411400579174472cb223b5 100644 (file)
@@ -747,25 +747,65 @@ GSUB
         unwrapped=util.no_line_wrap_block
         @pot[:body] << unwrapped << br
       end
+      def pot_structure_idx_markup(idx)
+        struct=['={']
+        idx.sort.each do |x|
+          x.each_with_index do |y,i0|
+            case y
+            when String
+              struct << ';' unless struct[-1] =~/=\{/
+              struct << y
+              if x[i0+1].class == Hash \
+              and x[i0+1][:sub].length > 0
+                struct << ':'
+              end
+            when Hash
+              if y[:plus].to_i > 0
+                struct << '+' + y[:plus].to_s
+              end
+              if y[:sub].length > 0
+                y[:sub].each_with_index do |z,i1|
+                  z.each_with_index do |a,i2|
+                    #p a
+                    if z.length > 0
+                      struct << a[0]
+                      if a[1][:plus].to_i > 0
+                        struct << '+' + a[1][:plus].to_s
+                      end
+                      if (i1 + 1) < y[:sub].length
+                        struct << '|'
+                      end
+                    end
+                  end
+                end
+              end
+            end
+          end
+        end
+        struct << '}'
+        #puts struct.join
+        struct.join
+      end
       def pot_structure_idx(dob_src='',dob_trn='')                             #% used for book index but broken as original markup lost, already abstracted, fix
-        #mark="={ ... }"
-        #instruct=s_mark=''
-        #if @md.opt.act[:maintenance][:set]==:on
-        #  instruct="\n# the book index should be attached unwrapped to the preceding text block (there should be a new line, but no empty line)"
-        #  s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
-        #end
-        #d='book-idx'
-        #desc="#{d}#{s_mark}#{instruct}"
-        #orig='={' + dob_src.idx + '}'
-        #trans=if defined? dob_trn.idx \
-        #and not dob_trn.idx.nil? \
-        #and not dob_trn.idx.empty?
-        #  '={' + dob_trn.idx + '}'
-        #else ''
-        #end
-        #util=pot_structure(desc,orig,trans)
-        #unwrapped=util.no_line_wrap_block
-        #@pot[:body] << unwrapped << br
+        mark="={ ... }"
+        instruct=s_mark=''
+        if @md.opt.act[:maintenance][:set]==:on
+          instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \
+          + %{(there should be a new line, but no empty line)}
+          s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
+        end
+        d='book-idx'
+        desc="#{d}#{s_mark}#{instruct}"
+        orig=pot_structure_idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
+        trans=if defined? dob_trn.idx \
+        and not dob_trn.idx.nil? \
+        and not dob_trn.idx.empty?
+          pot_structure_idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}'
+        else ''
+        end
+        util=pot_structure(desc,orig,trans)
+        unwrapped=util.no_line_wrap_block
+        @pot[:body] << unwrapped << br
       end
       def pot_markup(data_src,data_trn)
         #@endnotes,@copen,@pot_contents_close=Array.new(3){[]}