class SiSU_TextRepresentation::Alter

Public Class Methods

new(x) click to toggle source
# File lib/sisu/shared_markup_alt.rb, line 57
def initialize(x)
  if x.is_a?(String)
    @t_o,@s=nil,x
  else
    @t_o,@s=x,x.obj.dup
  end
end

Public Instance Methods

html_lite() click to toggle source
# File lib/sisu/shared_markup_alt.rb, line 150
def html_lite #test whether eventually can be used in db_import replacing shared_html_lite (search for SiSU_FormatShared)
  if @t_o
    @s=@s.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'<b>\1</b>').
      gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'<i>\1</i>').
      gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'<u>\1</u>').
      gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"\1"').
      gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'+{\1}+').
      gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strke_c]}/,'-{\1}-').
      gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'<sup>\1</sup>').
      gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'<sub>\1</sub>').
      gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~')
    if @t_o.is !=:code
      if @s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/
        wm=@s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)|\S+/)
        words=urls(wm)
        @s=@s.gsub(/.+/m,words)
      end
      @s=@s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;').
        gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;').
        gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'<a href="\1" target="_top">\1</a>'). #http ftp matches escaped, no decoration
        gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1<a href="\2" target="_top">\2</a>\3'). #special case \{ e.g. \}http://url
        gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@url_brace.xml_open}<a href="\\1" target="_top">\\1</a>#{@url_brace.xml_close}}) #http ftp matches with decoration
    else
      @s=@s.gsub(/</m,'&lt;').gsub(/>/m,'&gt;')
    end
    if @t_o.is==:paragraph
      if @t_o.bullet_
        @s=@s
      end
      if @t_o.indent > 0
        @s=@s
      end
    end
    if @t_o.is==:heading
      @s=@s
    end
  else
    p __FILE__ << ':' << __LINE__.to_s
  end
  @s
end
semi_revert_markup() click to toggle source
# File lib/sisu/shared_markup_alt.rb, line 108
def semi_revert_markup                                             # used for digest, define rules, make same as in db clean
  if @t_o
    @s=@s.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'*{\1}*').
      gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'/{\1}/').
      gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'_{\1}_').
      gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"{\1}"').
      gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'+{\1}+').
      gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strke_c]}/,'-{\1}-').
      gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'^{\1}^').
      gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,',{\1},').
      gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~').
      gsub(/#{Mx[:en_a_o]}([\d*+]+\s+.+?)#{Mx[:en_a_c]}/,'~{\1}~'). # endnote marker marked up
      gsub(/#{Mx[:en_b_o]}([\d*+]+\s+.+?)#{Mx[:en_b_c]}/,'~[\1]~') # endnote marker marked up
    if @t_o.is==:heading \
    || @t_o.is==:para
      @s=@s.gsub(/ [ ]+/,' ')
      @s=@s.gsub(/(?:#{Mx[:nbsp]})+/,' ')
      if @t_o.is==:heading
        @s=@t_o.lv + '~ ' + @s
      end
      if @t_o.is==:para
        if @t_o.bullet_
          @s='_* ' + @s
        end
        if @t_o.indent.to_i > 0
          @s="_#{@t_o.indent} " + @s
          @s=@s.gsub(/^(_[1-9])\s_\*\s/,'\1* ')
        end
      end
    end
    if @t_o.is==:block \
    || @t_o.is==:group \
    || @t_o.is==:code
      @s=@s.gsub(/#{Mx[:nbsp]}/,' ')
      @s="#{@t_o.is.to_s}{\n\n#{@s}\n\n}#{@t_o.is.to_s}"
      @s=@s.gsub(/(?:#{Mx[:br_nl]}|\n)+/m,"\n\n")
    end
    #dealing with poem and verse calls for change in dal, where start and end verse of poem are marked as such
    @s=@s.strip
  end
  @s
end
strip_clean_of_extra_spaces() click to toggle source
# File lib/sisu/shared_markup_alt.rb, line 64
def strip_clean_of_extra_spaces                                              # dal output tuned
  @s=@s.dup
  @s=@s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') unless @s =~/#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/
  @s=@s.gsub(/ [ ]+/,' ').
    gsub(/^ [ ]+/,'').
    gsub(/ [ ]+$/,'').
    gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2').
    gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2')
end
strip_clean_of_markup() click to toggle source
# File lib/sisu/shared_markup_alt.rb, line 73
def strip_clean_of_markup                                                  # text form used in sql db search, used for digest, define rules, make same as in db clean
  @s=@s.dup                                                                  #% same as db clean -->
  @s=@s.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1').
    gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1').
    gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1').
    gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1').
    gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1').
    gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1').
    gsub(/#{Mx[:fa_superscript_o]}(\d+)#{Mx[:fa_superscript_c]}/,'[\1]').
    gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1').
    gsub(/#{Mx[:fa_hilite_o]}(.+?)#{Mx[:fa_hilite_c]}/,'\1').
    gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~').
    gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,''). # endnote removed
    gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,''). # endnote removed
    gsub(/(?:#{Mx[:nbsp]})+/,' ').
    gsub(/(?:#{Mx[:br_nl]})+/,"\n").
    gsub(/(?:#{Mx[:br_paragraph]})+/,"\n").
    gsub(/(?:#{Mx[:br_line]})+/,"\n").
    gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<').
    gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>').
    gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&').
    gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!').
    gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#').
    gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*').
    gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-').
    gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/').
    gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_').
    gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{').
    gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}').
    gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~').
    gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©').
    gsub(/\s\s+/,' ').
    gsub(/\s\s+/,' ').
    strip
end