kramdown 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kramdown might be problematic. Click here for more details.

Files changed (69) hide show
  1. data/CONTRIBUTERS +2 -1
  2. data/ChangeLog +454 -0
  3. data/README +1 -1
  4. data/VERSION +1 -1
  5. data/doc/{default.less.css → default.scss.css} +12 -9
  6. data/doc/documentation.page +1 -1
  7. data/doc/index.page +37 -3
  8. data/doc/syntax.page +10 -7
  9. data/lib/kramdown/converter.rb +1 -0
  10. data/lib/kramdown/converter/html.rb +61 -67
  11. data/lib/kramdown/converter/kramdown.rb +398 -0
  12. data/lib/kramdown/converter/latex.rb +274 -276
  13. data/lib/kramdown/document.rb +2 -0
  14. data/lib/kramdown/options.rb +16 -15
  15. data/lib/kramdown/parser/base.rb +0 -1
  16. data/lib/kramdown/parser/html.rb +122 -27
  17. data/lib/kramdown/parser/kramdown.rb +2 -0
  18. data/lib/kramdown/parser/kramdown/attribute_list.rb +2 -0
  19. data/lib/kramdown/parser/kramdown/extension.rb +2 -1
  20. data/lib/kramdown/parser/kramdown/html.rb +2 -2
  21. data/lib/kramdown/parser/kramdown/html_entity.rb +1 -1
  22. data/lib/kramdown/parser/kramdown/link.rb +5 -2
  23. data/lib/kramdown/parser/kramdown/list.rb +13 -9
  24. data/lib/kramdown/parser/kramdown/math.rb +1 -1
  25. data/lib/kramdown/parser/kramdown/typographic_symbol.rb +4 -4
  26. data/lib/kramdown/utils.rb +36 -0
  27. data/lib/kramdown/utils/entities.rb +338 -0
  28. data/lib/kramdown/utils/html.rb +72 -0
  29. data/lib/kramdown/version.rb +1 -1
  30. data/man/man1/kramdown.1 +20 -17
  31. data/test/run_tests.rb +1 -1
  32. data/test/test_files.rb +60 -3
  33. data/test/testcases/block/06_codeblock/whitespace.html +2 -2
  34. data/test/testcases/block/07_horizontal_rule/error.html.19 +7 -0
  35. data/test/testcases/block/09_html/html_to_native/code.html +1 -1
  36. data/test/testcases/block/09_html/html_to_native/code.text +1 -1
  37. data/test/testcases/block/09_html/html_to_native/table_simple.html +38 -2
  38. data/test/testcases/block/09_html/html_to_native/table_simple.text +42 -0
  39. data/test/testcases/block/09_html/html_to_native/typography.html.19 +1 -0
  40. data/test/testcases/block/09_html/simple.html.19 +62 -0
  41. data/test/testcases/block/11_ial/simple.html +3 -2
  42. data/test/testcases/block/12_extension/comment.html +3 -2
  43. data/test/testcases/block/12_extension/options.html +0 -3
  44. data/test/testcases/block/12_extension/options.text +0 -6
  45. data/test/testcases/block/13_definition_list/item_ial.html +14 -0
  46. data/test/testcases/block/13_definition_list/item_ial.text +8 -0
  47. data/test/testcases/block/16_toc/no_toc_depth.html +33 -0
  48. data/test/testcases/block/16_toc/no_toc_depth.options +1 -0
  49. data/test/testcases/block/16_toc/no_toc_depth.text +16 -0
  50. data/test/testcases/block/16_toc/toc_depth_2.html +24 -0
  51. data/test/testcases/block/16_toc/toc_depth_2.options +1 -0
  52. data/test/testcases/block/16_toc/toc_depth_2.text +16 -0
  53. data/test/testcases/span/01_link/empty.html +2 -0
  54. data/test/testcases/span/01_link/empty.text +2 -0
  55. data/test/testcases/span/01_link/imagelinks.html +2 -0
  56. data/test/testcases/span/01_link/imagelinks.text +2 -0
  57. data/test/testcases/span/01_link/inline.html.19 +40 -0
  58. data/test/testcases/span/01_link/reference.html.19 +32 -0
  59. data/test/testcases/span/extension/comment.html +3 -3
  60. data/test/testcases/span/text_substitutions/entities.html.19 +4 -0
  61. data/test/testcases/span/text_substitutions/entities_numeric.html +1 -0
  62. data/test/testcases/span/text_substitutions/entities_numeric.html.19 +1 -0
  63. data/test/testcases/span/text_substitutions/entities_numeric.options +1 -0
  64. data/test/testcases/span/text_substitutions/entities_numeric.text +1 -0
  65. data/test/testcases/span/text_substitutions/typography.html.19 +18 -0
  66. metadata +30 -10
  67. data/test/testcases/block/09_html/filtered_html.html +0 -1
  68. data/test/testcases/block/09_html/filtered_html.options +0 -1
  69. data/test/testcases/block/09_html/filtered_html.text +0 -1
