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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +84 -0
  3. data/lib/kramdown/compatibility.rb +36 -0
  4. data/lib/kramdown/converter/base.rb +259 -0
  5. data/lib/kramdown/converter/html.rb +461 -0
  6. data/lib/kramdown/converter/kramdown.rb +423 -0
  7. data/lib/kramdown/converter/latex.rb +600 -0
  8. data/lib/kramdown/converter/math_engine/itex2mml.rb +39 -0
  9. data/lib/kramdown/converter/math_engine/mathjax.rb +33 -0
  10. data/lib/kramdown/converter/math_engine/ritex.rb +38 -0
  11. data/lib/kramdown/converter/pdf.rb +624 -0
  12. data/lib/kramdown/converter/remove_html_tags.rb +53 -0
  13. data/lib/kramdown/converter/syntax_highlighter/coderay.rb +78 -0
  14. data/lib/kramdown/converter/syntax_highlighter/rouge.rb +37 -0
  15. data/lib/kramdown/converter/toc.rb +69 -0
  16. data/lib/kramdown/converter.rb +69 -0
  17. data/lib/kramdown/document.rb +144 -0
  18. data/lib/kramdown/element.rb +515 -0
  19. data/lib/kramdown/error.rb +17 -0
  20. data/lib/kramdown/options.rb +584 -0
  21. data/lib/kramdown/parser/base.rb +130 -0
  22. data/lib/kramdown/parser/gfm.rb +55 -0
  23. data/lib/kramdown/parser/html.rb +575 -0
  24. data/lib/kramdown/parser/kramdown/abbreviation.rb +67 -0
  25. data/lib/kramdown/parser/kramdown/autolink.rb +37 -0
  26. data/lib/kramdown/parser/kramdown/blank_line.rb +30 -0
  27. data/lib/kramdown/parser/kramdown/block_boundary.rb +33 -0
  28. data/lib/kramdown/parser/kramdown/blockquote.rb +39 -0
  29. data/lib/kramdown/parser/kramdown/codeblock.rb +56 -0
  30. data/lib/kramdown/parser/kramdown/codespan.rb +44 -0
  31. data/lib/kramdown/parser/kramdown/emphasis.rb +61 -0
  32. data/lib/kramdown/parser/kramdown/eob.rb +26 -0
  33. data/lib/kramdown/parser/kramdown/escaped_chars.rb +25 -0
  34. data/lib/kramdown/parser/kramdown/extensions.rb +201 -0
  35. data/lib/kramdown/parser/kramdown/footnote.rb +56 -0
  36. data/lib/kramdown/parser/kramdown/header.rb +59 -0
  37. data/lib/kramdown/parser/kramdown/horizontal_rule.rb +27 -0
  38. data/lib/kramdown/parser/kramdown/html.rb +160 -0
  39. data/lib/kramdown/parser/kramdown/html_entity.rb +33 -0
  40. data/lib/kramdown/parser/kramdown/line_break.rb +25 -0
  41. data/lib/kramdown/parser/kramdown/link.rb +139 -0
  42. data/lib/kramdown/parser/kramdown/list.rb +256 -0
  43. data/lib/kramdown/parser/kramdown/math.rb +54 -0
  44. data/lib/kramdown/parser/kramdown/paragraph.rb +54 -0
  45. data/lib/kramdown/parser/kramdown/smart_quotes.rb +174 -0
  46. data/lib/kramdown/parser/kramdown/table.rb +171 -0
  47. data/lib/kramdown/parser/kramdown/typographic_symbol.rb +44 -0
  48. data/lib/kramdown/parser/kramdown.rb +359 -0
  49. data/lib/kramdown/parser/markdown.rb +56 -0
  50. data/lib/kramdown/parser.rb +27 -0
  51. data/lib/kramdown/utils/configurable.rb +44 -0
  52. data/lib/kramdown/utils/entities.rb +347 -0
  53. data/lib/kramdown/utils/html.rb +75 -0
  54. data/lib/kramdown/utils/ordered_hash.rb +87 -0
  55. data/lib/kramdown/utils/string_scanner.rb +74 -0
  56. data/lib/kramdown/utils/unidecoder.rb +51 -0
  57. data/lib/kramdown/utils.rb +58 -0
  58. data/lib/kramdown/version.rb +15 -0
  59. data/lib/kramdown.rb +10 -0
  60. data/lib/motion-kramdown.rb +47 -0
  61. data/lib/rubymotion/encodings.rb +37 -0
  62. data/lib/rubymotion/rexml_shim.rb +25 -0
  63. data/lib/rubymotion/set.rb +1349 -0
  64. data/lib/rubymotion/version.rb +6 -0
  65. data/spec/document_tree.rb +48 -0
  66. data/spec/gfm_to_html.rb +95 -0
  67. data/spec/helpers/it_behaves_like.rb +27 -0
  68. data/spec/helpers/option_file.rb +46 -0
  69. data/spec/helpers/spec_options.rb +37 -0
  70. data/spec/helpers/tidy.rb +12 -0
  71. data/spec/html_to_html.rb +40 -0
  72. data/spec/html_to_kramdown_to_html.rb +46 -0
  73. data/spec/kramdown_to_xxx.rb +40 -0
  74. data/spec/test_location.rb +203 -0
  75. data/spec/test_string_scanner_kramdown.rb +19 -0
  76. data/spec/text_to_kramdown_to_html.rb +52 -0
  77. data/spec/text_to_latex.rb +33 -0
  78. metadata +164 -0
