From fa8a138532c5d7ac63094d23e3df335ad08a8206 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 19 Jun 2014 19:32:00 -0400 Subject: v6: ao, syntax, able optionally to indicate the language syntax of a code block --- data/doc/sisu/CHANGELOG_v6 | 1 + lib/sisu/v6/ao_doc_objects.rb | 7 ++++--- lib/sisu/v6/ao_doc_str.rb | 39 ++++++++++++++++++++++++------------- lib/sisu/v6/ao_expand_insertions.rb | 2 +- lib/sisu/v6/ao_misc_arrange.rb | 18 ++++++++--------- lib/sisu/v6/ao_syntax.rb | 2 +- 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6 index ce7b2e89..3f8f6e29 100644 --- a/data/doc/sisu/CHANGELOG_v6 +++ b/data/doc/sisu/CHANGELOG_v6 @@ -32,6 +32,7 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.0.8.orig.tar.xz * regex match for tics "```" followed by space tweaked * Symbol to match grouped text open & close (instead of String) * introduce way of removing unrecognized tic markers + * syntax, able optionally to indicate the language syntax of a code block * turn id numbers (for tags) into a hash * code blocks, clean trailing newlines * misc, minorish diff --git a/lib/sisu/v6/ao_doc_objects.rb b/lib/sisu/v6/ao_doc_objects.rb index 1d95e2c9..9356321c 100644 --- a/lib/sisu/v6/ao_doc_objects.rb +++ b/lib/sisu/v6/ao_doc_objects.rb @@ -240,10 +240,10 @@ module SiSU_AO_DocumentStructure end end class ObjectBlockTxt - attr_accessor :obj,:is,:of,:tags,:idx,:ocn,:odv,:osp,:parent,:note_,:number_,:ocn_,:digest,:tmp + attr_accessor :obj,:is,:of,:tags,:lngsyn,:idx,:ocn,:odv,:osp,:parent,:note_,:number_,:ocn_,:digest,:tmp def initialize @of=:block - @is=@obj=@idx=@ocn=@odv=@osp=@parent=@note_=@number_=@ocn_=@digest=@tmp=nil + @is=@obj=@lngsyn=@idx=@ocn=@odv=@osp=@parent=@note_=@number_=@ocn_=@digest=@tmp=nil @tags=[] end def code(h,o=nil) @@ -251,6 +251,7 @@ module SiSU_AO_DocumentStructure is= :code #Symbol, classification - specific type tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + lngsyn= h[:lngsyn] || ((defined? o.lngsyn) ? o.lngsyn : :txt) #symbol, code lngsyn idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) @@ -264,7 +265,7 @@ module SiSU_AO_DocumentStructure num= h[:num] || ((defined? o.num) ? o.num : nil) digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, sha512, sha256 or md5 tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@number_,@note_,@ocn_,@num,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,number_,note_,ocn_,num,digest,tmp + @of,@is,@tags,@obj,@lngsyn,@idx,@ocn,@odv,@osp,@parent,@number_,@note_,@ocn_,@num,@digest,@tmp=of,is,tags,obj,lngsyn,idx,ocn,odv,osp,parent,number_,note_,ocn_,num,digest,tmp self end def block(h,o=nil) diff --git a/lib/sisu/v6/ao_doc_str.rb b/lib/sisu/v6/ao_doc_str.rb index 2b2a86fc..0d9d7576 100644 --- a/lib/sisu/v6/ao_doc_str.rb +++ b/lib/sisu/v6/ao_doc_str.rb @@ -65,6 +65,7 @@ module SiSU_AO_DocumentStructureExtract @@flag={ ocn: :on, code: :off, + lngsyn: :txt, poem: :off, block: :off, group: :off, @@ -81,6 +82,7 @@ module SiSU_AO_DocumentStructureExtract @@flag={ ocn: :on, code: :off, + lngsyn: :txt, poem: :off, block: :off, group: :off, @@ -254,8 +256,8 @@ module SiSU_AO_DocumentStructureExtract next end t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") if @@flag[:code]==:off - if t_o !~/^(?:code|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \ - and t_o !~/^```[ ]+(?:code|poem|alt|group|block|table)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ \ + if t_o !~/^(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \ + and t_o !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ \ and @@flag[:code]==:off \ and @@flag[:poem]==:off \ and @@flag[:group]==:off \ @@ -416,16 +418,26 @@ module SiSU_AO_DocumentStructureExtract end end elsif @@flag[:code]==:off - if t_o =~/^(?:code\{|```[ ]+code)/ + if t_o =~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|```[ ]+code(?:\.[a-z][0-9a-z_]+)?)/ @@flag[:code]=case t_o - when /^code\{/ then :curls - when /^```[ ]+code/ then :tics - else @@flag[:code] #error + when /^code(?:\.[a-z][0-9a-z_]+)?\{/ then :curls + when /^```[ ]+code/ then :tics + else @@flag[:code] #error + end + @@flag[:lngsyn]=if t_o =~/^(?:code\.[a-z][0-9a-z_]+\{|```[ ]+code\.[a-z_]+)/ + case t_o + when /^code\.([a-z][0-9a-z_]+)\{/ + :"#{$1}" + when /^```[ ]+code\.([a-z][0-9a-z_]+)/ + :"#{$1}" + else :txt + end + else :txt end @@counter=1 - @codeblock_numbered=(t_o =~/^(?:code\{#|```[ ]+code\s[#])/) ? true : false + @codeblock_numbered=(t_o =~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{#|```[ ]+code(?:\.[a-z][0-9a-z_]+)?\s[#])/) ? true : false @num_id[:code_block] +=1 - h={ obj: '', sym: :code_block_open, num: @num_id[:code_block] } + h={ obj: '', sym: :code_block_open, num: @num_id[:code_block], syntax: @@flag[:lngsyn] } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) elsif t_o =~/^(?:poem\{|```[ ]+poem)/ @@flag[:poem]=case t_o @@ -610,7 +622,8 @@ module SiSU_AO_DocumentStructureExtract @tuned_code[-1].gsub!(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*\Z/m,'') obj=@tuned_code.join("\n") tags=[] - h={ obj: obj, tags: tags, num: @num_id[:code_block], number_: @codeblock_numbered } + h={ obj: obj, syntax: @@flag[:lngsyn], tags: tags, num: @num_id[:code_block], number_: @codeblock_numbered } + @@flag[:lngsyn]=:txt t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.code(h) @tuned_code=[] tuned_file << t_o @@ -670,8 +683,8 @@ module SiSU_AO_DocumentStructureExtract or @@flag[:group]==:curls or @@flag[:group]==:tics \ or @@flag[:alt]==:curls or @@flag[:alt]==:tics) \ and t_o =~/\S/ \ - and t_o !~/^(?:\}(?:verse|code|alt|group|block)|(?:verse|code|alt|group|block)\{)/ \ - and t_o !~/^```[ ]+(?:code|poem|alt|group|block)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ # fix logic + and t_o !~/^(?:\}(?:verse|code|alt|group|block)|(?:verse|code(?:\.[a-z][0-9a-z_]+)?|alt|group|block)\{)/ \ + and t_o !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ # fix logic sub_array=t_o.dup @line_mode=sub_array.scan(/.+/) type=if @@flag[:poem]==:curls or @@flag[:poem]==:tics @@ -758,8 +771,8 @@ module SiSU_AO_DocumentStructureExtract lines,lines_new=@data,[] lines.each do |line| line=if line =~/\S/ \ - and line !~/^(?:code\{|\}code)/ \ - and line !~/^(?:```[ ]+code|```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \ + and line !~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|\}code)/ \ + and line !~/^(?:```[ ]+code(?:\.[a-z][0-9a-z_]+)?|```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \ and not line.is_a?(Hash) #watch @@counter+=1 if @@flag[:code]==:curls or @@flag[:code]==:tics line=line.gsub(/\s\s/,"#{Mx[:nbsp]*2}"). diff --git a/lib/sisu/v6/ao_expand_insertions.rb b/lib/sisu/v6/ao_expand_insertions.rb index 6b1e642d..22e3b1ea 100644 --- a/lib/sisu/v6/ao_expand_insertions.rb +++ b/lib/sisu/v6/ao_expand_insertions.rb @@ -333,7 +333,7 @@ module SiSU_AO_Insertions tuned_file,tuned_file_tmp=[],[] codeblock_=false data.each do |para| - codeblock_=if para =~/^(?:code\{|```[ ]+code)/ + codeblock_=if para =~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|```[ ]+code(?:\.[a-z][0-9a-z_]+)?)/ true elsif para =~/^(?:\}code|```(?:\s|$))/m false diff --git a/lib/sisu/v6/ao_misc_arrange.rb b/lib/sisu/v6/ao_misc_arrange.rb index e58ce72a..a6b3a73d 100644 --- a/lib/sisu/v6/ao_misc_arrange.rb +++ b/lib/sisu/v6/ao_misc_arrange.rb @@ -77,14 +77,14 @@ module SiSU_AO_MiscArrangeText def markup_blocks(para) def ticks(para) block_open,block_close,text=nil,nil,nil - if para =~/\A```[ ]+(?:code|poem|alt|group|block|table).*?\n.+?\n```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m + if para =~/\A```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table).*?\n.+?\n```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m @flag=:close - block_open,text,block_close=/\A(```[ ]+(?:code|poem|alt|group|block|table).*?)\n(.+?)\n(```([ ]+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1..3] + block_open,text,block_close=/\A(```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table).*?)\n(.+?)\n(```([ ]+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1..3] ((para=~/^```[ ]+table(?:~h)?\s+/) \ and (para !~/^```[ ]+table(?:~h)?\s+c\d+/)) \ ? para : (para=[]; para << block_open << text << block_close) - elsif para =~/\A```[ ]+(?:code|poem|alt|group|block|table).*?\n.*?\Z/m #look at, study + elsif para =~/\A```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table).*?\n.*?\Z/m #look at, study @flag=:open block_open,text=/\A(```(?:[ ]+.+?))\n(.*?)\Z/m.match(para)[1,2] para=[] @@ -117,12 +117,12 @@ module SiSU_AO_MiscArrangeText end def curly_braces(para) block_open,block_close,text=nil,nil,nil - para=if para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m - block_open,text,block_close=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1..3] + para=if para =~/\A(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table)\{ .+?\n.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m + block_open,text,block_close=/\A((?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table)\{ .+?)\n(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1..3] para=[] para << block_open << text << block_close - elsif para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\Z/m - block_open,text=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\Z/m.match(para)[1,2] + elsif para =~/\A(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table)\{ .+?\n.+?\Z/m + block_open,text=/\A((?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table)\{ .+?)\n(.+?)\Z/m.match(para)[1,2] para=[] if not text.to_s.empty? para << block_open << text @@ -141,7 +141,7 @@ module SiSU_AO_MiscArrangeText end para end - para=if para =~/\A```[ ]+(?:code|poem|alt|group|block|table).*?\n.*?\Z/m \ + para=if para =~/\A```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table).*?\n.*?\Z/m \ or @flag==:open ticks(para) elsif para =~/```/m @@ -149,7 +149,7 @@ module SiSU_AO_MiscArrangeText else para end - para=(para =~/^(?:code|poem|alt|group|block|table)\{|^\}(?:code|poem|alt|group|block|table)/m) \ + para=(para =~/^(?:code(?:\.[a-z][0-9a-z_]+)?|poem|alt|group|block|table)\{|^\}(?:code|poem|alt|group|block|table)/m) \ ? curly_braces(para) : para end diff --git a/lib/sisu/v6/ao_syntax.rb b/lib/sisu/v6/ao_syntax.rb index 8a13e406..fb3508b9 100644 --- a/lib/sisu/v6/ao_syntax.rb +++ b/lib/sisu/v6/ao_syntax.rb @@ -91,7 +91,7 @@ module SiSU_AO_Syntax { o: Mx[:fa_underscore_o], c: Mx[:fa_underscore_c] } else p __LINE__.to_s + '::' + __FILE__ end - @http_m=%r{\{.+?\}https?://\S+|https?:\S+|:\S+|\.\.\/\S+|#\S+|\S+?\.png\b|[*]~\S+|^#{Mx[:meta_o]}.+|#{Mx[:gr_o]}(?:code|block|group|alt|verse)(?:-end)?#{Mx[:gr_c]}|#{Mx[:fa_o]}:br#{Mx[:fa_c]}} + @http_m=%r{\{.+?\}https?://\S+|https?:\S+|:\S+|\.\.\/\S+|#\S+|\S+?\.png\b|[*]~\S+|^#{Mx[:meta_o]}.+|#{Mx[:gr_o]}(?:code(?:\.[a-z][0-9a-z_]+)?|block|group|alt|verse)(?:-end)?#{Mx[:gr_c]}|#{Mx[:fa_o]}:br#{Mx[:fa_c]}} @manmkp_ital=emph_italics \ ? '[i/*]\\{.+?\\}[i/*]' : '[i/]\\{.+?\\}[i/]' -- cgit v1.2.3