@@ -44,7 +44,7 @@ module Kramdown
44
44
  # Parse the inline math at the current location.
45
45
  def parse_inline_math
46
46
  @src.pos += @src.matched_size
47
- @tree.children << Element.new(:math, @src[1], :category => :inline)
47
+ @tree.children << Element.new(:math, @src[1], :category => :span)
48
48
  end
49
49
  define_parser(:inline_math, INLINE_MATH_START, '\$')
50
50
 
@@ -38,11 +38,11 @@ module Kramdown
38
38
  if val.kind_of?(Symbol)
39
39
  @tree.children << Element.new(:typographic_sym, val)
40
40
  elsif @src.matched == '\\<<'
41
- @tree.children << Element.new(:entity, 'lt')
42
- @tree.children << Element.new(:entity, 'lt')
41
+ @tree.children << Element.new(:entity, ::Kramdown::Utils::Entities.entity('lt'))
42
+ @tree.children << Element.new(:entity, ::Kramdown::Utils::Entities.entity('lt'))
43
43
  else
44
- @tree.children << Element.new(:entity, 'gt')
45
- @tree.children << Element.new(:entity, 'gt')
44
+ @tree.children << Element.new(:entity, ::Kramdown::Utils::Entities.entity('gt'))
45
+ @tree.children << Element.new(:entity, ::Kramdown::Utils::Entities.entity('gt'))
46
46
  end
47
47
  end
