rutils 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,341 +1,321 @@
1
1
  module RuTils
2
+ module Gilenson
3
+ end
4
+ end
5
+
6
+ # Это - прямой порт Тыпографицы от pixelapes.
7
+ # Настройки можно регулировать через методы, т.е.
8
+ #
9
+ # typ = RuTils::Gilenson::Obsolete.new('Эти "так называемые" великие деятели')
10
+ # typ.html = false => "false"
11
+ # typ.dash = true => "true"
12
+ # typ.to_html => 'Эти «так называемые» великие деятели'
13
+ # Ни обновляться ни поддерживаться этот модуль более не будет.
14
+ class RuTils::Gilenson::Obsolete
15
+ def initialize(text, *args)
16
+ @_text = text
17
+ @skip_tags = true;
18
+ @p_prefix = "<p class=typo>";
19
+ @p_postfix = "</p>";
20
+ @a_soft = true;
21
+ @indent_a = "images/z.gif width=25 height=1 border=0 alt=\'\' align=top />" # <->
22
+ @indent_b = "images/z.gif width=50 height=1 border=0 alt=\'\' align=top />" # <-->
23
+ @fixed_size = 80 # максимальная ширина
24
+ @ignore = /notypo/ # regex, который игнорируется. Этим надо воспользоваться для обработки pre и code
25
+
26
+ @de_nobr = true;
27
+
28
+ @phonemasks = [[ /([0-9]{4})\-([0-9]{2})\-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/,
29
+ /([0-9]{4})\-([0-9]{2})\-([0-9]{2})/,
30
+ /(\([0-9\+\-]+\)) ?([0-9]{3})\-([0-9]{2})\-([0-9]{2})/,
31
+ /(\([0-9\+\-]+\)) ?([0-9]{2})\-([0-9]{2})\-([0-9]{2})/,
32
+ /(\([0-9\+\-]+\)) ?([0-9]{3})\-([0-9]{2})/,
33
+ /(\([0-9\+\-]+\)) ?([0-9]{2})\-([0-9]{3})/,
34
+ /([0-9]{3})\-([0-9]{2})\-([0-9]{2})/,
35
+ /([0-9]{2})\-([0-9]{2})\-([0-9]{2})/,
36
+ /([0-9]{1})\-([0-9]{2})\-([0-9]{2})/,
37
+ /([0-9]{2})\-([0-9]{3})/,
38
+ /([0-9]+)\-([0-9]+)/,
39
+ ],[
40
+ '<nobr>\1&ndash;\2&ndash;\3&nbsp;\4:\5:\6</nobr>',
41
+ '<nobr>\1&ndash;\2&ndash;\3</nobr>',
42
+ '<nobr>\1&nbsp;\2&ndash;\3&ndash;\4</nobr>',
43
+ '<nobr>\1&nbsp;\2&ndash;\3&ndash;\4</nobr>',
44
+ '<nobr>\1&nbsp;\2&ndash;\3</nobr>',
45
+ '<nobr>\1&nbsp;\2&ndash;\3</nobr>',
46
+ '<nobr>\1&ndash;\2&ndash;\3</nobr>',
47
+ '<nobr>\1&ndash;\2&ndash;\3</nobr>',
48
+ '<nobr>\1&ndash;\2&ndash;\3</nobr>',
49
+ '<nobr>\1&ndash;\2</nobr>',
50
+ '<nobr>\1&ndash;\2</nobr>'
51
+ ]]
52
+
53
+ @glueleft = ['рис.', 'табл.', 'см.', 'им.', 'ул.', 'пер.', 'кв.', 'офис', 'оф.', 'г.']
54
+ @glueright = ['руб.', 'коп.', 'у.е.', 'мин.']
55
+
56
+ @settings = {
57
+ "inches" => true, # преобразовывать дюймы в &quot;
58
+ "laquo" => true, # кавычки-ёлочки
59
+ "farlaquo" => false, # кавычки-ёлочки для фара (знаки "больше-меньше")
60
+ "quotes" => true, # кавычки-английские лапки
61
+ "dash" => true, # короткое тире (150)
62
+ "emdash" => true, # длинное тире двумя минусами (151)
63
+ "(c)" => true,
64
+ "(r)" => true,
65
+ "(tm)" => true,
66
+ "(p)" => true,
67
+ "+-" => true, # спецсимволы, какие - понятно
68
+ "degrees" => true, # знак градуса
69
+ "<-->" => true, # отступы $Indent*
70
+ "dashglue" => true, "wordglue" => true, # приклеивание предлогов и дефисов
71
+ "spacing" => true, # запятые и пробелы, перестановка
72
+ "phones" => true, # обработка телефонов
73
+ "fixed" => false, # подгон под фиксированную ширину
74
+ "html" => false # запрет тагов html
75
+ }
76
+ # irrelevant - indentation with images
77
+ @indent_a = "<!--indent-->"
78
+ @indent_b = "<!--indent-->"
79
+
80
+ @mark_tag = "\xF0\xF0\xF0\xF0" # Подстановочные маркеры тегов
81
+ @mark_ignored = "\201" # Подстановочные маркеры неизменяемых групп
82
+ end
83
+
84
+
85
+ # Proxy unknown method calls as setting switches. Methods with = will set settings, methods without - fetch them
86
+ def method_missing(meth, *args) #:nodoc:
87
+ setting = meth.to_s.gsub(/=$/, '')
88
+ super(meth, *args) unless @settings.has_key?(setting) #this will pop the exception if we have no such setting
89
+
90
+ return @settings[meth.to_s] if setting == meth.to_s
91
+ return (@settings[meth.to_s] = args[0])
92
+ end
93
+
94
+
95
+ def to_html(no_paragraph = false)
96
+
97
+ text = @_text
98
+
99
+ # -2. игнорируем ещё регексп
100
+ ignored = []
101
+
2
102
 
