From 99c5b5d56f8785ee9ec2cc991c55a8a2eb6524bb Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 5 Feb 2014 01:02:31 -0500 Subject: v5 v6: html, endnote name and nameref make compliant (epub use same) --- lib/sisu/v5/constants.rb | 6 ++++++ lib/sisu/v5/html_format.rb | 2 +- lib/sisu/v5/html_segments.rb | 6 +++--- lib/sisu/v5/html_tune.rb | 12 ++++++------ lib/sisu/v5/xhtml_epub2_format.rb | 6 +++--- lib/sisu/v5/xhtml_epub2_segments.rb | 2 +- lib/sisu/v5/xhtml_epub2_tune.rb | 20 ++++++++++---------- lib/sisu/v6/constants.rb | 6 ++++++ lib/sisu/v6/html_format.rb | 2 +- lib/sisu/v6/html_segments.rb | 6 +++--- lib/sisu/v6/html_tune.rb | 12 ++++++------ lib/sisu/v6/xhtml_epub2_format.rb | 6 +++--- lib/sisu/v6/xhtml_epub2_segments.rb | 2 +- lib/sisu/v6/xhtml_epub2_tune.rb | 20 ++++++++++---------- 14 files changed, 60 insertions(+), 48 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index fea57ce8..a9be54f0 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -102,6 +102,12 @@ Xx={ } Mx={ ocn_id_char: 'o', + note: 'note_', + note_ref: 'noteref_', + note_astx: 'note_astx_', + note_ref_astx: 'noteref_astx_', + note_plus: 'note_plus_', + note_ref_plus: 'noteref_plus_', meta_o: '〔@', meta_c: '〕', lv_o_0: 0, lv_o_1: 1, diff --git a/lib/sisu/v5/html_format.rb b/lib/sisu/v5/html_format.rb index e0be4f8a..a933d091 100644 --- a/lib/sisu/v5/html_format.rb +++ b/lib/sisu/v5/html_format.rb @@ -1248,7 +1248,7 @@ WOK note='' if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end note=$1 - note=note.gsub(/[\n\s]+/m,' ') + note=note.gsub(/[\s]+/m,' ') txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' '). gsub(/ \d+<\/sup> /m,'') end diff --git a/lib/sisu/v5/html_segments.rb b/lib/sisu/v5/html_segments.rb index b710db81..7a368b9d 100644 --- a/lib/sisu/v5/html_segments.rb +++ b/lib/sisu/v5/html_segments.rb @@ -502,7 +502,7 @@ module SiSU_HTML_Seg '