48
48
  define_parser(:typographic_syms, TYPOGRAPHIC_SYMS_RE, '--|\\.\\.\\.|(?:\\\\| )?(?:<<|>>)')
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ #--
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
+ #
6
+ # This file is part of kramdown.
7
+ #
8
+ # kramdown is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ #++
21
+ #
22
+
23
+ module Kramdown
24
+
25
+ # == Utils Module
26
+ #
27
+ # This module contains utility class/modules/methods that can be used by both parsers and
28
+ # converters.
29
+ module Utils
30
+
31
+ autoload :Entities, 'kramdown/utils/entities'
32
+ autoload :HTML, 'kramdown/utils/html'
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,338 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ #--
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
+ #
6
+ # This file is part of kramdown.
7
+ #
8
+ # kramdown is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ #++
21
+ #
22
+
23
+ module Kramdown
24
+
25
+ module Utils
26
+
27
+ module Entities
28
+
29
+ class Entity < Struct.new(:code_point, :name)
30
+
31
+ def char
32
+ [code_point].pack('U*') rescue nil
33
+ end
34
+
35
+ end
36
+
37
+ ENTITY_TABLE = [
38
+ [913, 'Alpha'],
39
+ [914, 'Beta'],
40
+ [915, 'Gamma'],
41
+ [916, 'Delta'],
42
+ [917, 'Epsilon'],
43
+ [918, 'Zeta'],
44
+ [919, 'Eta'],
45
+ [920, 'Theta'],
46
+ [921, 'Iota'],
47
+ [922, 'Kappa'],
48
+ [923, 'Lambda'],
49
+ [924, 'Mu'],
50
+ [925, 'Nu'],
51
+ [926, 'Xi'],
52
+ [927, 'Omicron'],
53
+ [928, 'Pi'],
54
+ [929, 'Rho'],
55
+ [931, 'Sigma'],
56
+ [932, 'Tau'],
57
+ [933, 'Upsilon'],
58
+ [934, 'Phi'],
59
+ [935, 'Chi'],
60
+ [936, 'Psi'],
61
+ [937, 'Omega'],
62
+ [945, 'alpha'],
63
+ [946, 'beta'],
64
+ [947, 'gamma'],
65
+ [948, 'delta'],
66
+ [949, 'epsilon'],
67
+ [950, 'zeta'],
68
+ [951, 'eta'],
69
+ [952, 'theta'],
70
+ [953, 'iota'],
71
+ [954, 'kappa'],
72
+ [955, 'lambda'],
73
+ [956, 'mu'],
74
+ [957, 'nu'],
75
+ [958, 'xi'],
76
+ [959, 'omicron'],
77
+ [960, 'pi'],
78
+ [961, 'rho'],
79
+ [963, 'sigma'],
80
+ [964, 'tau'],
81
+ [965, 'upsilon'],
82
+ [966, 'phi'],
83
+ [967, 'chi'],
84
+ [968, 'psi'],
85
+ [969, 'omega'],
86
+ [962, 'sigmaf'],
87
+ [977, 'thetasym'],
88
+ [982, 'piv'],
89
+ [8230, 'hellip'],
90
+ [8242, '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
+ [8968, 'rceil'],
149
+ [8969, 'lceil'],
150
+ [8970, 'lfloor'],
151
+ [8971, 'rfloor'],
152
+ [9001, 'rang'],
153
+ [9002, 'lang'],
154
+ [9674, 'loz'],
155
+ [9824, 'spades'],
156
+ [9827, 'clubs'],
157
+ [9829, 'hearts'],
158
+ [9830, 'diams'],
159
+ [38, 'amp'],
160
+ [34, 'quot'],
161
+ [39, 'apos'],
162
+ [169, 'copy'],
163
+ [60, 'lt'],
164
+ [62, 'gt'],
165
+ [338, 'OElig'],
166
+ [339, 'oelig'],
167
+ [352, 'Scaron'],
168
+ [353, 'scaron'],
169
+ [376, 'Yuml'],
170
+ [710, 'circ'],
171
+ [732, 'tilde'],
172
+ [8211, 'ndash'],
173
+ [8212, 'mdash'],
174
+ [8216, 'lsquo'],
175
+ [8217, 'rsquo'],
176
+ [8220, 'ldquo'],
177
+ [8221, 'rdquo'],
178
+ [8224, 'dagger'],
179
+ [8225, 'Dagger'],
180
+ [8240, 'permil'],
181
+ [8364, 'euro'],
182
+ [8249, 'lsaquo'],
183
+ [8250, 'rsaquo'],
184
+ [160, 'nbsp'],
185
+ [161, 'iexcl'],
186
+ [163, 'pound'],
187
+ [164, 'curren'],
188
+ [165, 'yen'],
189
+ [166, 'brvbar'],
190
+ [167, 'sect'],
191
+ [171, 'laquo'],
192
+ [187, 'raquo'],
193
+ [174, 'reg'],
194
+ [170, 'ordf'],
195
+ [172, 'not'],
196
+ [176, 'deg'],
197
+ [177, 'plusmn'],
198
+ [180, 'acute'],
199
+ [181, 'micro'],
200
+ [182, 'para'],
201
+ [183, 'middot'],
202
+ [186, 'ordm'],
203
+ [162, 'cent'],
204
+ [185, 'sup1'],
205
+ [178, 'sup2'],
206
+ [179, 'sup3'],
207
+ [189, 'frac12'],
208
+ [188, 'frac14'],
209
+ [190, 'frac34'],
210
+ [192, 'Agrave'],
211
+ [193, 'Aacute'],
212
+ [194, 'Acirc'],
213
+ [195, 'Atilde'],
214
+ [196, 'Auml'],
215
+ [197, 'Aring'],
216
+ [198, 'AElig'],
217
+ [199, 'Ccedil'],
218
+ [200, 'Egrave'],
219
+ [201, 'Eacute'],
220
+ [202, 'Ecirc'],
221
+ [203, 'Euml'],
222
+ [204, 'Igrave'],
223
+ [205, 'Iacute'],
224
+ [206, 'Icirc'],
225
+ [207, 'Iuml'],
226
+ [208, 'ETH'],
227
+ [209, 'Ntilde'],
228
+ [210, 'Ograve'],
229
+ [211, 'Oacute'],
230
+ [212, 'Ocirc'],
231
+ [213, 'Otilde'],
232
+ [214, 'Ouml'],
233
+ [215, 'times'],
234
+ [216, 'Oslash'],
235
+ [217, 'Ugrave'],
236
+ [218, 'Uacute'],
237
+ [219, 'Ucirc'],
238
+ [220, 'Uuml'],
239
+ [221, 'Yacute'],
240
+ [222, 'THORN'],
241
+ [223, 'szlig'],
242
+ [224, 'agrave'],
243
+ [225, 'aacute'],
244
+ [226, 'acirc'],
245
+ [227, 'atilde'],
246
+ [228, 'auml'],
247
+ [229, 'aring'],
248
+ [230, 'aelig'],
249
+ [231, 'ccedil'],
250
+ [232, 'egrave'],
251
+ [233, 'eacute'],
252
+ [234, 'ecirc'],
253
+ [235, 'euml'],
254
+ [236, 'igrave'],
255
+ [237, 'iacute'],
256
+ [238, 'icirc'],
257
+ [239, 'iuml'],
258
+ [240, 'eth'],
259
+ [241, 'ntilde'],
260
+ [242, 'ograve'],
261
+ [243, 'oacute'],
262
+ [244, 'ocirc'],
263
+ [245, 'otilde'],
264
+ [246, 'ouml'],
265
+ [247, 'divide'],
266
+ [248, 'oslash'],
267
+ [249, 'ugrave'],
268
+ [250, 'uacute'],
269
+ [251, 'ucirc'],
270
+ [252, 'uuml'],
271
+ [253, 'yacute'],
272
+ [254, 'thorn'],
273
+ [255, 'yuml'],
274
+
275
+ [8218, 'sbquo'],
276
+ [402, 'fnof'],
277
+ [8222, 'bdquo'],
278
+ [381, 'Zcaron'],
279
+ [382, 'zcaron'],
280
+
281
+ [128, 8364],
282
+ [130, 8218],
283
+ [131, 402],
284
+ [132, 8222],
285
+ [133, 8230],
286
+ [134, 8224],
287
+ [135, 8225],
288
+ [136, 710],
289
+ [137, 8240],
290
+ [138, 352],
291
+ [139, 8249],
292
+ [140, 338],
293
+ [142, 381],
294
+ [145, 8216],
295
+ [146, 8217],
296
+ [147, 8220],
297
+ [148, 8221],
298
+ [149, 8226],
299
+ [150, 8211],
300
+ [151, 8212],
301
+ [152, 732],
302
+ [153, 8482],
303
+ [154, 353],
304
+ [155, 8250],
305
+ [156, 339],
306
+ [158, 382],
307
+ [159, 376],
308
+ ]
309
+ ENTITY_MAP = Hash.new do |h,k|
310
+ if k.kind_of?(Integer)
311
+ h[k] = Entity.new(k, nil)
312
+ else
313
+ raise Kramdown::Error, "Can't handle generic non-integer character reference '#{k}'"
314
+ end
315
+ end
316
+
317
+ ENTITY_TABLE.each do |code_point, data|
318
+ if data.kind_of?(String)
319
+ ENTITY_MAP[code_point] = ENTITY_MAP[data] = Entity.new(code_point, data)
320
+ else
321
+ raise "No entity object for code point #{data} found" unless ENTITY_MAP.has_key?(data)
322
+ ENTITY_MAP[code_point] = ENTITY_MAP[data]
323
+ end
324
+ end
325
+
326
+ # Return the entity for the given +point_or_name+.
327
+ def entity(point_or_name)
328
+ ENTITY_MAP[point_or_name]
329
+ end
330
+
331
+ module_function :entity
332
+
333
+ end
334
+
335
+ end
336
+
337
+ end
338
+
@@ -0,0 +1,72 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ #--
4
+ # Copyright (C) 2009-2010 Thomas Leitner <t_leitner@gmx.at>
5
+ #
6
+ # This file is part of kramdown.
7
+ #
8
+ # kramdown is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # This program is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ #++
21
+ #
22
+
23
+ module Kramdown
24
+
25
+ module Utils
26
+
27
+ module HTML
28
+
29
+ # Convert the +entity+ to a string.
30
+ def entity_to_str(e)
31
+ if RUBY_VERSION >= '1.9' && (c = e.char.encode(@doc.parse_infos[:encoding]) rescue nil) && !ESCAPE_MAP.has_key?(c)
32
+ c
33
+ elsif @doc.options[:numeric_entities] || e.name.nil?
34
+ "&##{e.code_point};"
35
+ else
36
+ "&#{e.name};"
37
+ end
38
+ end
39
+
40
+ # Return the string with the attributes of the element +el+.
41
+ def html_attributes(el)
42
+ (el.options[:attr] || {}).map {|k,v| v.nil? ? '' : " #{k}=\"#{escape_html(v.to_s, :no_entities)}\"" }.sort.join('')
43
+ end
44
+
45
+ ESCAPE_MAP = {
46
+ '<' => '&lt;',
47
+ '>' => '&gt;',
48
+ '&' => '&amp;',
49
+ '"' => '&quot;'
50
+ }
51
+ ESCAPE_ALL_RE = Regexp.union(*ESCAPE_MAP.collect {|k,v| k})
52
+ ESCAPE_NO_ENTITIES_RE = Regexp.union(REXML::Parsers::BaseParser::REFERENCE_RE, ESCAPE_ALL_RE)
53
+ ESCAPE_NORMAL = Regexp.union(REXML::Parsers::BaseParser::REFERENCE_RE, /<|>|&/)
54
+ ESCAPE_RE_FROM_TYPE = {
55
+ :all => ESCAPE_ALL_RE,
56
+ :no_entities => ESCAPE_NO_ENTITIES_RE,
57
+ :text => ESCAPE_NORMAL
58
+ }
59
+
60
+ # Escape the special HTML characters in the string +str+. The parameter +type+ specifies what
61
+ # is escaped: <tt>:all</tt> - all special HTML characters as well as entities,
62
+ # <tt>:no_entities</tt> - all special HTML characters but no entities, <tt>:text</tt> - all
63
+ # special HTML characters except the quotation mark but no entities.
64
+ def escape_html(str, type = :all)
65
+ str.gsub(ESCAPE_RE_FROM_TYPE[type]) {|m| ESCAPE_MAP[m] || m}
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ end