95: def to_html(no_paragraph = false)
96:
97: text = @_text
98:
99:
100: ignored = []
101:
102:
103: text.scan(@ignore) do |result|
104: ignored << result
105: end
106:
107: text.gsub!(@ignore, @mark_ignored)
108:
109:
110: text.gsub!(/&/, '&') if @settings["html"]
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127: tags = []
128: if (@skip_tags)
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139: re = /(<\/?[a-z0-9]+(\s+([a-z]+(=((\'[^\']*\')|(\"[^\"]*\")|([0-9@\-_a-z:\/?&=\.]+)))?)?)*\/?>)/ui
140:
141:
142:
143: tags = text.scan(re).map{|tag| tag[0] }
144:
145: text.gsub!(re, @mark_tag)
146:
147:
148: end
149:
150:
151: if @settings["spacing"]
152: text.gsub!( /(\s*)([,]*)/sui, '\2\1');
153: text.gsub!( /(\s*)([\.?!]*)(\s*[ЁА-ЯA-Z])/su, '\2\1\3');
154: end
155:
156:
157:
158:
159:
160:
161:
162: text.gsub!(/\s([0-9]{1,2}([\.,][0-9]{1,2})?)\"/ui, ' \1"') if @settings["inches"]
163:
164:
165: if (@settings["quotes"])
166: text.gsub!( /\"\"/ui, """")
167: text.gsub!( /\"\.\"/ui, ""."")
168: _text = '""';
169: while _text != text do
170: _text = text
171: text.gsub!( /(^|\s|\201|\xF0\xF0\xF0\xF0|>)\"([0-9A-Za-z\'\!\s\.\?\,\-\&\;\:\_\xF0\xF0\xF0\xF0\201]+(\"|”))/ui, '\1“\2')
172:
173: text = text.gsub( /(\&\#147\;([A-Za-z0-9\'\!\s\.\?\,\-\&\;\:\xF0\xF0\xF0\xF0\201\_]*).*[A-Za-z0-9][\xF0\xF0\xF0\xF0\201\?\.\!\,]*)\"/ui, '\1”')
174: end
175: end
176:
177:
178: if @settings["laquo"]
179: text.gsub!( /\"\"/ui, """");
180: text.gsub!( /(^|\s|\201|\xF0\xF0\xF0\xF0|>|\()\"((\201|\xF0\xF0\xF0\xF0)*[~0-9ёЁA-Za-zА-Яа-я\-:\/\.])/ui, "\\1«\\2");
181:
182: text.gsub!( /(^|\s|\201|\xF0\xF0\xF0\xF0|>|\()\"((\201|\xF0\xF0\xF0\xF0|\/ |\/|\!)*[~0-9ёЁA-Za-zА-Яа-я\-:\/\.])/ui, "\\1«\\2")
183: _text = "\"\"";
184: while (_text != text) do
185: _text = text;
186: text.gsub!( /(\«\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0)*)\"/sui, "\\1»")
187:
188: text.gsub!( /(\«\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0)*\?(\201|\xF0\xF0\xF0\xF0)*)\"/sui, "\\1»")
189: text.gsub!( /(\«\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0|\/|\!)*)\"/sui, "\\1»")
190: end
191: end
192:
193:
194:
195: if (@settings["quotes"] && (@settings["laquo"] or @settings["farlaquo"]))
196: text.gsub!(/(\&\#147;\;(([A-Za-z0-9'!\.?,\-&;:]|\s|\xF0\xF0\xF0\xF0|\201)*)«(.*)»)»/ui,"\\1”");
197: end
198:
199:
200:
201: if (@settings["dash"])
202: text.gsub!( /(\s|;)\-(\s)/ui, "\\1–\\2")
203: end
204:
205:
206:
207: if (@settings["emdash"])
208: text.gsub!( /(\s|;)\-\-(\s)/ui, "\\1—\\2")
209:
210: text.gsub!(/\([сСcC]\)((?=\w)|(?=\s[0-9]+))/u, "©") if @settings["(c)"]
211:
212: text.gsub!( /\(r\)/ui, "<sup>®</sup>") if @settings["(r)"]
213:
214:
215: text.gsub!( /\(tm\)|\(тм\)/ui, "™") if @settings["(tm)"]
216:
217: text.gsub!( /\(p\)/ui, "§") if @settings["(p)"]
218: end
219:
220:
221:
222: text.gsub!(/[^+]\+\-/ui, "±") if @settings["+-"]
223:
224:
225:
226: if @settings["degrees"]
227: text.gsub!( /-([0-9])+\^([FCС])/, "–\\1°\\2")
228: text.gsub!( /\+([0-9])+\^([FCС])/, "+\\1°\\2")
229: text.gsub!( /\^([FCС])/, "°\\1")
230: end
231:
232:
233:
234: if @settings["phones"]
235: @phonemasks[0].each_with_index do |v, i|
236: text.gsub!(v, @phonemasks[1][i])
237: end
238: end
239:
240:
241:
242: if (@settings["wordglue"])
243:
244: text = " " + text + " ";
245: _text = " " + text + " ";
246: until _text == text
247: _text = text
248: text.gsub!( /(\s+)([a-zа-яА-Я]{1,2})(\s+)([^\\s$])/ui, '\1\2 \4')
249: text.gsub!( /(\s+)([a-zа-яА-Я]{3})(\s+)([^\\s$])/ui, '\1\2 \4')
250: end
251:
252: for i in @glueleft
253: text.gsub!( /(\s)(#{i})(\s+)/sui, '\1\2 ')
254: end
255:
256: for i in @glueright
257: text.gsub!( /(\s)(#{i})(\s+)/sui, ' \2\3')
258: end
259: end
260:
261:
262:
263:
264: text.gsub!( /([a-zа-яА-Я0-9]+(\-[a-zа-яА-Я0-9]+)+)/ui, '<nobr>\1</nobr>') if @settings["dashglue"]
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281: tags.each do |tag|
282: text.sub!(@mark_tag, tag)
283: end
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317: text.gsub(/(\s)+$/, "").gsub(/^(\s)+/, "")
318:
319: end