@@ -0,0 +1,515 @@
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
+ # Represents all elements in the element tree.
13
+ #
14
+ # kramdown only uses this one class for representing all available elements in an element tree
15
+ # (paragraphs, headers, emphasis, ...). The type of element can be set via the #type accessor.
16
+ #
17
+ # Following is a description of all supported element types.
18
+ #
19
+ # Note that the option :location may contain the start line number of an element in the source
20
+ # document.
21
+ #
22
+ # == Structural Elements
23
+ #
24
+ # === :root
25
+ #
26
+ # [Category] None
27
+ # [Usage context] As the root element of a document
28
+ # [Content model] Block-level elements
29
+ #
30
+ # Represents the root of a kramdown document.
31
+ #
32
+ # The root element contains the following option keys:
33
+ #
34
+ # :encoding:: When running on Ruby 1.9 this key has to be set to the encoding used for the text
35
+ # parts of the kramdown document.
36
+ #
37
+ # :abbrev_defs:: This key may be used to store the mapping of abbreviation to abbreviation
38
+ # definition.
39
+ #
40
+ # :options:: This key may be used to store options that were set during parsing of the document.
41
+ #
42
+ #
43
+ # === :blank
44
+ #
45
+ # [Category] Block-level element
46
+ # [Usage context] Where block-level elements are expected
47
+ # [Content model] Empty
48
+ #
49
+ # Represents one or more blank lines. It is not allowed to have two or more consecutive blank
50
+ # elements.
51
+ #
52
+ # The +value+ field may contain the original content of the blank lines.
53
+ #
54
+ #
55
+ # === :p
56
+ #
57
+ # [Category] Block-level element
58
+ # [Usage context] Where block-level elements are expected
59
+ # [Content model] Span-level elements
60
+ #
61
+ # Represents a paragraph.
62
+ #
63
+ # If the option :transparent is +true+, this element just represents a block of text. I.e. this
64
+ # element just functions as a container for span-level elements.
65
+ #
66
+ #
67
+ # === :header
68
+ #
69
+ # [Category] Block-level element
70
+ # [Usage context] Where block-level elements are expected
71
+ # [Content model] Span-level elements
72
+ #
73
+ # Represents a header.
74
+ #
75
+ # The option :level specifies the header level and has to contain a number between 1 and \6. The
76
+ # option :raw_text has to contain the raw header text.
77
+ #
78
+ #
79
+ # === :blockquote
80
+ #
81
+ # [Category] Block-level element
82
+ # [Usage context] Where block-level elements are expected
83
+ # [Content model] Block-level elements
84
+ #
85
+ # Represents a blockquote.
86
+ #
87
+ #
88
+ # === :codeblock
89
+ #
90
+ # [Category] Block-level element
91
+ # [Usage context] Where block-level elements are expected
92
+ # [Content model] Empty
93
+ #
94
+ # Represents a code block, i.e. a block of text that should be used as-is.
95
+ #
96
+ # The +value+ field has to contain the content of the code block.
97
+ #
98
+ #
99
+ # === :ul
100
+ #
101
+ # [Category] Block-level element
102
+ # [Usage context] Where block-level elements are expected
103
+ # [Content model] One or more :li elements
104
+ #
105
+ # Represents an unordered list.
106
+ #
107
+ #
108
+ # === :ol
109
+ #
110
+ # [Category] Block-level element
111
+ # [Usage context] Where block-level elements are expected
112
+ # [Content model] One or more :li elements
113
+ #
114
+ # Represents an ordered list.
115
+ #
116
+ #
117
+ # === :li
118
+ #
119
+ # [Category] Block-level element
120
+ # [Usage context] Inside :ol and :ul elements
121
+ # [Content model] Block-level elements
122
+ #
123
+ # Represents a list item of an ordered or unordered list.
124
+ #
125
+ # Note that the first child of a list item must not be a :blank element!
126
+ #
127
+ #
128
+ # === :dl
129
+ #
130
+ # [Category] Block-level element
131
+ # [Usage context] Where block-level elements are expected
132
+ # [Content model] One or more groups each consisting of one or more :dt elements followed by one
133
+ # or more :dd elements.
134
+ #
135
+ # Represents a definition list which contains groups consisting of terms and definitions for them.
136
+ #
137
+ #
138
+ # === :dt
139
+ #
140
+ # [Category] Block-level element
141
+ # [Usage context] Before :dt or :dd elements inside a :dl elment
142
+ # [Content model] Span-level elements
143
+ #
144
+ # Represents the term part of a term-definition group in a definition list.
145
+ #
146
+ #
147
+ # === :dd
148
+ #
149
+ # [Category] Block-level element
150
+ # [Usage context] After :dt or :dd elements inside a :dl elment
151
+ # [Content model] Block-level elements
152
+ #
153
+ # Represents the definition part of a term-definition group in a definition list.
154
+ #
155
+ #
156
+ # === :hr
157
+ #
158
+ # [Category] Block-level element
159
+ # [Usage context] Where block-level elements are expected
160
+ # [Content model] None
161
+ #
162
+ # Represents a horizontal line.
163
+ #
164
+ #
165
+ # === :table
166
+ #
167
+ # [Category] Block-level element
168
+ # [Usage context] Where block-level elements are expected
169
+ # [Content model] Zero or one :thead elements, one or more :tbody elements, zero or one :tfoot
170
+ # elements
171
+ #
172
+ # Represents a table. Each table row (i.e. :tr element) of the table has to contain the same
173
+ # number of :td elements.
174
+ #
175
+ # The option :alignment has to be an array containing the alignment values, exactly one for each
176
+ # column of the table. The possible alignment values are :left, :center, :right and :default.
177
+ #
178
+ #
179
+ # === :thead
180
+ #
181
+ # [Category] None
182
+ # [Usage context] As first element inside a :table element
183
+ # [Content model] One or more :tr elements
184
+ #
185
+ # Represents the table header.
186
+ #
187
+ #
188
+ # === :tbody
189
+ #
190
+ # [Category] None
191
+ # [Usage context] After a :thead element but before a :tfoot element inside a :table element
192
+ # [Content model] One or more :tr elements
193
+ #
194
+ # Represents a table body.
195
+ #
196
+ #
197
+ # === :tfoot
198
+ #
199
+ # [Category] None
200
+ # [Usage context] As last element inside a :table element
201
+ # [Content model] One or more :tr elements
202
+ #
203
+ # Represents the table footer.
204
+ #
205
+ #
206
+ # === :tr
207
+ #
208
+ # [Category] None
209
+ # [Usage context] Inside :thead, :tbody and :tfoot elements
210
+ # [Content model] One or more :td elements
211
+ #
212
+ # Represents a table row.
213
+ #
214
+ #
215
+ # === :td
216
+ #
217
+ # [Category] Block-level element
218
+ # [Usage context] Inside :tr elements
219
+ # [Content model] As child of :thead/:tr span-level elements, as child of :tbody/:tr and
220
+ # :tfoot/:tr block-level elements
221
+ #
222
+ # Represents a table cell.
223
+ #
224
+ #
225
+ # === :math
226
+ #
227
+ # [Category] Block/span-level element
228
+ # [Usage context] Where block/span-level elements are expected
229
+ # [Content model] None
230
+ #
231
+ # Represents mathematical text that is written in LaTeX.
232
+ #
233
+ # The +value+ field has to contain the actual mathematical text.
234
+ #
235
+ # The option :category has to be set to either :span or :block depending on the context where the
236
+ # element is used.
237
+ #
238
+ #
239
+ # == Text Markup Elements
240
+ #
241
+ # === :text
242
+ #
243
+ # [Category] Span-level element
244
+ # [Usage context] Where span-level elements are expected
245
+ # [Content model] None
246
+ #
247
+ # Represents text.
248
+ #
249
+ # The +value+ field has to contain the text itself.
250
+ #
251
+ #
252
+ # === :br
253
+ #
254
+ # [Category] Span-level element
255
+ # [Usage context] Where span-level elements are expected
256
+ # [Content model] None
257
+ #
258
+ # Represents a hard line break.
259
+ #
260
+ #
261
+ # === :a
262
+ #
263
+ # [Category] Span-level element
264
+ # [Usage context] Where span-level elements are expected
265
+ # [Content model] Span-level elements
266
+ #
267
+ # Represents a link to an URL.
268
+ #
269
+ # The attribute +href+ has to be set to the URL to which the link points. The attribute +title+
270
+ # optionally contains the title of the link.
271
+ #
272
+ #
273
+ # === :img
274
+ #
275
+ # [Category] Span-level element
276
+ # [Usage context] Where span-level elements are expected
277
+ # [Content model] None
278
+ #
279
+ # Represents an image.
280
+ #
281
+ # The attribute +src+ has to be set to the URL of the image. The attribute +alt+ has to contain a
282
+ # text description of the image. The attribute +title+ optionally contains the title of the image.
283
+ #
284
+ #
285
+ # === :codespan
286
+ #
287
+ # [Category] Span-level element
288
+ # [Usage context] Where span-level elements are expected
289
+ # [Content model] None
290
+ #
291
+ # Represents verbatim text.
292
+ #
293
+ # The +value+ field has to contain the content of the code span.
294
+ #
295
+ #
296
+ # === :footnote
297
+ #
298
+ # [Category] Span-level element
299
+ # [Usage context] Where span-level elements are expected
300
+ # [Content model] None
301
+ #
302
+ # Represents a footnote marker.
303
+ #
304
+ # The +value+ field has to contain an element whose children are the content of the footnote. The
305
+ # option :name has to contain a valid and unique footnote name. A valid footnote name consists of
306
+ # a word character or a digit and then optionally followed by other word characters, digits or
307
+ # dashes.
308
+ #
309
+ #
310
+ # === :em
311
+ #
312
+ # [Category] Span-level element
313
+ # [Usage context] Where span-level elements are expected
314
+ # [Content model] Span-level elements
315
+ #
316
+ # Represents emphasis of its contents.
317
+ #
318
+ #
319
+ # === :strong
320
+ #
321
+ # [Category] Span-level element
322
+ # [Usage context] Where span-level elements are expected
323
+ # [Content model] Span-level elements
324
+ #
325
+ # Represents strong importance for its contents.
326
+ #
327
+ #
328
+ # === :entity
329
+ #
330
+ # [Category] Span-level element
331
+ # [Usage context] Where span-level elements are expected
332
+ # [Content model] None
333
+ #
334
+ # Represents an HTML entity.
335
+ #
336
+ # The +value+ field has to contain an instance of Kramdown::Utils::Entities::Entity. The option
337
+ # :original can be used to store the original representation of the entity.
338
+ #
339
+ #
340
+ # === :typographic_sym
341
+ #
342
+ # [Category] Span-level element
343
+ # [Usage context] Where span-level elements are expected
344
+ # [Content model] None
345
+ #
346
+ # Represents a typographic symbol.
347
+ #
348
+ # The +value+ field needs to contain a Symbol representing the specific typographic symbol from
349
+ # the following list:
350
+ #
351
+ # :mdash:: An mdash character (---)
352
+ # :ndash:: An ndash character (--)
353
+ # :hellip:: An ellipsis (...)
354
+ # :laquo:: A left guillemet (<<)
355
+ # :raquo:: A right guillemet (>>)
356
+ # :laquo_space:: A left guillemet with a space (<< )
357
+ # :raquo_space:: A right guillemet with a space ( >>)
358
+ #
359
+ #
360
+ # === :smart_quote
361
+ #
362
+ # [Category] Span-level element
363
+ # [Usage context] Where span-level elements are expected
364
+ # [Content model] None
365
+ #
366
+ # Represents a quotation character.
367
+ #
368
+ # The +value+ field needs to contain a Symbol representing the specific quotation character:
369
+ #
370
+ # :lsquo:: Left single quote
371
+ # :rsquo:: Right single quote
372
+ # :ldquo:: Left double quote
373
+ # :rdquo:: Right double quote
374
+ #
375
+ #
376
+ # === :abbreviation
377
+ #
378
+ # [Category] Span-level element
379
+ # [Usage context] Where span-level elements are expected
380
+ # [Content model] None
381
+ #
382
+ # Represents a text part that is an abbreviation.
383
+ #
384
+ # The +value+ field has to contain the text part that is the abbreviation. The definition of the
385
+ # abbreviation is stored in the :root element of the document.
386
+ #
387
+ #
388
+ # == Other Elements
389
+ #
390
+ # === :html_element
391
+ #
392
+ # [Category] Block/span-level element
393
+ # [Usage context] Where block/span-level elements or raw HTML elements are expected
394
+ # [Content model] Depends on the element
395
+ #
396
+ # Represents an HTML element.
397
+ #
398
+ # The +value+ field has to contain the name of the HTML element the element is representing.
399
+ #
400
+ # The option :category has to be set to either :span or :block depending on the whether the
401
+ # element is a block-level or a span-level element. The option :content_model has to be set to the
402
+ # content model for the element (either :block if it contains block-level elements, :span if it
403
+ # contains span-level elements or :raw if it contains raw content).
404
+ #
405
+ #
406
+ # === :xml_comment
407
+ #
408
+ # [Category] Block/span-level element
409
+ # [Usage context] Where block/span-level elements are expected or in raw HTML elements
410
+ # [Content model] None
411
+ #
412
+ # Represents an XML/HTML comment.
413
+ #
414
+ # The +value+ field has to contain the whole XML/HTML comment including the delimiters.
415
+ #
416
+ # The option :category has to be set to either :span or :block depending on the context where the
417
+ # element is used.
418
+ #
419
+ #
420
+ # === :xml_pi
421
+ #
422
+ # [Category] Block/span-level element
423
+ # [Usage context] Where block/span-level elements are expected or in raw HTML elements
424
+ # [Content model] None
425
+ #
426
+ # Represents an XML/HTML processing instruction.
427
+ #
428
+ # The +value+ field has to contain the whole XML/HTML processing instruction including the
429
+ # delimiters.
430
+ #
431
+ # The option :category has to be set to either :span or :block depending on the context where the
432
+ # element is used.
433
+ #
434
+ #
435
+ # === :comment
436
+ #
437
+ # [Category] Block/span-level element
438
+ # [Usage context] Where block/span-level elements are expected
439
+ # [Content model] None
440
+ #
441
+ # Represents a comment.
442
+ #
443
+ # The +value+ field has to contain the comment.
444
+ #
445
+ # The option :category has to be set to either :span or :block depending on the context where the
446
+ # element is used. If it is set to :span, then no blank lines are allowed in the comment.
447
+ #
448
+ #
449
+ # === :raw
450
+ #
451
+ # [Category] Block/span-level element
452
+ # [Usage context] Where block/span-level elements are expected
453
+ # [Content model] None
454
+ #
455
+ # Represents a raw string that should not be modified. For example, the element could contain some
456
+ # HTML code that should be output as-is without modification and escaping.
457
+ #
458
+ # The +value+ field has to contain the actual raw text.
459
+ #
460
+ # The option :category has to be set to either :span or :block depending on the context where the
461
+ # element is used. If it is set to :span, then no blank lines are allowed in the raw text.
462
+ #
463
+ # The option :type can be set to an array of strings to define for which converters the raw string
464
+ # is valid.
465
+ #
466
+ class Element
467
+
468
+ # A symbol representing the element type. For example, :p or :blockquote.
469
+ attr_accessor :type
470
+
471
+ # The value of the element. The interpretation of this field depends on the type of the element.
472
+ # Many elements don't use this field.
473
+ attr_accessor :value
474
+
475
+ # The child elements of this element.
476
+ attr_accessor :children
477
+
478
+
479
+ # Create a new Element object of type +type+. The optional parameters +value+, +attr+ and
480
+ # +options+ can also be set in this constructor for convenience.
481
+ def initialize(type, value = nil, attr = nil, options = nil)
482
+ @type, @value, @attr, @options = type, value, (Utils::OrderedHash.new.merge!(attr) if attr), options
483
+ @children = []
484
+ end
485
+
486
+ # The attributes of the element. Uses an Utils::OrderedHash to retain the insertion order.
487
+ def attr
488
+ @attr ||= Utils::OrderedHash.new
489
+ end
490
+
491
+ # The options hash for the element. It is used for storing arbitray options.
492
+ def options
493
+ @options ||= {}
494
+ end
495
+
496
+ def inspect #:nodoc:
497
+ "<kd:#{@type}#{@value.nil? ? '' : ' ' + @value.inspect} #{@attr.inspect}#{options.empty? ? '' : ' ' + @options.inspect}#{@children.empty? ? '' : ' ' + @children.inspect}>"
498
+ end
499
+
500
+ CATEGORY = {} # :nodoc:
501
+ [:blank, :p, :header, :blockquote, :codeblock, :ul, :ol, :li, :dl, :dt, :dd, :table, :td, :hr].each {|b| CATEGORY[b] = :block}
502
+ [:text, :a, :br, :img, :codespan, :footnote, :em, :strong, :entity, :typographic_sym,
503
+ :smart_quote, :abbreviation].each {|b| CATEGORY[b] = :span}
504
+
505
+ # Return the category of +el+ which can be :block, :span or +nil+.
506
+ #
507
+ # Most elements have a fixed category, however, some elements can either appear in a block-level
508
+ # or a span-level context. These elements need to have the option :category correctly set.
509
+ def self.category(el)
510
+ CATEGORY[el.type] || el.options[:category]
511
+ end
512
+
513
+ end
514
+
515
+ end
@@ -0,0 +1,17 @@
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
+ # This error is raised when an error condition is encountered.
13
+ #
14
+ # *Note* that this error is only raised by the support framework for the parsers and converters.
15
+ class Error < RuntimeError; end
16
+
17
+ end