From 5e292103d5da448844c7c5bc38b920874d895107 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 26 Jul 2011 20:22:49 -0400 Subject: v3: dal, indent, control of first line of indent & rest of paragraph * implements hanging indent, and possibility to set first line step indent * __[1-9] hanging indent (initial indent 0); paragraph text indent [1-9] * _[0-9]?_[1-9] initial indent; paragraph text indent * __[1-9]! bold words \\ part of hanging indent paragraph text --- lib/sisu/v3/dal_doc_str.rb | 66 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 8 deletions(-) (limited to 'lib/sisu/v3/dal_doc_str.rb') diff --git a/lib/sisu/v3/dal_doc_str.rb b/lib/sisu/v3/dal_doc_str.rb index ed289015..52425437 100644 --- a/lib/sisu/v3/dal_doc_str.rb +++ b/lib/sisu/v3/dal_doc_str.rb @@ -92,8 +92,36 @@ module SiSU_document_structure_extract def bullet_test(str) bool=((str=~/\*/) ? true : false) end - def indent_test(str) - num=((str=~/^_([1-9])/) ? $1 : 0) + def hang_and_indent_test(str) + hang_indent=if str=~/^_([1-9])[^_]/ + [$1,$1] + elsif str=~/^__([1-9])/ + [0,$1] + elsif str=~/^_([0-9])_([0-9])/ + [$1,$2] + else + [0,0] + end + hang,indent=hang_indent[0],hang_indent[1] + [hang,indent] + end + def hang_and_indent_def_test(str1,str2) + hang_indent=if str1=~/^_([1-9])[^_]/ + [$1,$1] + elsif str1=~/^__([1-9])/ + [0,$1] + elsif str1=~/^_([0-9])_([0-9])/ + [$1,$2] + else + [0,0] + end + obj=if str2 =~/^(.+?)\s+\\\\(?:\s+|\n)/ + str2.gsub(/^(.+?)(\s+\\\\(?:\s+|\n))/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2") + else + str2.gsub(/^(.+?)\n/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\n") + end + hang,indent=hang_indent[0],hang_indent[1] + [hang,indent,obj] end def endnote_test?(str) bool=((str=~/~\{.+?\}~|~\[.+?\]~/) ? true : false) @@ -171,16 +199,37 @@ module SiSU_document_structure_extract SiSU_document_structure::Object_heading.new.heading(h) else nil end - when /^(?:_[1-9]|_[1-9]?\*)\s+/ #indented and/or bullet paragraph - t_o=if t_o=~/^(_(?:[1-9]?\*|[1-9])\s+)(.+)/m + when /^_(?:[1-9]!?|[1-9]?\*)\s+/ #indented and/or bullet paragraph + t_o=if t_o=~/^(_(?:[1-9]?\*|[1-9]!?)\s+)(.+)/m tst,obj=$1,$2 - indent=indent_test(tst) + if t_o=~/^_[1-9]!\s+.+/m + hang,indent,obj=hang_and_indent_def_test(tst,obj) + else + hang,indent=hang_and_indent_test(tst) + end bullet=bullet_test(tst) image=image_test(obj) note=endnote_test?(obj) obj,tags=extract_tags(obj) unless obj=~/\A\s*\Z/m - h={ bullet_: bullet, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + h={ bullet_: bullet, hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + SiSU_document_structure::Object_para.new.paragraph(h) + end + else nil + end + when /^_[0-9]?_[0-9]!?\s+/ #hanging indent paragraph + t_o=if t_o=~/^(_[0-9]?_[0-9]!?\s+)(.+)/m + tst,obj=$1,$2 + if t_o=~/^_[0-9]?_[0-9]!\s+.+/m + hang,indent,obj=hang_and_indent_def_test(tst,obj) + else + hang,indent=hang_and_indent_test(tst) + end + image=image_test(obj) + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + unless obj=~/\A\s*\Z/m + h={ hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } SiSU_document_structure::Object_para.new.paragraph(h) end else nil @@ -196,7 +245,7 @@ module SiSU_document_structure_extract note=endnote_test?(t_o) obj,tags=extract_tags(t_o) unless obj=~/\A\s*\Z/m - h={ bullet_: false, indent: 0, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + h={ bullet_: false, indent: 0, hang: 0, obj: obj, idx: idx, note_: note, image_: image, tags: tags } SiSU_document_structure::Object_para.new.paragraph(h) end end @@ -725,7 +774,8 @@ module SiSU_document_structure_extract end def structure_markup #build structure where structure provided only in meta header @dob=if @dob.is =~/para/ \ - and @dob.indent !~/[1-9]/ \ + and ((@dob.hang !~/[1-9]/ and @dob.indent !~/[1-9]/) \ + or (@dob.hang != @dob.indent)) \ and not @dob.bullet_ @dob=case @dob.obj when /^#{@md.lv1}/ -- cgit v1.2.3