motion-kramdown 0.5.0
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.
- checksums.yaml +7 -0
- data/README.md +84 -0
- data/lib/kramdown/compatibility.rb +36 -0
- data/lib/kramdown/converter/base.rb +259 -0
- data/lib/kramdown/converter/html.rb +461 -0
- data/lib/kramdown/converter/kramdown.rb +423 -0
- data/lib/kramdown/converter/latex.rb +600 -0
- data/lib/kramdown/converter/math_engine/itex2mml.rb +39 -0
- data/lib/kramdown/converter/math_engine/mathjax.rb +33 -0
- data/lib/kramdown/converter/math_engine/ritex.rb +38 -0
- data/lib/kramdown/converter/pdf.rb +624 -0
- data/lib/kramdown/converter/remove_html_tags.rb +53 -0
- data/lib/kramdown/converter/syntax_highlighter/coderay.rb +78 -0
- data/lib/kramdown/converter/syntax_highlighter/rouge.rb +37 -0
- data/lib/kramdown/converter/toc.rb +69 -0
- data/lib/kramdown/converter.rb +69 -0
- data/lib/kramdown/document.rb +144 -0
- data/lib/kramdown/element.rb +515 -0
- data/lib/kramdown/error.rb +17 -0
- data/lib/kramdown/options.rb +584 -0
- data/lib/kramdown/parser/base.rb +130 -0
- data/lib/kramdown/parser/gfm.rb +55 -0
- data/lib/kramdown/parser/html.rb +575 -0
- data/lib/kramdown/parser/kramdown/abbreviation.rb +67 -0
- data/lib/kramdown/parser/kramdown/autolink.rb +37 -0
- data/lib/kramdown/parser/kramdown/blank_line.rb +30 -0
- data/lib/kramdown/parser/kramdown/block_boundary.rb +33 -0
- data/lib/kramdown/parser/kramdown/blockquote.rb +39 -0
- data/lib/kramdown/parser/kramdown/codeblock.rb +56 -0
- data/lib/kramdown/parser/kramdown/codespan.rb +44 -0
- data/lib/kramdown/parser/kramdown/emphasis.rb +61 -0
- data/lib/kramdown/parser/kramdown/eob.rb +26 -0
- data/lib/kramdown/parser/kramdown/escaped_chars.rb +25 -0
- data/lib/kramdown/parser/kramdown/extensions.rb +201 -0
- data/lib/kramdown/parser/kramdown/footnote.rb +56 -0
- data/lib/kramdown/parser/kramdown/header.rb +59 -0
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +27 -0
- data/lib/kramdown/parser/kramdown/html.rb +160 -0
- data/lib/kramdown/parser/kramdown/html_entity.rb +33 -0
- data/lib/kramdown/parser/kramdown/line_break.rb +25 -0
- data/lib/kramdown/parser/kramdown/link.rb +139 -0
- data/lib/kramdown/parser/kramdown/list.rb +256 -0
- data/lib/kramdown/parser/kramdown/math.rb +54 -0
- data/lib/kramdown/parser/kramdown/paragraph.rb +54 -0
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +174 -0
- data/lib/kramdown/parser/kramdown/table.rb +171 -0
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +44 -0
- data/lib/kramdown/parser/kramdown.rb +359 -0
- data/lib/kramdown/parser/markdown.rb +56 -0
- data/lib/kramdown/parser.rb +27 -0
- data/lib/kramdown/utils/configurable.rb +44 -0
- data/lib/kramdown/utils/entities.rb +347 -0
- data/lib/kramdown/utils/html.rb +75 -0
- data/lib/kramdown/utils/ordered_hash.rb +87 -0
- data/lib/kramdown/utils/string_scanner.rb +74 -0
- data/lib/kramdown/utils/unidecoder.rb +51 -0
- data/lib/kramdown/utils.rb +58 -0
- data/lib/kramdown/version.rb +15 -0
- data/lib/kramdown.rb +10 -0
- data/lib/motion-kramdown.rb +47 -0
- data/lib/rubymotion/encodings.rb +37 -0
- data/lib/rubymotion/rexml_shim.rb +25 -0
- data/lib/rubymotion/set.rb +1349 -0
- data/lib/rubymotion/version.rb +6 -0
- data/spec/document_tree.rb +48 -0
- data/spec/gfm_to_html.rb +95 -0
- data/spec/helpers/it_behaves_like.rb +27 -0
- data/spec/helpers/option_file.rb +46 -0
- data/spec/helpers/spec_options.rb +37 -0
- data/spec/helpers/tidy.rb +12 -0
- data/spec/html_to_html.rb +40 -0
- data/spec/html_to_kramdown_to_html.rb +46 -0
- data/spec/kramdown_to_xxx.rb +40 -0
- data/spec/test_location.rb +203 -0
- data/spec/test_string_scanner_kramdown.rb +19 -0
- data/spec/text_to_kramdown_to_html.rb +52 -0
- data/spec/text_to_latex.rb +33 -0
- metadata +164 -0
@@ -0,0 +1,347 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
|
10
|
+
module Kramdown
|
11
|
+
|
12
|
+
module Utils
|
13
|
+
|
14
|
+
# Provides convenience methods for handling named and numeric entities.
|
15
|
+
module Entities
|
16
|
+
|
17
|
+
# Represents an entity that has a +code_point+ and +name+.
|
18
|
+
class Entity < Struct.new(:code_point, :name)
|
19
|
+
|
20
|
+
# Return the UTF8 representation of the entity.
|
21
|
+
def char
|
22
|
+
[code_point] ? [code_point].pack('U*') : nil # RM can't use rescue nil
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
# Array of arrays. Each sub-array specifies a code point and the associated name.
|
28
|
+
#
|
29
|
+
# This table is not used directly -- Entity objects are automatically created from it and put
|
30
|
+
# into a Hash map when this file is loaded.
|
31
|
+
ENTITY_TABLE = [
|
32
|
+
[913, 'Alpha'],
|
33
|
+
[914, 'Beta'],
|
34
|
+
[915, 'Gamma'],
|
35
|
+
[916, 'Delta'],
|
36
|
+
[917, 'Epsilon'],
|
37
|
+
[918, 'Zeta'],
|
38
|
+
[919, 'Eta'],
|
39
|
+
[920, 'Theta'],
|
40
|
+
[921, 'Iota'],
|
41
|
+
[922, 'Kappa'],
|
42
|
+
[923, 'Lambda'],
|
43
|
+
[924, 'Mu'],
|
44
|
+
[925, 'Nu'],
|
45
|
+
[926, 'Xi'],
|
46
|
+
[927, 'Omicron'],
|
47
|
+
[928, 'Pi'],
|
48
|
+
[929, 'Rho'],
|
49
|
+
[931, 'Sigma'],
|
50
|
+
[932, 'Tau'],
|
51
|
+
[933, 'Upsilon'],
|
52
|
+
[934, 'Phi'],
|
53
|
+
[935, 'Chi'],
|
54
|
+
[936, 'Psi'],
|
55
|
+
[937, 'Omega'],
|
56
|
+
[945, 'alpha'],
|
57
|
+
[946, 'beta'],
|
58
|
+
[947, 'gamma'],
|
59
|
+
[948, 'delta'],
|
60
|
+
[949, 'epsilon'],
|
61
|
+
[950, 'zeta'],
|
62
|
+
[951, 'eta'],
|
63
|
+
[952, 'theta'],
|
64
|
+
[953, 'iota'],
|
65
|
+
[954, 'kappa'],
|
66
|
+
[955, 'lambda'],
|
67
|
+
[956, 'mu'],
|
68
|
+
[957, 'nu'],
|
69
|
+
[958, 'xi'],
|
70
|
+
[959, 'omicron'],
|
71
|
+
[960, 'pi'],
|
72
|
+
[961, 'rho'],
|
73
|
+
[963, 'sigma'],
|
74
|
+
[964, 'tau'],
|
75
|
+
[965, 'upsilon'],
|
76
|
+
[966, 'phi'],
|
77
|
+
[967, 'chi'],
|
78
|
+
[968, 'psi'],
|
79
|
+
[969, 'omega'],
|
80
|
+
[962, 'sigmaf'],
|
81
|
+
[977, 'thetasym'],
|
82
|
+
[978, 'upsih'],
|
83
|
+
[982, 'piv'],
|
84
|
+
[8204, 'zwnj'],
|
85
|
+
[8205, 'zwj'],
|
86
|
+
[8206, 'lrm'],
|
87
|
+
[8207, 'rlm'],
|
88
|
+
[8230, 'hellip'],
|
89
|
+
[8242, 'prime'],
|
90
|
+
[8243, 'Prime'],
|
91
|
+
[8254, 'oline'],
|
92
|
+
[8260, 'frasl'],
|
93
|
+
[8472, 'weierp'],
|
94
|
+
[8465, 'image'],
|
95
|
+
[8476, 'real'],
|
96
|
+
[8501, 'alefsym'],
|
97
|
+
[8226, 'bull'],
|
98
|
+
[8482, 'trade'],
|
99
|
+
[8592, 'larr'],
|
100
|
+
[8594, 'rarr'],
|
101
|
+
[8593, 'uarr'],
|
102
|
+
[8595, 'darr'],
|
103
|
+
[8596, 'harr'],
|
104
|
+
[8629, 'crarr'],
|
105
|
+
[8657, 'uArr'],
|
106
|
+
[8659, 'dArr'],
|
107
|
+
[8656, 'lArr'],
|
108
|
+
[8658, 'rArr'],
|
109
|
+
[8660, 'hArr'],
|
110
|
+
[8704, 'forall'],
|
111
|
+
[8706, 'part'],
|
112
|
+
[8707, 'exist'],
|
113
|
+
[8709, 'empty'],
|
114
|
+
[8711, 'nabla'],
|
115
|
+
[8712, 'isin'],
|
116
|
+
[8715, 'ni'],
|
117
|
+
[8713, 'notin'],
|
118
|
+
[8721, 'sum'],
|
119
|
+
[8719, 'prod'],
|
120
|
+
[8722, 'minus'],
|
121
|
+
[8727, 'lowast'],
|
122
|
+
[8730, 'radic'],
|
123
|
+
[8733, 'prop'],
|
124
|
+
[8734, 'infin'],
|
125
|
+
[8736, 'ang'],
|
126
|
+
[8743, 'and'],
|
127
|
+
[8744, 'or'],
|
128
|
+
[8745, 'cup'],
|
129
|
+
[8746, 'cap'],
|
130
|
+
[8747, 'int'],
|
131
|
+
[8756, 'there4'],
|
132
|
+
[8764, 'sim'],
|
133
|
+
[8776, 'asymp'],
|
134
|
+
[8773, 'cong'],
|
135
|
+
[8800, 'ne'],
|
136
|
+
[8801, 'equiv'],
|
137
|
+
[8804, 'le'],
|
138
|
+
[8805, 'ge'],
|
139
|
+
[8834, 'sub'],
|
140
|
+
[8835, 'sup'],
|
141
|
+
[8838, 'sube'],
|
142
|
+
[8839, 'supe'],
|
143
|
+
[8836, 'nsub'],
|
144
|
+
[8853, 'oplus'],
|
145
|
+
[8855, 'otimes'],
|
146
|
+
[8869, 'perp'],
|
147
|
+
[8901, 'sdot'],
|
148
|
+
[8942, 'vellip'],
|
149
|
+
[8968, 'rceil'],
|
150
|
+
[8969, 'lceil'],
|
151
|
+
[8970, 'lfloor'],
|
152
|
+
[8971, 'rfloor'],
|
153
|
+
[9001, 'rang'],
|
154
|
+
[9002, 'lang'],
|
155
|
+
[9674, 'loz'],
|
156
|
+
[9824, 'spades'],
|
157
|
+
[9827, 'clubs'],
|
158
|
+
[9829, 'hearts'],
|
159
|
+
[9830, 'diams'],
|
160
|
+
[38, 'amp'],
|
161
|
+
[34, 'quot'],
|
162
|
+
[39, 'apos'],
|
163
|
+
[169, 'copy'],
|
164
|
+
[60, 'lt'],
|
165
|
+
[62, 'gt'],
|
166
|
+
[338, 'OElig'],
|
167
|
+
[339, 'oelig'],
|
168
|
+
[352, 'Scaron'],
|
169
|
+
[353, 'scaron'],
|
170
|
+
[376, 'Yuml'],
|
171
|
+
[710, 'circ'],
|
172
|
+
[732, 'tilde'],
|
173
|
+
[8211, 'ndash'],
|
174
|
+
[8212, 'mdash'],
|
175
|
+
[8216, 'lsquo'],
|
176
|
+
[8217, 'rsquo'],
|
177
|
+
[8220, 'ldquo'],
|
178
|
+
[8221, 'rdquo'],
|
179
|
+
[8224, 'dagger'],
|
180
|
+
[8225, 'Dagger'],
|
181
|
+
[8240, 'permil'],
|
182
|
+
[8364, 'euro'],
|
183
|
+
[8249, 'lsaquo'],
|
184
|
+
[8250, 'rsaquo'],
|
185
|
+
[160, 'nbsp'],
|
186
|
+
[161, 'iexcl'],
|
187
|
+
[163, 'pound'],
|
188
|
+
[164, 'curren'],
|
189
|
+
[165, 'yen'],
|
190
|
+
[166, 'brvbar'],
|
191
|
+
[167, 'sect'],
|
192
|
+
[168, 'uml'],
|
193
|
+
[171, 'laquo'],
|
194
|
+
[187, 'raquo'],
|
195
|
+
[174, 'reg'],
|
196
|
+
[170, 'ordf'],
|
197
|
+
[172, 'not'],
|
198
|
+
[173, 'shy'],
|
199
|
+
[175, 'macr'],
|
200
|
+
[176, 'deg'],
|
201
|
+
[177, 'plusmn'],
|
202
|
+
[180, 'acute'],
|
203
|
+
[181, 'micro'],
|
204
|
+
[182, 'para'],
|
205
|
+
[183, 'middot'],
|
206
|
+
[184, 'cedil'],
|
207
|
+
[186, 'ordm'],
|
208
|
+
[162, 'cent'],
|
209
|
+
[185, 'sup1'],
|
210
|
+
[178, 'sup2'],
|
211
|
+
[179, 'sup3'],
|
212
|
+
[189, 'frac12'],
|
213
|
+
[188, 'frac14'],
|
214
|
+
[190, 'frac34'],
|
215
|
+
[191, 'iquest'],
|
216
|
+
[192, 'Agrave'],
|
217
|
+
[193, 'Aacute'],
|
218
|
+
[194, 'Acirc'],
|
219
|
+
[195, 'Atilde'],
|
220
|
+
[196, 'Auml'],
|
221
|
+
[197, 'Aring'],
|
222
|
+
[198, 'AElig'],
|
223
|
+
[199, 'Ccedil'],
|
224
|
+
[200, 'Egrave'],
|
225
|
+
[201, 'Eacute'],
|
226
|
+
[202, 'Ecirc'],
|
227
|
+
[203, 'Euml'],
|
228
|
+
[204, 'Igrave'],
|
229
|
+
[205, 'Iacute'],
|
230
|
+
[206, 'Icirc'],
|
231
|
+
[207, 'Iuml'],
|
232
|
+
[208, 'ETH'],
|
233
|
+
[209, 'Ntilde'],
|
234
|
+
[210, 'Ograve'],
|
235
|
+
[211, 'Oacute'],
|
236
|
+
[212, 'Ocirc'],
|
237
|
+
[213, 'Otilde'],
|
238
|
+
[214, 'Ouml'],
|
239
|
+
[215, 'times'],
|
240
|
+
[216, 'Oslash'],
|
241
|
+
[217, 'Ugrave'],
|
242
|
+
[218, 'Uacute'],
|
243
|
+
[219, 'Ucirc'],
|
244
|
+
[220, 'Uuml'],
|
245
|
+
[221, 'Yacute'],
|
246
|
+
[222, 'THORN'],
|
247
|
+
[223, 'szlig'],
|
248
|
+
[224, 'agrave'],
|
249
|
+
[225, 'aacute'],
|
250
|
+
[226, 'acirc'],
|
251
|
+
[227, 'atilde'],
|
252
|
+
[228, 'auml'],
|
253
|
+
[229, 'aring'],
|
254
|
+
[230, 'aelig'],
|
255
|
+
[231, 'ccedil'],
|
256
|
+
[232, 'egrave'],
|
257
|
+
[233, 'eacute'],
|
258
|
+
[234, 'ecirc'],
|
259
|
+
[235, 'euml'],
|
260
|
+
[236, 'igrave'],
|
261
|
+
[237, 'iacute'],
|
262
|
+
[238, 'icirc'],
|
263
|
+
[239, 'iuml'],
|
264
|
+
[240, 'eth'],
|
265
|
+
[241, 'ntilde'],
|
266
|
+
[242, 'ograve'],
|
267
|
+
[243, 'oacute'],
|
268
|
+
[244, 'ocirc'],
|
269
|
+
[245, 'otilde'],
|
270
|
+
[246, 'ouml'],
|
271
|
+
[247, 'divide'],
|
272
|
+
[248, 'oslash'],
|
273
|
+
[249, 'ugrave'],
|
274
|
+
[250, 'uacute'],
|
275
|
+
[251, 'ucirc'],
|
276
|
+
[252, 'uuml'],
|
277
|
+
[253, 'yacute'],
|
278
|
+
[254, 'thorn'],
|
279
|
+
[255, 'yuml'],
|
280
|
+
|
281
|
+
[8218, 'sbquo'],
|
282
|
+
[402, 'fnof'],
|
283
|
+
[8222, 'bdquo'],
|
284
|
+
|
285
|
+
[128, 8364],
|
286
|
+
[130, 8218],
|
287
|
+
[131, 402],
|
288
|
+
[132, 8222],
|
289
|
+
[133, 8230],
|
290
|
+
[134, 8224],
|
291
|
+
[135, 8225],
|
292
|
+
[136, 710],
|
293
|
+
[137, 8240],
|
294
|
+
[138, 352],
|
295
|
+
[139, 8249],
|
296
|
+
[140, 338],
|
297
|
+
[142, 381],
|
298
|
+
[145, 8216],
|
299
|
+
[146, 8217],
|
300
|
+
[147, 8220],
|
301
|
+
[148, 8221],
|
302
|
+
[149, 8226],
|
303
|
+
[150, 8211],
|
304
|
+
[151, 8212],
|
305
|
+
[152, 732],
|
306
|
+
[153, 8482],
|
307
|
+
[154, 353],
|
308
|
+
[155, 8250],
|
309
|
+
[156, 339],
|
310
|
+
[158, 382],
|
311
|
+
[159, 376],
|
312
|
+
|
313
|
+
[8194, 'ensp'],
|
314
|
+
[8195, 'emsp'],
|
315
|
+
[8201, 'thinsp'],
|
316
|
+
]
|
317
|
+
|
318
|
+
# Contains the mapping of code point (or name) to the actual Entity object.
|
319
|
+
ENTITY_MAP = Hash.new do |h,k|
|
320
|
+
if k.kind_of?(Integer)
|
321
|
+
h[k] = Entity.new(k, nil)
|
322
|
+
else
|
323
|
+
raise Kramdown::Error, "Can't handle generic non-integer character reference '#{k}'"
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
ENTITY_TABLE.each do |code_point, data|
|
328
|
+
if data.kind_of?(String)
|
329
|
+
ENTITY_MAP[code_point] = ENTITY_MAP[data] = Entity.new(code_point, data)
|
330
|
+
else
|
331
|
+
ENTITY_MAP[code_point] = ENTITY_MAP[data]
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# Return the entity for the given code point or name +point_or_name+.
|
336
|
+
def entity(point_or_name)
|
337
|
+
ENTITY_MAP[point_or_name]
|
338
|
+
end
|
339
|
+
|
340
|
+
module_function :entity
|
341
|
+
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
345
|
+
|
346
|
+
end
|
347
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
|
10
|
+
module Kramdown
|
11
|
+
|
12
|
+
module Utils
|
13
|
+
|
14
|
+
# Provides convenience methods for HTML related tasks.
|
15
|
+
#
|
16
|
+
# *Note* that this module has to be mixed into a class that has a @root (containing an element
|
17
|
+
# of type :root) and an @options (containing an options hash) instance variable so that some of
|
18
|
+
# the methods can work correctly.
|
19
|
+
module Html
|
20
|
+
|
21
|
+
# Convert the entity +e+ to a string. The optional parameter +original+ may contain the
|
22
|
+
# original representation of the entity.
|
23
|
+
#
|
24
|
+
# This method uses the option +entity_output+ to determine the output form for the entity.
|
25
|
+
def entity_to_str(e, original = nil)
|
26
|
+
entity_output = @options[:entity_output]
|
27
|
+
|
28
|
+
if e.char.respond_to?(:encoding) && entity_output == :as_char &&
|
29
|
+
(c = (@root.options[:encoding] ? e.char.encode(@root.options[:encoding]) : nil)) && # RM can't use rescue nil
|
30
|
+
((c = e.char) == '"' || !ESCAPE_MAP.has_key?(c))
|
31
|
+
c
|
32
|
+
elsif (entity_output == :as_input || entity_output == :as_char) && original
|
33
|
+
original
|
34
|
+
elsif (entity_output == :symbolic || ESCAPE_MAP.has_key?(e.char)) && !e.name.nil?
|
35
|
+
"&#{e.name};"
|
36
|
+
else # default to :numeric
|
37
|
+
"&##{e.code_point};"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return the HTML representation of the attributes +attr+.
|
42
|
+
def html_attributes(attr)
|
43
|
+
attr.map {|k,v| v.nil? || (k == 'id' && v.strip.empty?) ? '' : " #{k}=\"#{escape_html(v.to_s, :attribute)}\"" }.join('')
|
44
|
+
end
|
45
|
+
|
46
|
+
# :stopdoc:
|
47
|
+
ESCAPE_MAP = {
|
48
|
+
'<' => '<',
|
49
|
+
'>' => '>',
|
50
|
+
'&' => '&',
|
51
|
+
'"' => '"'
|
52
|
+
}
|
53
|
+
ESCAPE_ALL_RE = /<|>|&/
|
54
|
+
ESCAPE_TEXT_RE = Regexp.union(REXML::Parsers::BaseParser::REFERENCE_RE, /<|>|&/)
|
55
|
+
ESCAPE_ATTRIBUTE_RE = Regexp.union(REXML::Parsers::BaseParser::REFERENCE_RE, /<|>|&|"/)
|
56
|
+
ESCAPE_RE_FROM_TYPE = {
|
57
|
+
:all => ESCAPE_ALL_RE,
|
58
|
+
:text => ESCAPE_TEXT_RE,
|
59
|
+
:attribute => ESCAPE_ATTRIBUTE_RE
|
60
|
+
}
|
61
|
+
# :startdoc:
|
62
|
+
|
63
|
+
# Escape the special HTML characters in the string +str+. The parameter +type+ specifies what
|
64
|
+
# is escaped: :all - all special HTML characters except the quotation mark as well as
|
65
|
+
# entities, :text - all special HTML characters except the quotation mark but no entities and
|
66
|
+
# :attribute - all special HTML characters including the quotation mark but no entities.
|
67
|
+
def escape_html(str, type = :all)
|
68
|
+
str.gsub(ESCAPE_RE_FROM_TYPE[type]) {|m| ESCAPE_MAP[m] || m}
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
|
10
|
+
module Kramdown
|
11
|
+
|
12
|
+
module Utils
|
13
|
+
|
14
|
+
if RUBY_VERSION < '1.9'
|
15
|
+
|
16
|
+
# A partial hash implementation which preserves the insertion order of the keys.
|
17
|
+
#
|
18
|
+
# *Note* that this class is only used on Ruby 1.8 since the built-in Hash on Ruby 1.9
|
19
|
+
# automatically preserves the insertion order. However, to remain compatibility only the
|
20
|
+
# methods defined in this class may be used when working with OrderedHash on Ruby 1.9.
|
21
|
+
class OrderedHash
|
22
|
+
|
23
|
+
include Enumerable
|
24
|
+
|
25
|
+
# Initialize the OrderedHash object.
|
26
|
+
def initialize
|
27
|
+
@data = {}
|
28
|
+
@order = []
|
29
|
+
end
|
30
|
+
|
31
|
+
# Iterate over the stored keys in insertion order.
|
32
|
+
def each
|
33
|
+
@order.each {|k| yield(k, @data[k])}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return the value for the +key+.
|
37
|
+
def [](key)
|
38
|
+
@data[key]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return +true+ if the hash contains the key.
|
42
|
+
def has_key?(key)
|
43
|
+
@data.has_key?(key)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Set the value for the +key+ to +val+.
|
47
|
+
def []=(key, val)
|
48
|
+
@order << key if !@data.has_key?(key)
|
49
|
+
@data[key] = val
|
50
|
+
end
|
51
|
+
|
52
|
+
# Delete the +key+.
|
53
|
+
def delete(key)
|
54
|
+
@order.delete(key)
|
55
|
+
@data.delete(key)
|
56
|
+
end
|
57
|
+
|
58
|
+
def merge!(other)
|
59
|
+
other.each {|k,v| self[k] = v}
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
def dup #:nodoc:
|
64
|
+
new_object = super
|
65
|
+
new_object.instance_variable_set(:@data, @data.dup)
|
66
|
+
new_object.instance_variable_set(:@order, @order.dup)
|
67
|
+
new_object
|
68
|
+
end
|
69
|
+
|
70
|
+
def ==(other) #:nodoc:
|
71
|
+
return false unless other.kind_of?(self.class)
|
72
|
+
@data == other.instance_variable_get(:@data) && @order == other.instance_variable_get(:@order)
|
73
|
+
end
|
74
|
+
|
75
|
+
def inspect #:nodoc:
|
76
|
+
"{" + map {|k,v| "#{k.inspect}=>#{v.inspect}"}.join(" ") + "}"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
else
|
82
|
+
OrderedHash = Hash
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# RM require 'strscan'
|
4
|
+
|
5
|
+
module Kramdown
|
6
|
+
module Utils
|
7
|
+
|
8
|
+
# This patched StringScanner adds line number information for current scan position and a
|
9
|
+
# start_line_number override for nested StringScanners.
|
10
|
+
class StringScanner < ::StringScanner
|
11
|
+
|
12
|
+
# The start line number. Used for nested StringScanners that scan a sub-string of the source
|
13
|
+
# document. The kramdown parser uses this, e.g., for span level parsers.
|
14
|
+
attr_reader :start_line_number
|
15
|
+
|
16
|
+
# Takes the start line number as optional second argument.
|
17
|
+
#
|
18
|
+
# Note: The original second argument is no longer used so this should be safe.
|
19
|
+
def initialize(string, start_line_number = 1)
|
20
|
+
super(string)
|
21
|
+
@start_line_number = start_line_number || 1
|
22
|
+
@previous_pos = 0
|
23
|
+
@previous_line_number = @start_line_number
|
24
|
+
end
|
25
|
+
|
26
|
+
# Sets the byte position of the scan pointer.
|
27
|
+
#
|
28
|
+
# Note: This also resets some internal variables, so always use pos= when setting the position
|
29
|
+
# and don't use any other method for that!
|
30
|
+
def pos=(pos)
|
31
|
+
if self.pos > pos
|
32
|
+
@previous_line_number = @start_line_number
|
33
|
+
@previous_pos = 0
|
34
|
+
end
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return information needed to revert the byte position of the string scanner in a performant
|
39
|
+
# way.
|
40
|
+
#
|
41
|
+
# The returned data can be fed to #revert_pos to revert the position to the saved one.
|
42
|
+
#
|
43
|
+
# Note: Just saving #pos won't be enough.
|
44
|
+
def save_pos
|
45
|
+
[pos, @previous_pos, @previous_line_number]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Revert the position to one saved by #save_pos.
|
49
|
+
def revert_pos(data)
|
50
|
+
self.pos = data[0]
|
51
|
+
@previous_pos, @previous_line_number = data[1], data[2]
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the line number for current charpos.
|
55
|
+
#
|
56
|
+
# NOTE: Requires that all line endings are normalized to '\n'
|
57
|
+
#
|
58
|
+
# NOTE: Normally we'd have to add one to the count of newlines to get the correct line number.
|
59
|
+
# However we add the one indirectly by using a one-based start_line_number.
|
60
|
+
def current_line_number
|
61
|
+
# Not using string[@previous_pos..best_pos].count('\n') because it is slower
|
62
|
+
strscan = ::StringScanner.new(string)
|
63
|
+
strscan.pos = @previous_pos
|
64
|
+
old_pos = pos + 1
|
65
|
+
@previous_line_number += 1 while strscan.skip_until(/\n/) && strscan.pos <= old_pos
|
66
|
+
|
67
|
+
@previous_pos = (eos? ? pos : pos + 1)
|
68
|
+
@previous_line_number
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
# This file is based on code originally from the Stringex library and needs the data files from
|
10
|
+
# Stringex to work correctly.
|
11
|
+
|
12
|
+
module Kramdown
|
13
|
+
module Utils
|
14
|
+
|
15
|
+
# Provides the ability to tranliterate Unicode strings into plain ASCII ones.
|
16
|
+
module Unidecoder
|
17
|
+
|
18
|
+
# RM gem 'stringex' if defined?(Gem)
|
19
|
+
# RM TODO path = $:.find {|dir| File.directory?(File.join(File.expand_path(dir), "stringex", "unidecoder_data"))}
|
20
|
+
path = 'lib' # RM TODO
|
21
|
+
|
22
|
+
if RUBY_VERSION <= '1.8.6' || !path
|
23
|
+
def self.decode(string)
|
24
|
+
string
|
25
|
+
end
|
26
|
+
else
|
27
|
+
|
28
|
+
CODEPOINTS = Hash.new do |h, k|
|
29
|
+
if File.exists?(File.join(path, "stringex", "unidecoder_data", "#{k}.yml")) # RM
|
30
|
+
h[k] = YAML::load(File.join(path, "stringex", "unidecoder_data", "#{k}.yml")) # RM
|
31
|
+
end # RM
|
32
|
+
end
|
33
|
+
|
34
|
+
# Transliterate string from Unicode into ASCII.
|
35
|
+
def self.decode(string)
|
36
|
+
string.gsub(/[^\x00-\x7f]/u) do |codepoint|
|
37
|
+
begin
|
38
|
+
unpacked = codepoint.unpack("U")[0]
|
39
|
+
CODEPOINTS["x%02x" % (unpacked >> 8)][unpacked & 255]
|
40
|
+
rescue
|
41
|
+
"?"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown which is licensed under the MIT.
|
7
|
+
#++
|
8
|
+
#
|
9
|
+
|
10
|
+
module Kramdown
|
11
|
+
|
12
|
+
# == \Utils Module
|
13
|
+
#
|
14
|
+
# This module contains utility class/modules/methods that can be used by both parsers and
|
15
|
+
# converters.
|
16
|
+
module Utils
|
17
|
+
|
18
|
+
# RM autoload :Entities, 'kramdown/utils/entities'
|
19
|
+
# RM autoload :Html, 'kramdown/utils/html'
|
20
|
+
# RM autoload :OrderedHash, 'kramdown/utils/ordered_hash'
|
21
|
+
# RM autoload :Unidecoder, 'kramdown/utils/unidecoder'
|
22
|
+
# RM autoload :StringScanner, 'kramdown/utils/string_scanner'
|
23
|
+
# RM autoload :Configurable, 'kramdown/utils/configurable'
|
24
|
+
|
25
|
+
# Treat +name+ as if it were snake cased (e.g. snake_case) and camelize it (e.g. SnakeCase).
|
26
|
+
def self.camelize(name)
|
27
|
+
name.split('_').inject('') {|s,x| s << x[0..0].upcase << x[1..-1] }
|
28
|
+
end
|
29
|
+
|
30
|
+
# Treat +name+ as if it were camelized (e.g. CamelizedName) and snake-case it (e.g. camelized_name).
|
31
|
+
def self.snake_case(name)
|
32
|
+
name = name.dup
|
33
|
+
name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
34
|
+
name.gsub!(/([a-z])([A-Z])/,'\1_\2')
|
35
|
+
name.downcase!
|
36
|
+
name
|
37
|
+
end
|
38
|
+
|
39
|
+
if RUBY_VERSION < '2.0'
|
40
|
+
|
41
|
+
# Resolve the recursive constant +str+.
|
42
|
+
def self.deep_const_get(str)
|
43
|
+
names = str.split(/::/)
|
44
|
+
names.shift if names.first.empty?
|
45
|
+
names.inject(::Object) {|mod, s| mod.const_get(s)}
|
46
|
+
end
|
47
|
+
|
48
|
+
else
|
49
|
+
|
50
|
+
def self.deep_const_get(str)
|
51
|
+
::Object.const_get(str)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|