' end if @md.flag_separate_endnotes - dob.obj=dob.obj.gsub(/"\s+href="#_(\d+)">/,%{" href=\"endnotes#{Sfx[:html]}#_\\1">}) #endnote- twice #removed file type + dob.obj=dob.obj.gsub(/"\s+href="#(#{Mx[:note]}\d+)">/,%{" href=\"endnotes#{Sfx[:html]}#\\1">}) #endnote- twice #removed file type end if dob.obj !~/#{@vz.margin_txt_w1}|#{@vz.margin_txt_w2}/ if (dob.is==:heading \ @@ -600,7 +600,7 @@ module SiSU_HTML_Seg @@seg_subtoc_array << subtoc end if @md.flag_auto_endnotes - if (dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ ') #% creation of separate end segment/page of all endnotes referenced back to reference segment - m=/(?:#{Mx[:en_a_o]}[\d*+]+|#{Mx[:en_b_o]}[*+]\d+)\s+(.+?href=")(#-[\d*+]+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi + m=/(?:#{Mx[:en_a_o]}[\d*+]+|#{Mx[:en_b_o]}[*+]\d+)\s+(.+?href=")(##{Mx[:note_ref]}[\d*+]+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi endnote_part_a=note_match_seg[m,1] endnote_part_b=note_match_seg[m,2] txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b } diff --git a/lib/sisu/v5/html_tune.rb b/lib/sisu/v5/html_tune.rb index e9392ca8..84336861 100644 --- a/lib/sisu/v5/html_tune.rb +++ b/lib/sisu/v5/html_tune.rb @@ -256,14 +256,14 @@ module SiSU_HTML_Tune def endnotes_html(dob) unless dob.is ==:code dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, - '  \2  ' + #note- endnote- - '\1\2  \2. \3 \4'). #endnote- note- (careful may have switched) + %{  \\2  } + + %{\\1\\2  \\2. \\3 \\4}). gsub(/(#{Mx[:en_b_o]})([*+]\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - '  \2  ' + #note- endnote- - '\1\2  \2. \3 \4'). #endnote- note- (careful may have switched) + %{  \\2  } + + %{\\1\\2  \\2. \\3 \\4}). gsub(/(#{Mx[:en_a_o]})([*+]+)\s+(.+?)(#{Mx[:en_a_c]})/, - '  \2  ' + #note- endnote- - '\1\2  \2 \3 \4') #endnote- note- (careful may have switched) + %{  \\2  } + + %{\\1\\2  \\2 \\3 \\4}) end dob end diff --git a/lib/sisu/v5/xhtml_epub2_format.rb b/lib/sisu/v5/xhtml_epub2_format.rb index 8dd8a88e..e3b877aa 100644 --- a/lib/sisu/v5/xhtml_epub2_format.rb +++ b/lib/sisu/v5/xhtml_epub2_format.rb @@ -2132,10 +2132,10 @@ output_epub_cont_seg.close note='' if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end note=$1 - note=note.gsub(/[\n\s]+/m,' ') + note=note.gsub(/[\s]+/m,' ') txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' '). - gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,''). - gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,'') #remove + gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,''). + gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,'') #remove end %{<#{tag} class="#{attrib}"> #{txt} #{note} diff --git a/lib/sisu/v5/xhtml_epub2_segments.rb b/lib/sisu/v5/xhtml_epub2_segments.rb index 764fcc17..8612696f 100644 --- a/lib/sisu/v5/xhtml_epub2_segments.rb +++ b/lib/sisu/v5/xhtml_epub2_segments.rb @@ -401,7 +401,7 @@ WOK sto.break end if @md.flag_separate_endnotes # may need to revisit, check - dob.obj=dob.obj.gsub(/"\s+href="#note_ref(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}#note_ref\\1">}) #endnote- twice #removed file type + dob.obj=dob.obj.gsub(/"\s+href="##{Mx[:note_ref]}(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}##{Mx[:note_ref]}\\1">}) #endnote- twice #removed file type end if (dob.is ==:heading \ || dob.is==:heading_insert \ diff --git a/lib/sisu/v5/xhtml_epub2_tune.rb b/lib/sisu/v5/xhtml_epub2_tune.rb index 6ac53c39..82f90366 100644 --- a/lib/sisu/v5/xhtml_epub2_tune.rb +++ b/lib/sisu/v5/xhtml_epub2_tune.rb @@ -298,22 +298,22 @@ module SiSU_XHTML_EPUB2_Tune data.each do |dob| unless dob.is ==:code dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1\\2 #{Mx[:nbsp]}\\2. \\3 \\4}). #endnote- note- (careful may have switched) + %{#{Mx[:nbsp]}#{Mx[:nbsp]}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1\\2 #{Mx[:nbsp]}\\2. \\3 \\4}). #endnote- note- (careful may have switched) gsub(/(#{Mx[:en_b_o]})[*](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{ast}\\2 #{Mx[:nbsp]}#{ast}\\2. \\3 \\4}). #endnote- note- (careful may have switched) + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{ast}\\2 #{Mx[:nbsp]}#{ast}\\2. \\3 \\4}). #endnote- note- (careful may have switched) gsub(/(#{Mx[:en_b_o]})[+](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{pls}\\2 #{Mx[:nbsp]}#{pls}\\2. \\3 \\4}) #endnote- note- (careful may have switched) # double-check there may here be a bug + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{pls}\\2 #{Mx[:nbsp]}#{pls}\\2. \\3 \\4}) #endnote- note- (careful may have switched) # double-check there may here be a bug if dob.obj =~/#{Mx[:en_a_o]}([*+]+)\s+.+?#{Mx[:en_a_c]}/ m=$1.length.to_i dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]})[*]+\s+(.+?)(#{Mx[:en_a_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast*m}#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{ast*m} #{Mx[:nbsp]}#{ast*m} \\2 \\3}). #endnote- note- (careful may have switched) + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast*m}#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{ast*m} #{Mx[:nbsp]}#{ast*m} \\2 \\3}). #endnote- note- (careful may have switched) gsub(/(#{Mx[:en_a_o]})([+]+)\s+(.+?)(#{Mx[:en_a_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls*m}#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{pls*m} #{Mx[:nbsp]}#{pls*m} \\2 \\3}) #endnote- note- (careful may have switched) + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls*m}#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{pls*m} #{Mx[:nbsp]}#{pls*m} \\2 \\3}) #endnote- note- (careful may have switched) end end @tuned_file << dob diff --git a/lib/sisu/v6/constants.rb b/lib/sisu/v6/constants.rb index 390df5a4..e70a2f98 100644 --- a/lib/sisu/v6/constants.rb +++ b/lib/sisu/v6/constants.rb @@ -102,6 +102,12 @@ Xx={ } Mx={ ocn_id_char: 'o', + note: 'note_', + note_ref: 'noteref_', + note_astx: 'note_astx_', + note_ref_astx: 'noteref_astx_', + note_plus: 'note_plus_', + note_ref_plus: 'noteref_plus_', meta_o: '〔@', meta_c: '〕', lv_o_0: 0, lv_o_1: 1, diff --git a/lib/sisu/v6/html_format.rb b/lib/sisu/v6/html_format.rb index ddfaaa70..63271d95 100644 --- a/lib/sisu/v6/html_format.rb +++ b/lib/sisu/v6/html_format.rb @@ -1248,7 +1248,7 @@ WOK note='' if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end note=$1 - note=note.gsub(/[\n\s]+/m,' ') + note=note.gsub(/[\s]+/m,' ') txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' '). gsub(/ \d+<\/sup> /m,'') end diff --git a/lib/sisu/v6/html_segments.rb b/lib/sisu/v6/html_segments.rb index efe37024..0586cdf6 100644 --- a/lib/sisu/v6/html_segments.rb +++ b/lib/sisu/v6/html_segments.rb @@ -502,7 +502,7 @@ module SiSU_HTML_Seg '


