aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v5/ao_doc_str.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2014-07-01 00:33:49 -0400
committerRalph Amissah <ralph@amissah.com>2014-07-01 00:33:52 -0400
commit954419b5ae79efb032d28b145ee40d0b61c80c23 (patch)
tree6076bfea3c7a0d93c387a9d4d3bfe1e479aac6d3 /lib/sisu/v5/ao_doc_str.rb
parentsisu.org minor (diff)
v5: merge what was sisu_6.0.8 into v5
* ao, * syntax, able optionally to indicate the language syntax of a code block * syntax, introduce box text block/group * syntax, introduce tics quotes markup (blockquote equivalent) * docbook, * ocn & footnote numbers (as xml comments) * metadata header (docinfo) * quotes (blockquote) * tables * images * code block * vim syntax, add * code block, language syntax, optional * box block * quote block
Diffstat (limited to 'lib/sisu/v5/ao_doc_str.rb')
-rw-r--r--lib/sisu/v5/ao_doc_str.rb164
1 files changed, 115 insertions, 49 deletions
diff --git a/lib/sisu/v5/ao_doc_str.rb b/lib/sisu/v5/ao_doc_str.rb
index 4708a126..e5ed0fd0 100644
--- a/lib/sisu/v5/ao_doc_str.rb
+++ b/lib/sisu/v5/ao_doc_str.rb
@@ -65,10 +65,13 @@ module SiSU_AO_DocumentStructureExtract
@@flag={
ocn: :on,
code: :off,
+ lngsyn: :txt,
poem: :off,
block: :off,
+ box: :off,
group: :off,
alt: :off,
+ quote: :off,
table: :off,
table_to: :off,
}
@@ -81,10 +84,13 @@ module SiSU_AO_DocumentStructureExtract
@@flag={
ocn: :on,
code: :off,
+ lngsyn: :txt,
poem: :off,
block: :off,
+ box: :off,
group: :off,
alt: :off,
+ quote: :off,
table: :off,
table_to: :off,
}
@@ -119,6 +125,11 @@ module SiSU_AO_DocumentStructureExtract
? true
: false
end
+ def quotes?
+ @@flag[:quote]==:open \
+ ? true
+ : false
+ end
def hang_and_indent_test(str)
hang_indent=if str=~/^_([1-9])[^_]/
[$1,$1]
@@ -229,8 +240,10 @@ module SiSU_AO_DocumentStructureExtract
@num_id={
code_block: 0,
poem: 0,
+ box: 0,
group: 0,
alt: 0,
+ quote: 0,
table: 0,
}
@metadata={}
@@ -254,13 +267,14 @@ 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_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \
+ and t_o !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$|^`:quote_(?:open|close)`/ \
and @@flag[:code]==:off \
and @@flag[:poem]==:off \
and @@flag[:group]==:off \
and @@flag[:block]==:off \
and @@flag[:alt]==:off \
+ and @@flag[:box]==:off \
and @@flag[:table]==:off
unless t_o =~/^(?:@\S+?:|%+)\s/ # extract book index for paragraph if any
idx=if t_o=~/^=\{(.+)\}\s*$\Z/m; m=$1
@@ -364,7 +378,7 @@ module SiSU_AO_DocumentStructureExtract
obj << ' ~#'
end
end
- h={ bullet_: bullet, hang: hang, 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, quote: quotes? }
SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
end
else nil
@@ -387,7 +401,7 @@ module SiSU_AO_DocumentStructureExtract
obj << ' ~#'
end
end
- h={ hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags }
+ h={ hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags, quote: quotes? }
SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
end
else nil
@@ -411,22 +425,32 @@ module SiSU_AO_DocumentStructureExtract
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 }
+ h={ bullet_: false, indent: 0, hang: 0, obj: obj, idx: idx, note_: note, image_: image, tags: tags, quote: quotes? }
SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
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: "group text start #{@num_id[:code_block]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ 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
when /^poem\{/ then :curls
@@ -434,8 +458,18 @@ module SiSU_AO_DocumentStructureExtract
else @@flag[:poem] #error
end
@num_id[:poem] +=1
- h={ obj: "poem start #{@num_id[:poem]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :poem_open, num: @num_id[:poem] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
+ tuned_file << t_o
+ elsif t_o =~/^(?:box(?:\.[a-z_]+)?\{|```[ ]+box(?:\.[a-z_]+)?)/
+ @@flag[:box]=case t_o
+ when /^box\{/ then :curls
+ when /^```[ ]+box/ then :tics
+ else @@flag[:box] #error
+ end
+ @num_id[:box] +=1
+ h={ obj: '', sym: :box_open, num: @num_id[:box] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
tuned_file << t_o
elsif t_o =~/^(?:group\{|```[ ]+group)/
@@flag[:group]=case t_o
@@ -444,8 +478,8 @@ module SiSU_AO_DocumentStructureExtract
else @@flag[:group] #error
end
@num_id[:group] +=1
- h={ obj: "group text start #{@num_id[:group]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :group_open, num: @num_id[:group] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
tuned_file << t_o
elsif t_o =~/^(?:block\{|```[ ]+block)/
@@flag[:block]=case t_o
@@ -454,8 +488,8 @@ module SiSU_AO_DocumentStructureExtract
else @@flag[:block] #error
end
@num_id[:block] +=1
- h={ obj: "block text start #{@num_id[:block]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :block_open, num: @num_id[:block] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
tuned_file << t_o
elsif t_o =~/^(?:alt\{|```[ ]+alt)/
@@flag[:alt]=case t_o
@@ -464,14 +498,20 @@ module SiSU_AO_DocumentStructureExtract
else @@flag[:alt] #error
end
@num_id[:alt] +=1
- h={ obj: "alt text start #{@num_id[:alt]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :alt_open, num: @num_id[:alt] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
tuned_file << t_o
+ elsif t_o =~/^`:quote_open`/
+ @@flag[:quote]=:open
+ @num_id[:quote] +=1
+ h={ obj: '', sym: :quote_open, num: @num_id[:quote] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
+ #tuned_file << t_o #% find second source, entered twice, should be once so closed off here
elsif t_o =~/^(?:table\{|```[ ]+table|\{table)[ ~]/
@num_id[:table] +=1
- h={ obj: "table start #{@num_id[:table]}" }
- ins=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
- tuned_file << ins
+ h={ obj: '', sym: :table_open, num: @num_id[:table] }
+ ins_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
+ tuned_file << ins_o
if t_o=~/^table\{(?:~h)?\s+/
@@flag[:table]=:curls
@rows=''
@@ -526,8 +566,8 @@ module SiSU_AO_DocumentStructureExtract
h={ head_: hd, cols: cols, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_id[:table]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :table_close, num: @num_id[:table] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
t_o
elsif t_o=~/^```[ ]+table(?:~h)?\s+/
m1,m2,hd=nil,nil,nil
@@ -549,8 +589,8 @@ module SiSU_AO_DocumentStructureExtract
h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_id[:table]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :table_close, num: @num_id[:table] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
t_o
elsif t_o=~/^\{table(?:~h)?\s+/
m1,m2,hd=nil,nil,nil
@@ -572,8 +612,8 @@ module SiSU_AO_DocumentStructureExtract
h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_id[:table]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :table_close, num: @num_id[:table] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
t_o
end
end
@@ -590,13 +630,13 @@ module SiSU_AO_DocumentStructureExtract
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(@h)
tuned_file << t_o
@h,@rows=nil,''
- h={ obj: "table end #{@num_id[:table]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :table_close, num: @num_id[:table] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
t_o
else
if t_o.is_a?(String) \
and t_o !~/^(?:table\{|```[ ]+table)/
- t_o=t_o.gsub(/^\n+/m,''). #check added for ruby 1.9.2 not needed in 1.8 series (tested in v2)
+ t_o=t_o.gsub(/^\n+/m,'').
gsub(/\n+/m,"#{Mx[:tc_p]}")
@rows += t_o + Mx[:tc_c]
end
@@ -610,12 +650,13 @@ 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
- h={ obj: "code block end #{@num_id[:code_block]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :code_close, num: @num_id[:code_block] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
end
if (@@flag[:code]==:curls or @@flag[:code]==:tics) \
and t_o.is_a?(String)
@@ -627,14 +668,26 @@ module SiSU_AO_DocumentStructureExtract
t_o=nil
end
elsif (@@flag[:poem]==:curls or @@flag[:poem]==:tics) \
+ or (@@flag[:box]==:curls or @@flag[:box]==:tics) \
or (@@flag[:group]==:curls or @@flag[:group]==:tics) \
or (@@flag[:block]==:curls or @@flag[:block]==:tics) \
- or (@@flag[:alt]==:curls or @@flag[:alt]==:tics)
+ or (@@flag[:alt]==:curls or @@flag[:alt]==:tics) \
+ or (@@flag[:quote]==:open and t_o =~/`:quote_close`/m) #not
if (@@flag[:poem]==:curls and t_o =~/^\}poem/) \
or (@@flag[:poem]==:tics and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:poem]=:off
- h={ obj: "poem end #{@num_id[:poem]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :poem_close, num: @num_id[:poem] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
+ elsif (@@flag[:box]==:curls and t_o =~/^\}box/) \
+ or (@@flag[:box]==:tics and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
+ @@flag[:box]=:off
+ obj,tags=extract_tags(@tuned_block.join("\n"))
+ h={ obj: obj, tags: tags, num: @num_id[:box] }
+ @tuned_block=[]
+ t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.box(h)
+ tuned_file << t_o
+ h={ obj: '', sym: :box_close, num: @num_id[:box] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
elsif (@@flag[:group]==:curls and t_o =~/^\}group/) \
or (@@flag[:group]==:tics and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:group]=:off
@@ -643,8 +696,8 @@ module SiSU_AO_DocumentStructureExtract
@tuned_block=[]
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.group(h)
tuned_file << t_o
- h={ obj: "group text end #{@num_id[:group]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :group_close, num: @num_id[:group] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
elsif (@@flag[:block]==:curls and t_o =~/^\}block/) \
or (@@flag[:block]==:tics and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:block]=:off
@@ -653,8 +706,8 @@ module SiSU_AO_DocumentStructureExtract
@tuned_block=[]
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.block(h)
tuned_file << t_o
- h={ obj: "block text end #{@num_id[:block]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :block_close, num: @num_id[:block] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
elsif (@@flag[:alt]==:curls and t_o =~/^\}alt/) \
or (@@flag[:alt]==:tics and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:alt]=:off
@@ -663,15 +716,23 @@ module SiSU_AO_DocumentStructureExtract
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.alt(h)
@tuned_block=[]
tuned_file << t_o
- h={ obj: "alt text end #{@num_id[:alt]}" }
- t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
+ h={ obj: '', sym: :alt_close, num: @num_id[:alt] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
+ elsif @@flag[:quote]==:open and t_o =~/`:quote_close`/m
+ @@flag[:quote]=:off
+ h={ obj: '', sym: :quote_close, num: @num_id[:quote] }
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
+ elsif @@flag[:quote]==:open
+ t_o,tags=extract_tags(t_o)
+ h={ indent: 1, obj: t_o, idx: idx, note_: note, image_: image, tags: tags, quote: quotes? }
+ SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
end
if (@@flag[:poem]==:curls or @@flag[:poem]==:tics \
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|box|alt|group|block)|(?:verse|code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|alt|group|block)\{)/ \
+ and t_o !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-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
@@ -692,8 +753,10 @@ module SiSU_AO_DocumentStructureExtract
end
if @@flag[:code]==:off
if @@flag[:poem]==:curls or @@flag[:poem]==:tics \
+ or @@flag[:box]==:curls or @@flag[:box]==:tics \
or @@flag[:group]==:curls or @@flag[:group]==:tics \
- or @@flag[:alt]==:curls or @@flag[:alt]==:tics
+ or @@flag[:alt]==:curls or @@flag[:alt]==:tics \
+ or (@@flag[:quote]==:open and t_o =~/`:quote_close`/m)
if t_o.is_a?(String)
t_o=t_o.gsub(/\n/m,"#{Mx[:br_nl]}").
gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}").
@@ -702,6 +765,7 @@ module SiSU_AO_DocumentStructureExtract
elsif t_o.is==:group \
|| t_o.is==:block \
|| t_o.is==:alt \
+ || t_o.is==:box \
|| t_o.is==:verse
t_o.obj=t_o.obj.gsub(/\n/m,"#{Mx[:br_nl]}").
gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}").
@@ -758,8 +822,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}").
@@ -1190,6 +1254,7 @@ SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}"}
ocnc+=1
ocn_sp,parent="c#{ocnc}",node
elsif dob.is==:group \
+ || dob.is==:box \
|| dob.is==:block \
|| dob.is==:alt \
|| dob.is==:verse
@@ -1237,6 +1302,7 @@ SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}"}
if dob.is==:code \
|| dob.is==:verse \
|| dob.is==:alt \
+ || dob.is==:box \
|| dob.is==:group \
|| dob.is==:block
dob.obj=dob.obj.gsub(/\n+/,"\n") #newlines taken out