Class: SiSU_TextRepresentation::Alter

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/shared_markup_alt.rb

Instance Method Summary collapse

Constructor Details

#initialize(x) ⇒ Alter

Returns a new instance of Alter.



59
60
61
62
63
64
65
# File 'lib/sisu/shared_markup_alt.rb', line 59

def initialize(x)
  if x.is_a?(String)
    @t_o,@s=nil,x
  else
    @t_o,@s=x,x.obj.dup
  end
end

Instance Method Details

#html_liteObject

test whether eventually can be used in db_import replacing shared_html_lite (search for SiSU_FormatShared)



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/sisu/shared_markup_alt.rb', line 152

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_markupObject

used for digest, define rules, make same as in db clean



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/sisu/shared_markup_alt.rb', line 110

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_spacesObject

dal output tuned



66
67
68
69
70
71
72
73
74
# File 'lib/sisu/shared_markup_alt.rb', line 66

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_markupObject

text form used in sql db search, used for digest, define rules, make same as in db clean



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sisu/shared_markup_alt.rb', line 75

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