3
- module Gilenson
4
- module StringFormatting
5
- # Форматирует строку с помощью Gilenson. Всп дополнительные опции передаются форматтеру.
6
- def gilensize(*args)
7
- args = {} unless args.is_a?(Hash)
8
- RuTils::Gilenson::Formatter.new(self, *args).to_html
9
- end
103
+ text.scan(@ignore) do |result|
104
+ ignored << result
10
105
  end
11
- end
12
-
13
- # Это - прямой порт Тыпографицы от pixelapes.
14
- # Настройки можно регулировать через методы, т.е.
15
- #
16
- # typ = Typografica.new('Эти "так называемые" великие деятели')
17
- # typ.html = false => "false"
18
- # typ.dash = true => "true"
19
- # typ.to_html => 'Эти &laquo;так называемые&raquo; великие деятели'
20
- class Gilenson::Typografica
21
- def initialize(text, *args)
22
- @_text = text
23
- @skip_tags = true;
24
- @p_prefix = "<p class=typo>";
25
- @p_postfix = "</p>";
26
- @a_soft = true;
27
- @indent_a = "images/z.gif width=25 height=1 border=0 alt=\'\' align=top />" # <->
28
- @indent_b = "images/z.gif width=50 height=1 border=0 alt=\'\' align=top />" # <-->
29
- @fixed_size = 80 # максимальная ширина
30
- @ignore = /notypo/ # regex, который игнорируется. Этим надо воспользоваться для обработки pre и code
31
-
32
- @de_nobr = true;
33
-
34
- @phonemasks = [[ /([0-9]{4})\-([0-9]{2})\-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/,
35
- /([0-9]{4})\-([0-9]{2})\-([0-9]{2})/,
36
- /(\([0-9\+\-]+\)) ?([0-9]{3})\-([0-9]{2})\-([0-9]{2})/,
37
- /(\([0-9\+\-]+\)) ?([0-9]{2})\-([0-9]{2})\-([0-9]{2})/,
38
- /(\([0-9\+\-]+\)) ?([0-9]{3})\-([0-9]{2})/,
39
- /(\([0-9\+\-]+\)) ?([0-9]{2})\-([0-9]{3})/,
40
- /([0-9]{3})\-([0-9]{2})\-([0-9]{2})/,
41
- /([0-9]{2})\-([0-9]{2})\-([0-9]{2})/,
42
- /([0-9]{1})\-([0-9]{2})\-([0-9]{2})/,
43
- /([0-9]{2})\-([0-9]{3})/,
44
- /([0-9]+)\-([0-9]+)/,
45
- ],[
46
- '<nobr>\1&ndash;\2&ndash;\3&nbsp;\4:\5:\6</nobr>',
47
- '<nobr>\1&ndash;\2&ndash;\3</nobr>',
48
- '<nobr>\1&nbsp;\2&ndash;\3&ndash;\4</nobr>',
49
- '<nobr>\1&nbsp;\2&ndash;\3&ndash;\4</nobr>',
50
- '<nobr>\1&nbsp;\2&ndash;\3</nobr>',
51
- '<nobr>\1&nbsp;\2&ndash;\3</nobr>',
52
- '<nobr>\1&ndash;\2&ndash;\3</nobr>',
53
- '<nobr>\1&ndash;\2&ndash;\3</nobr>',
54
- '<nobr>\1&ndash;\2&ndash;\3</nobr>',
55
- '<nobr>\1&ndash;\2</nobr>',
56
- '<nobr>\1&ndash;\2</nobr>'
57
- ]]
58
-
59
- @glueleft = ['рис.', 'табл.', 'см.', 'им.', 'ул.', 'пер.', 'кв.', 'офис', 'оф.', 'г.']
60
- @glueright = ['руб.', 'коп.', 'у.е.', 'мин.']
61
-
62
- @settings = {
63
- "inches" => true, # преобразовывать дюймы в &quot;
64
- "laquo" => true, # кавычки-ёлочки
65
- "farlaquo" => false, # кавычки-ёлочки для фара (знаки "больше-меньше")
66
- "quotes" => true, # кавычки-английские лапки
67
- "dash" => true, # короткое тире (150)
68
- "emdash" => true, # длинное тире двумя минусами (151)
69
- "(c)" => true,
70
- "(r)" => true,
71
- "(tm)" => true,
72
- "(p)" => true,
73
- "+-" => true, # спецсимволы, какие - понятно
74
- "degrees" => true, # знак градуса
75
- "<-->" => true, # отступы $Indent*
76
- "dashglue" => true, "wordglue" => true, # приклеивание предлогов и дефисов
77
- "spacing" => true, # запятые и пробелы, перестановка
78
- "phones" => true, # обработка телефонов
79
- "fixed" => false, # подгон под фиксированную ширину
80
- "html" => false # запрет тагов html
81
- }
82
- # irrelevant - indentation with images
83
- @indent_a = "<!--indent-->"
84
- @indent_b = "<!--indent-->"
85
-
86
- @mark_tag = "\xF0\xF0\xF0\xF0" # Подстановочные маркеры тегов
87
- @mark_ignored = "\201" # Подстановочные маркеры неизменяемых групп
88
- end
89
-
90
-
91
- # Proxy unknown method calls as setting switches. Methods with = will set settings, methods without - fetch them
92
- def method_missing(meth, *args) #:nodoc:
93
- setting = meth.to_s.gsub(/=$/, '')
94
- super(meth, *args) unless @settings.has_key?(setting) #this will pop the exception if we have no such setting
95
-
96
- return @settings[meth.to_s] if setting == meth.to_s
97
- return (@settings[meth.to_s] = args[0])
98
- end
99
-
100
-
101
- def to_html(no_paragraph = false)
102
-
103
- text = @_text
104
-
105
- # -2. игнорируем ещё регексп
106
- ignored = []
107
-
108
-
109
- text.scan(@ignore) do |result|
110
- ignored << result
111
- end
112
-
113
- text.gsub!(@ignore, @mark_ignored) # маркер игнора
114
-
115
- # -1. запрет тагов html
116
- text.gsub!(/&/, '&amp;') if @settings["html"]
117
-
118
-
119
- # 0. Вырезаем таги
120
- # проблема на самом деле в том, на что похожи таги.
121
- # вариант 1, простой (закрывающий таг) </abcz>
122
- # вариант 2, простой (просто таг) <abcz>
123
- # вариант 3, посложней <abcz href="abcz">
124
- # вариант 4, простой (просто таг) <abcz />
125
- # вариант 5, вакка \xA2\xA2...== нафиг нафиг
126
- # самый сложный вариант - это когда в параметре тага встречается вдруг символ ">"
127
- # вот он: <abcz href="abcz>">
128
- # как работает вырезание? введём спецсимвол. Да, да, спецсимвол.
129
- # нам он ещё вопьётся =)
130
- # заменим все таги на спец.символ, запоминая одновременно их в массив.
131
- # и будем верить, что спец.символы в дикой природе не встречаются.
132
-
133
- tags = []
134
- if (@skip_tags)
135
- # re = /<\/?[a-z0-9]+("+ # имя тага
136
- # "\s+("+ # повторяющая конструкция: хотя бы один разделитель и тельце
137
- # "[a-z]+("+ # атрибут из букв, за которым может стоять знак равенства и потом
138
- # "=((\'[^\']*\')|(\"[^\"]*\")|([0-9@\-_a-z:\/?&=\.]+))"+ #
139
- # ")?"+
140
- # ")?"+
141
- # ")*\/?>|\xA2\xA2[^\n]*?==/i;
142
-
143
- # re = /<\/?[a-z0-9]+(\s+([a-z]+(=((\'[^\']*\')|(\"[^\"]*\")|([0-9@\-_a-z:\/?&=\.]+)))?)?)*\/?>|\xA2\xA2[^\n]*?==/ui
144
-
145
- re = /(<\/?[a-z0-9]+(\s+([a-z]+(=((\'[^\']*\')|(\"[^\"]*\")|([0-9@\-_a-z:\/?&=\.]+)))?)?)*\/?>)/ui
106
+
107
+ text.gsub!(@ignore, @mark_ignored) # маркер игнора
108
+
109
+ # -1. запрет тагов html
110
+ text.gsub!(/&/, '&amp;') if @settings["html"]
111
+
112
+
113
+ # 0. Вырезаем таги
114
+ # проблема на самом деле в том, на что похожи таги.
115
+ # вариант 1, простой (закрывающий таг) </abcz>
116
+ # вариант 2, простой (просто таг) <abcz>
117
+ # вариант 3, посложней <abcz href="abcz">
118
+ # вариант 4, простой (просто таг) <abcz />
119
+ # вариант 5, вакка \xA2\xA2...== нафиг нафиг
120
+ # самый сложный вариант - это когда в параметре тага встречается вдруг символ ">"
121
+ # вот он: <abcz href="abcz>">
122
+ # как работает вырезание? введём спецсимвол. Да, да, спецсимвол.
123
+ # нам он ещё вопьётся =)
124
+ # заменим все таги на спец.символ, запоминая одновременно их в массив.
125
+ # и будем верить, что спец.символы в дикой природе не встречаются.
126
+
127
+ tags = []
128
+ if (@skip_tags)
129
+ # re = /<\/?[a-z0-9]+("+ # имя тага
130
+ # "\s+("+ # повторяющая конструкция: хотя бы один разделитель и тельце
131
+ # "[a-z]+("+ # атрибут из букв, за которым может стоять знак равенства и потом
132
+ # "=((\'[^\']*\')|(\"[^\"]*\")|([0-9@\-_a-z:\/?&=\.]+))"+ #
133
+ # ")?"+
134
+ # ")?"+
135
+ # ")*\/?>|\xA2\xA2[^\n]*?==/i;
136
+
137
+ # re = /<\/?[a-z0-9]+(\s+([a-z]+(=((\'[^\']*\')|(\"[^\"]*\")|([0-9@\-_a-z:\/?&=\.]+)))?)?)*\/?>|\xA2\xA2[^\n]*?==/ui
138
+
139
+ re = /(<\/?[a-z0-9]+(\s+([a-z]+(=((\'[^\']*\')|(\"[^\"]*\")|([0-9@\-_a-z:\/?&=\.]+)))?)?)*\/?>)/ui
146
140
 
147
141
  # по-хорошему атрибуты тоже нужно типографить. Или не нужно? бугага...
148
142
 
149
- tags = text.scan(re).map{|tag| tag[0] }
150
- # match = "&lt;" + match if @settings["html"]
151
- text.gsub!(re, @mark_tag) #маркер тега, мы используем Invalid UTF-sequence для него
152
-
153
- # puts "matched #{tags.size} tags"
154
- end
155
-
156
- # 1. Запятые и пробелы
157
- if @settings["spacing"]
158
- text.gsub!( /(\s*)([,]*)/sui, '\2\1');
159
- text.gsub!( /(\s*)([\.?!]*)(\s*[ЁА-ЯA-Z])/su, '\2\1\3');
160
- end
161
-
162
- # 2. Разбиение на строки длиной не более ХХ символов
163
- # --- для ваки не портировано ---
164
- # --- для ваки не портировано ---
165
-
166
- # 3. Спецсимволы
167
- # 0. дюймы с цифрами
168
- text.gsub!(/\s([0-9]{1,2}([\.,][0-9]{1,2})?)\"/ui, ' \1&quot;') if @settings["inches"]
169
-
170
- # 1. лапки
171
- if (@settings["quotes"])
172
- text.gsub!( /\"\"/ui, "&quot;&quot;")
173
- text.gsub!( /\"\.\"/ui, "&quot;.&quot;")
174
- _text = '""';
175
- while _text != text do
176
- _text = text
177
- text.gsub!( /(^|\s|\201|\xF0\xF0\xF0\xF0|>)\"([0-9A-Za-z\'\!\s\.\?\,\-\&\;\:\_\xF0\xF0\xF0\xF0\201]+(\"|&#148;))/ui, '\1&#147;\2')
178
- #this doesnt work in-place. somehow.
179
- 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&#148;')
180
- end
181
- end
143
+ tags = text.scan(re).map{|tag| tag[0] }
144
+ # match = "&lt;" + match if @settings["html"]
145
+ text.gsub!(re, @mark_tag) #маркер тега, мы используем Invalid UTF-sequence для него
146
+
147
+ # puts "matched #{tags.size} tags"
148
+ end
182
149
 
183
- # 2. ёлочки
184
- if @settings["laquo"]
185
- text.gsub!( /\"\"/ui, "&quot;&quot;");
186
- text.gsub!( /(^|\s|\201|\xF0\xF0\xF0\xF0|>|\()\"((\201|\xF0\xF0\xF0\xF0)*[~0-9ёЁA-Za-zА-Яа-я\-:\/\.])/ui, "\\1&laquo;\\2");
187
- # nb: wacko only regexp follows:
188
- text.gsub!( /(^|\s|\201|\xF0\xF0\xF0\xF0|>|\()\"((\201|\xF0\xF0\xF0\xF0|\/&nbsp;|\/|\!)*[~0-9ёЁA-Za-zА-Яа-я\-:\/\.])/ui, "\\1&laquo;\\2")
189
- _text = "\"\"";
190
- while (_text != text) do
191
- _text = text;
192
- text.gsub!( /(\&laquo\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0)*)\"/sui, "\\1&raquo;")
193
- # nb: wacko only regexps follows:
194
- text.gsub!( /(\&laquo\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0)*\?(\201|\xF0\xF0\xF0\xF0)*)\"/sui, "\\1&raquo;")
195
- text.gsub!( /(\&laquo\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0|\/|\!)*)\"/sui, "\\1&raquo;")
196
- end
197
- end
198
-
199
-
200
- # 2b. одновременно ёлочки и лапки
201
- if (@settings["quotes"] && (@settings["laquo"] or @settings["farlaquo"]))
202
- text.gsub!(/(\&\#147\;(([A-Za-z0-9'!\.?,\-&;:]|\s|\xF0\xF0\xF0\xF0|\201)*)&laquo;(.*)&raquo;)&raquo;/ui,"\\1&#148;");
203
- end
204
-
205
-
206
- # 3. тире
207
- if (@settings["dash"])
208
- text.gsub!( /(\s|;)\-(\s)/ui, "\\1&ndash;\\2")
209
- end
210
-
211
-
212
- # 3a. тире длинное
213
- if (@settings["emdash"])
214
- text.gsub!( /(\s|;)\-\-(\s)/ui, "\\1&mdash;\\2")
215
- # 4. (с)
216
- text.gsub!(/\([сСcC]\)((?=\w)|(?=\s[0-9]+))/u, "&copy;") if @settings["(c)"]
217
- # 4a. (r)
218
- text.gsub!( /\(r\)/ui, "<sup>&#174;</sup>") if @settings["(r)"]
219
-
220
- # 4b. (tm)
221
- text.gsub!( /\(tm\)|\(тм\)/ui, "&#153;") if @settings["(tm)"]
222
- # 4c. (p)
223
- text.gsub!( /\(p\)/ui, "&#167;") if @settings["(p)"]
224
- end
225
-
226
-
227
- # 5. +/-
228
- text.gsub!(/[^+]\+\-/ui, "&#177;") if @settings["+-"]
229
-
230
-
231
- # 5a. 12^C
232
- if @settings["degrees"]
233
- text.gsub!( /-([0-9])+\^([FCС])/, "&ndash;\\1&#176\\2")
234
- text.gsub!( /\+([0-9])+\^([FCС])/, "+\\1&#176\\2")
235
- text.gsub!( /\^([FCС])/, "&#176\\1")
236
- end
237
-
238
-
239
- # 6. телефоны
240
- if @settings["phones"]
241
- @phonemasks[0].each_with_index do |v, i|
242
- text.gsub!(v, @phonemasks[1][i])
243
- end
244
- end
245
-
246
-
247
- # 7. Короткие слова и &nbsp;
248
- if (@settings["wordglue"])
249
-
250
- text = " " + text + " ";
251
- _text = " " + text + " ";
252
- until _text == text
253
- _text = text
254
- text.gsub!( /(\s+)([a-zа-яА-Я]{1,2})(\s+)([^\\s$])/ui, '\1\2&nbsp;\4')
255
- text.gsub!( /(\s+)([a-zа-яА-Я]{3})(\s+)([^\\s$])/ui, '\1\2&nbsp;\4')
256
- end
257
-
258
- for i in @glueleft
259
- text.gsub!( /(\s)(#{i})(\s+)/sui, '\1\2&nbsp;')
260
- end
261
-
262
- for i in @glueright
263
- text.gsub!( /(\s)(#{i})(\s+)/sui, '&nbsp;\2\3')
264
- end
265
- end
150
+ # 1. Запятые и пробелы
151
+ if @settings["spacing"]
152
+ text.gsub!( /(\s*)([,]*)/sui, '\2\1');
153
+ text.gsub!( /(\s*)([\.?!]*)(\s*[ЁА-ЯA-Z])/su, '\2\1\3');
154
+ end
266
155
 
156
+ # 2. Разбиение на строки длиной не более ХХ символов
157
+ # --- для ваки не портировано ---
158
+ # --- для ваки не портировано ---
159
+
160
+ # 3. Спецсимволы
161
+ # 0. дюймы с цифрами
162
+ text.gsub!(/\s([0-9]{1,2}([\.,][0-9]{1,2})?)\"/ui, ' \1&quot;') if @settings["inches"]
163
+
164
+ # 1. лапки
165
+ if (@settings["quotes"])
166
+ text.gsub!( /\"\"/ui, "&quot;&quot;")
167
+ text.gsub!( /\"\.\"/ui, "&quot;.&quot;")
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]+(\"|&#148;))/ui, '\1&#147;\2')
172
+ #this doesnt work in-place. somehow.
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&#148;')
174
+ end
175
+ end
267
176
 
177
+ # 2. ёлочки
178
+ if @settings["laquo"]
179
+ text.gsub!( /\"\"/ui, "&quot;&quot;");
180
+ text.gsub!( /(^|\s|\201|\xF0\xF0\xF0\xF0|>|\()\"((\201|\xF0\xF0\xF0\xF0)*[~0-9ёЁA-Za-zА-Яа-я\-:\/\.])/ui, "\\1&laquo;\\2");
181
+ # nb: wacko only regexp follows:
182
+ text.gsub!( /(^|\s|\201|\xF0\xF0\xF0\xF0|>|\()\"((\201|\xF0\xF0\xF0\xF0|\/&nbsp;|\/|\!)*[~0-9ёЁA-Za-zА-Яа-я\-:\/\.])/ui, "\\1&laquo;\\2")
183
+ _text = "\"\"";
184
+ while (_text != text) do
185
+ _text = text;
186
+ text.gsub!( /(\&laquo\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0)*)\"/sui, "\\1&raquo;")
187
+ # nb: wacko only regexps follows:
188
+ text.gsub!( /(\&laquo\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0)*\?(\201|\xF0\xF0\xF0\xF0)*)\"/sui, "\\1&raquo;")
189
+ text.gsub!( /(\&laquo\;([^\"]*)[ёЁA-Za-zА-Яа-я0-9\.\-:\/](\201|\xF0\xF0\xF0\xF0|\/|\!)*)\"/sui, "\\1&raquo;")
190
+ end
191
+ end
268
192
 
269
- # 8. Склейка ласт. Тьфу! дефисов.
270
- text.gsub!( /([a-zа-яА-Я0-9]+(\-[a-zа-яА-Я0-9]+)+)/ui, '<nobr>\1</nobr>') if @settings["dashglue"]
271
193
 
194
+ # 2b. одновременно ёлочки и лапки
195
+ if (@settings["quotes"] && (@settings["laquo"] or @settings["farlaquo"]))
196
+ text.gsub!(/(\&\#147;\;(([A-Za-z0-9'!\.?,\-&;:]|\s|\xF0\xF0\xF0\xF0|\201)*)&laquo;(.*)&raquo;)&raquo;/ui,"\\1&#148;");
197
+ end
272
198
 
273
- # 9. Макросы
274
199
 
200
+ # 3. тире
201
+ if (@settings["dash"])
202
+ text.gsub!( /(\s|;)\-(\s)/ui, "\\1&ndash;\\2")
203
+ end
275
204
 
276
205
 
277
- # 10. Переводы строк
278
- # --- для ваки не портировано ---
279
- # --- для ваки не портировано ---
206
+ # 3a. тире длинное
207
+ if (@settings["emdash"])
208
+ text.gsub!( /(\s|;)\-\-(\s)/ui, "\\1&mdash;\\2")
209
+ # 4. (с)
210
+ text.gsub!(/\([сСcC]\)((?=\w)|(?=\s[0-9]+))/u, "&copy;") if @settings["(c)"]
211
+ # 4a. (r)
212
+ text.gsub!( /\(r\)/ui, "<sup>&#174;</sup>") if @settings["(r)"]
280
213
 
214
+ # 4b. (tm)
215
+ text.gsub!( /\(tm\)|\(тм\)/ui, "&#153;") if @settings["(tm)"]
216
+ # 4c. (p)
217
+ text.gsub!( /\(p\)/ui, "&#167;") if @settings["(p)"]
218
+ end
281
219
 
282
- # БЕСКОНЕЧНОСТЬ. Вставляем таги обратно.
283
- # if (@skip_tags)
284
- # text = text.split("\xF0\xF0\xF0\xF0").join
285
- #
286
220
 
287
- tags.each do |tag|
288
- text.sub!(@mark_tag, tag)
289
- end
290
-
291
- # i = 0
292
- # text.gsub!(@mark_tag) {
293
- # i + 1
294
- # tags[i-1]
295
- # }
221
+ # 5. +/-
222
+ text.gsub!(/[^+]\+\-/ui, "&#177;") if @settings["+-"]
296
223
 
297
- # text = text.split("\xF0\xF0\xF0\xF0")
298
- #puts "reinserted #{i} tags"
299
- #
300
- # end
301
-
302
224
 
303
- #ext.gsub!("a", '')
304
- # raise "Text still has tag markers!" if text.include?("a")
225
+ # 5a. 12^C
226
+ if @settings["degrees"]
227
+ text.gsub!( /-([0-9])+\^([FCС])/, "&ndash;\\1&#176;\\2")
228
+ text.gsub!( /\+([0-9])+\^([FCС])/, "+\\1&#176;\\2")
229
+ text.gsub!( /\^([FCС])/, "&#176;\\1")
230
+ end
231
+
232
+
233
+ # 6. телефоны
234
+ if @settings["phones"]
235
+ @phonemasks[0].each_with_index do |v, i|
236
+ text.gsub!(v, @phonemasks[1][i])
237
+ end
238
+ end
305
239
 
306
- # БЕСКОНЕЧНОСТЬ-2. вставляем ещё сигнорированный регексп
307
- #
308
- # if @ignore
309
- # ignored.each { | tag | text.sub!(@mark_ignored, tag) }
310
- # end
311
240
 
312
- # raise "Text still has ignored markers!" if text.include?("\201")
241
+ # 7. Короткие слова и &nbsp;
242
+ if (@settings["wordglue"])
313
243
 
314
- # БОНУС: прокручивание ссылок через A(...)
315
- # --- для ваки не портировано ---
316
- # --- для ваки не портировано ---
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&nbsp;\4')
249
+ text.gsub!( /(\s+)([a-zа-яА-Я]{3})(\s+)([^\\s$])/ui, '\1\2&nbsp;\4')
250
+ end
251
+
252
+ for i in @glueleft
253
+ text.gsub!( /(\s)(#{i})(\s+)/sui, '\1\2&nbsp;')
254
+ end
255
+
256
+ for i in @glueright
257
+ text.gsub!( /(\s)(#{i})(\s+)/sui, '&nbsp;\2\3')
258
+ end
259
+ end
317
260
 
318
- # фуф, закончили.
319
- # text.gsub!(/<nobr>/, "<span class=\"nobr\">").gsub(/<\/nobr>/, "</span>") if (@de_nobr)
320
261
 
321
- # text.gsub!(/<nobr>/, "<span class=\"nobr\">").gsub(/<\/nobr>/, "</span>") if (@de_nobr)
322
262
 
323
- text.gsub(/(\s)+$/, "").gsub(/^(\s)+/, "")
263
+ # 8. Склейка ласт. Тьфу! дефисов.
264
+ text.gsub!( /([a-zа-яА-Я0-9]+(\-[a-zа-яА-Я0-9]+)+)/ui, '<nobr>\1</nobr>') if @settings["dashglue"]
324
265
 
325
- end
326
266
 
327
- private
267
+ # 9. Макросы
328
268
 
329
- end
330
269
 
331
- end #end RuTils
332
270
 
333
- # Вгружаем этот форматтер если уже не загружен наш новый
334
- unless defined?(RuTils::Gilenson::Formatter)
335
- class RuTils::Gilenson::Formatter < RuTils::Gilenson::Typografica
271
+ # 10. Переводы строк
272
+ # --- для ваки не портировано ---
273
+ # --- для ваки не портировано ---
274
+
275
+
276
+ # БЕСКОНЕЧНОСТЬ. Вставляем таги обратно.
277
+ # if (@skip_tags)
278
+ # text = text.split("\xF0\xF0\xF0\xF0").join
279
+ #
280
+
281
+ tags.each do |tag|
282
+ text.sub!(@mark_tag, tag)
283
+ end
284
+
285
+ # i = 0
286
+ # text.gsub!(@mark_tag) {
287
+ # i + 1
288
+ # tags[i-1]
289
+ # }
290
+
291
+ # text = text.split("\xF0\xF0\xF0\xF0")
292
+ #puts "reinserted #{i} tags"
293
+ #
294
+ # end
295
+
296
+
297
+ #ext.gsub!("a", '')
298
+ # raise "Text still has tag markers!" if text.include?("a")
299
+
300
+ # БЕСКОНЕЧНОСТЬ-2. вставляем ещё сигнорированный регексп
301
+ #
302
+ # if @ignore
303
+ # ignored.each { | tag | text.sub!(@mark_ignored, tag) }
304
+ # end
305
+
306
+ # raise "Text still has ignored markers!" if text.include?("\201")
307
+
308
+ # БОНУС: прокручивание ссылок через A(...)
309
+ # --- для ваки не портировано ---
310
+ # --- для ваки не портировано ---
311
+
312
+ # фуф, закончили.
313
+ # text.gsub!(/<nobr>/, "<span class=\"nobr\">").gsub(/<\/nobr>/, "</span>") if (@de_nobr)
314
+
315
+ # text.gsub!(/<nobr>/, "<span class=\"nobr\">").gsub(/<\/nobr>/, "</span>") if (@de_nobr)
316
+
317
+ text.gsub(/(\s)+$/, "").gsub(/^(\s)+/, "")
318
+
336
319
  end
337
- end
338
320
 
339
- class Object::String
340
- include RuTils::Gilenson::StringFormatting
341
321
  end