From 386233f07b668554d0057c405c661a95d588b43a Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 21 Aug 2013 23:14:21 -0400 Subject: v5: markup syntax add: switch ocn (object numbering) off & on for content block * switch ocn off & on for a block of content, line containing only off: "--~#" (omit headings where possible) "---#" on: "--+#" --- data/doc/sisu/CHANGELOG_v5 | 4 +++ lib/sisu/v5/dal_doc_objects.rb | 27 +++++++++++++++++ lib/sisu/v5/dal_doc_str.rb | 66 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5 index d0d18914..a7c6e2cd 100644 --- a/data/doc/sisu/CHANGELOG_v5 +++ b/data/doc/sisu/CHANGELOG_v5 @@ -30,6 +30,10 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.0.12.orig.tar.xz sisu_5.0.12.orig.tar.xz sisu_5.0.12-1.dsc +* syntax add + * switch ocn off and on for a block of content, line containing only + off: "--~#" (omit headings where possible) "---#" on: "--+#" + * messages to terminal * code marker * rescued error messages diff --git a/lib/sisu/v5/dal_doc_objects.rb b/lib/sisu/v5/dal_doc_objects.rb index 64ddbfb1..b2be6105 100644 --- a/lib/sisu/v5/dal_doc_objects.rb +++ b/lib/sisu/v5/dal_doc_objects.rb @@ -423,6 +423,33 @@ module SiSU_DAL_DocumentStructure self end end + class ObjectFlag + attr_accessor :obj,:is,:of,:flag,:mod,:tmp + def initialize + @of=:flag + @is=@obj=@flag=@mod=@tmp=nil + end + def flag(h,o=nil) + of= @of #String, classification - group + is= :flag #String, classification - specific type + obj= nil #String, text content + flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content + mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content + tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp + self + end + def flag_ocn(h,o=nil) + of= @of #String, classification - group + is= :flag_ocn #String, classification - specific type + obj= nil #String, text content + flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content + mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content + tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp + self + end + end class ObjectLayout attr_accessor :obj,:is,:of,:from,:tmp def initialize diff --git a/lib/sisu/v5/dal_doc_str.rb b/lib/sisu/v5/dal_doc_str.rb index 70c2e61f..c8174323 100644 --- a/lib/sisu/v5/dal_doc_str.rb +++ b/lib/sisu/v5/dal_doc_str.rb @@ -157,6 +157,24 @@ module SiSU_DAL_DocumentStructureExtract @@counter,@verse_count=0,0 @metadata={} @data.each do |t_o| + if t_o =~/^--([+~-])[#]$/ + h=case $1 + when /[+]/ + @@flag[:ocn]=:on + {flag: :ocn_on} + when /[~]/ + @@flag[:ocn]=:off_headings_substantive + {flag: :ocn_off, mod: :headings_substantive} + when /[-]/ + @@flag[:ocn]=:off_headings_exclude + {flag: :ocn_off, mod: :headings_exclude} + else + @@flag[:ocn]=:on + {flag: :ocn_on} + end + t_o=SiSU_DAL_DocumentStructure::ObjectFlag.new.flag_ocn(h) + next + end t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") unless @@flag['code'] if t_o !~/^(?:code|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \ and not @@flag['code'] \ @@ -192,18 +210,48 @@ module SiSU_DAL_DocumentStructureExtract obj=$1 note=endnote_test?(obj) obj,tags=extract_tags(obj) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + end h={ lv: lv, ln: ln, obj: obj, idx: idx, tags: tags } SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) elsif t_o=~/^:?[A-C1-6]\~(\S+?)-\s+(.+)/m name,obj=$1,$2 note=endnote_test?(obj) obj,tags=extract_tags(obj) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + end h={ lv: lv, name: name, obj: obj, idx: idx, autonum_: false, tags: tags} SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) elsif t_o=~/^:?[A-C1-6]\~(\S+)\s+(.+)/m name,obj=$1,$2 note=endnote_test?(obj) obj,tags=extract_tags(obj,name) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + end h={ lv: lv, name: name, obj: obj, idx: idx, tags: tags } SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) else nil @@ -221,6 +269,12 @@ module SiSU_DAL_DocumentStructureExtract note=endnote_test?(obj) obj,tags=extract_tags(obj) unless obj=~/\A\s*\Z/m + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end h={ bullet_: bullet, hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) end @@ -238,6 +292,12 @@ module SiSU_DAL_DocumentStructureExtract note=endnote_test?(obj) obj,tags=extract_tags(obj) unless obj=~/\A\s*\Z/m + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end h={ hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) end @@ -255,6 +315,12 @@ module SiSU_DAL_DocumentStructureExtract image=image_test(t_o) note=endnote_test?(t_o) obj,tags=extract_tags(t_o) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end unless obj=~/\A\s*\Z/m h={ bullet_: false, indent: 0, hang: 0, obj: obj, idx: idx, note_: note, image_: image, tags: tags } SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) -- cgit v1.2.3