' end if @md.flag_separate_endnotes - dob.obj=dob.obj.gsub(/"\s+href="#_(\d+)">/,%{" href=\"endnotes#{Sfx[:html]}#_\\1">}) #endnote- twice #removed file type + dob.obj=dob.obj.gsub(/"\s+href="#(#{Mx[:note]}\d+)">/,%{" href=\"endnotes#{Sfx[:html]}#\\1">}) #endnote- twice #removed file type end if dob.obj !~/#{@vz.margin_txt_w1}|#{@vz.margin_txt_w2}/ if (dob.is==:heading \ @@ -600,7 +600,7 @@ module SiSU_HTML_Seg @@seg_subtoc_array << subtoc end if @md.flag_auto_endnotes - if (dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ ') #% creation of separate end segment/page of all endnotes referenced back to reference segment - m=/(?:#{Mx[:en_a_o]}[\d*+]+|#{Mx[:en_b_o]}[*+]\d+)\s+(.+?href=")(#-[\d*+]+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi + m=/(?:#{Mx[:en_a_o]}[\d*+]+|#{Mx[:en_b_o]}[*+]\d+)\s+(.+?href=")(##{Mx[:note_ref]}[\d*+]+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi endnote_part_a=note_match_seg[m,1] endnote_part_b=note_match_seg[m,2] txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b } diff --git a/lib/sisu/v6/html_tune.rb b/lib/sisu/v6/html_tune.rb index 384a19b0..516deaa5 100644 --- a/lib/sisu/v6/html_tune.rb +++ b/lib/sisu/v6/html_tune.rb @@ -256,14 +256,14 @@ module SiSU_HTML_Tune def endnotes_html(dob) unless dob.is ==:code dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, - '  \2  ' + #note- endnote- - '\1\2  \2. \3 \4'). #endnote- note- (careful may have switched) + %{  \\2  } + + %{\\1\\2  \\2. \\3 \\4}). gsub(/(#{Mx[:en_b_o]})([*+]\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - '  \2  ' + #note- endnote- - '\1\2  \2. \3 \4'). #endnote- note- (careful may have switched) + %{  \\2  } + + %{\\1\\2  \\2. \\3 \\4}). gsub(/(#{Mx[:en_a_o]})([*+]+)\s+(.+?)(#{Mx[:en_a_c]})/, - '  \2  ' + #note- endnote- - '\1\2  \2 \3 \4') #endnote- note- (careful may have switched) + %{  \\2  } + + %{\\1\\2  \\2 \\3 \\4}) end dob end diff --git a/lib/sisu/v6/xhtml_epub2_format.rb b/lib/sisu/v6/xhtml_epub2_format.rb index d5b7e85e..7ae97f95 100644 --- a/lib/sisu/v6/xhtml_epub2_format.rb +++ b/lib/sisu/v6/xhtml_epub2_format.rb @@ -2132,10 +2132,10 @@ output_epub_cont_seg.close note='' if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end note=$1 - note=note.gsub(/[\n\s]+/m,' ') + note=note.gsub(/[\s]+/m,' ') txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' '). - gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,''). - gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,'') #remove + gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,''). + gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,'') #remove end %{<#{tag} class="#{attrib}"> #{txt} #{note} diff --git a/lib/sisu/v6/xhtml_epub2_segments.rb b/lib/sisu/v6/xhtml_epub2_segments.rb index 2be4afd9..d249b0ff 100644 --- a/lib/sisu/v6/xhtml_epub2_segments.rb +++ b/lib/sisu/v6/xhtml_epub2_segments.rb @@ -401,7 +401,7 @@ WOK sto.break end if @md.flag_separate_endnotes # may need to revisit, check - dob.obj=dob.obj.gsub(/"\s+href="#note_ref(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}#note_ref\\1">}) #endnote- twice #removed file type + dob.obj=dob.obj.gsub(/"\s+href="##{Mx[:note_ref]}(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}##{Mx[:note_ref]}\\1">}) #endnote- twice #removed file type end if (dob.is ==:heading \ || dob.is==:heading_insert \ diff --git a/lib/sisu/v6/xhtml_epub2_tune.rb b/lib/sisu/v6/xhtml_epub2_tune.rb index 12f70fcf..fd90ae54 100644 --- a/lib/sisu/v6/xhtml_epub2_tune.rb +++ b/lib/sisu/v6/xhtml_epub2_tune.rb @@ -298,22 +298,22 @@ module SiSU_XHTML_EPUB2_Tune data.each do |dob| unless dob.is ==:code dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1\\2 #{Mx[:nbsp]}\\2. \\3 \\4}). #endnote- note- (careful may have switched) + %{#{Mx[:nbsp]}#{Mx[:nbsp]}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1\\2 #{Mx[:nbsp]}\\2. \\3 \\4}). #endnote- note- (careful may have switched) gsub(/(#{Mx[:en_b_o]})[*](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{ast}\\2 #{Mx[:nbsp]}#{ast}\\2. \\3 \\4}). #endnote- note- (careful may have switched) + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{ast}\\2 #{Mx[:nbsp]}#{ast}\\2. \\3 \\4}). #endnote- note- (careful may have switched) gsub(/(#{Mx[:en_b_o]})[+](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{pls}\\2 #{Mx[:nbsp]}#{pls}\\2. \\3 \\4}) #endnote- note- (careful may have switched) # double-check there may here be a bug + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{pls}\\2 #{Mx[:nbsp]}#{pls}\\2. \\3 \\4}) #endnote- note- (careful may have switched) # double-check there may here be a bug if dob.obj =~/#{Mx[:en_a_o]}([*+]+)\s+.+?#{Mx[:en_a_c]}/ m=$1.length.to_i dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]})[*]+\s+(.+?)(#{Mx[:en_a_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast*m}#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{ast*m} #{Mx[:nbsp]}#{ast*m} \\2 \\3}). #endnote- note- (careful may have switched) + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast*m}#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{ast*m} #{Mx[:nbsp]}#{ast*m} \\2 \\3}). #endnote- note- (careful may have switched) gsub(/(#{Mx[:en_a_o]})([+]+)\s+(.+?)(#{Mx[:en_a_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls*m}#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{pls*m} #{Mx[:nbsp]}#{pls*m} \\2 \\3}) #endnote- note- (careful may have switched) + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls*m}#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{pls*m} #{Mx[:nbsp]}#{pls*m} \\2 \\3}) #endnote- note- (careful may have switched) end end @tuned_file << dob -- cgit v1.2.3