kramdown 0.13.3 → 0.13.4

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 (35) hide show
  1. data/CONTRIBUTERS +5 -1
  2. data/ChangeLog +192 -0
  3. data/Rakefile +4 -3
  4. data/VERSION +1 -1
  5. data/bin/kramdown +1 -1
  6. data/doc/index.page +1 -1
  7. data/doc/tests.page +1 -1
  8. data/lib/kramdown/converter.rb +1 -0
  9. data/lib/kramdown/converter/html.rb +3 -3
  10. data/lib/kramdown/converter/toc.rb +82 -0
  11. data/lib/kramdown/document.rb +1 -494
  12. data/lib/kramdown/element.rb +524 -0
  13. data/lib/kramdown/parser/html.rb +11 -11
  14. data/lib/kramdown/parser/kramdown.rb +1 -1
  15. data/lib/kramdown/parser/kramdown/header.rb +1 -1
  16. data/lib/kramdown/parser/kramdown/html.rb +11 -11
  17. data/lib/kramdown/parser/kramdown/smart_quotes.rb +1 -1
  18. data/lib/kramdown/version.rb +1 -1
  19. data/setup.rb +1 -1
  20. data/test/test_files.rb +3 -3
  21. data/test/testcases/block/09_html/parse_as_raw.html +3 -0
  22. data/test/testcases/block/09_html/parse_as_raw.htmlinput +34 -0
  23. data/test/testcases/block/09_html/parse_as_raw.text +3 -1
  24. data/test/testcases/block/09_html/parse_as_span.htmlinput +12 -0
  25. data/test/testcases/block/09_html/parse_as_span.text +1 -1
  26. data/test/testcases/block/09_html/parse_block_html.text +2 -2
  27. data/test/testcases/block/12_extension/options.html +1 -1
  28. data/test/testcases/block/12_extension/options2.html +1 -1
  29. data/test/testcases/block/12_extension/options3.html +2 -2
  30. data/test/testcases/block/14_table/table_with_footnote.html +1 -1
  31. data/test/testcases/span/04_footnote/footnote_nr.html +2 -2
  32. data/test/testcases/span/04_footnote/markers.html +5 -5
  33. data/test/testcases/span/05_html/normal.html +4 -2
  34. data/test/testcases/span/05_html/normal.text +6 -4
  35. metadata +40 -40
@@ -1,6 +1,10 @@
1
1
  Count Name
2
2
  ======= ====
3
- 472 Thomas Leitner <t_leitner@gmx.at>
3
+ 483 Thomas Leitner <t_leitner@gmx.at>
4
+ 3 gettalong <t_leitner@gmx.at>
4
5
  3 Ben Armston <ben.armston@googlemail.com>
5
6
  3 Alex Marandon <contact@alexmarandon.com>
7
+ 1 Postmodern <postmodern.mod3@gmail.com>
8
+ 1 John Croisant <jacius@gmail.com>
9
+ 1 Joe Fiorini <joe@faithfulgeek.org>
6
10
  1 Damien Pollet <damien.pollet@gmail.com>
data/ChangeLog CHANGED
@@ -1,3 +1,195 @@
1
+ commit 2a93cbc0e1bbe705159c645ae617538bad125394
2
+ Author: Thomas Leitner <t_leitner@gmx.at>
3
+ Date: Fri Dec 16 18:26:32 2011 +0100
4
+
5
+ Updated release notes, version number and benchmark graphs
6
+
7
+ doc/img/graph-jruby-1.6.0-330.png
8
+ doc/img/graph-ruby-1.8.5-231.png
9
+ doc/img/graph-ruby-1.8.6-399.png
10
+ doc/img/graph-ruby-1.8.7-249.png
11
+ doc/img/graph-ruby-1.8.7-302.png
12
+ doc/img/graph-ruby-1.9.2p136-136.png
13
+ doc/img/graph-ruby-1.9.3p0-0.png
14
+ doc/index.page
15
+ doc/news/release_0_13_4.page
16
+ doc/news/release_0_X_X.page
17
+ doc/tests.page
18
+ lib/kramdown/version.rb
19
+
20
+ commit dbbabbc5b61b67ed0d22c1aa4a6b17608ed771e6
21
+ Author: Thomas Leitner <t_leitner@gmx.at>
22
+ Date: Tue Dec 13 17:25:53 2011 +0100
23
+
24
+ Fixed test case to work with coderay 1.0
25
+
26
+ test/testcases/block/12_extension/options3.html
27
+
28
+ commit 6828b83435c30676185d675dc7b6054846606df0
29
+ Author: Thomas Leitner <t_leitner@gmx.at>
30
+ Date: Tue Dec 13 17:25:31 2011 +0100
31
+
32
+ Updated Rakefile and setup.rb
33
+
34
+ * Use gem package task supplied by rubygems
35
+ * Add coderay as development dependency
36
+ * Fix warning in setup.rb because of Config::CONFIG use
37
+
38
+ Rakefile
39
+ setup.rb
40
+
41
+ commit bb7e82ce3f5213830fa6387e6c790a75b919dd38
42
+ Author: Thomas Leitner <t_leitner@gmx.at>
43
+ Date: Tue Dec 13 17:23:51 2011 +0100
44
+
45
+ Fixed problem with different Array#delete_if internals on Ruby 1.9.3
46
+
47
+ See http://redmine.ruby-lang.org/issues/5752
48
+
49
+ lib/kramdown/parser/html.rb
50
+
51
+ commit cd253a5e9d4dcfe55c12caf9257e4f1fb6113943
52
+ Author: Thomas Leitner <t_leitner@gmx.at>
53
+ Date: Sun Dec 11 15:40:35 2011 +0100
54
+
55
+ Fixed warnings on Ruby 1.9.3
56
+
57
+ lib/kramdown/converter/html.rb
58
+ lib/kramdown/parser/html.rb
59
+ lib/kramdown/parser/kramdown.rb
60
+ lib/kramdown/parser/kramdown/header.rb
61
+ lib/kramdown/parser/kramdown/html.rb
62
+ lib/kramdown/parser/kramdown/smart_quotes.rb
63
+ test/test_files.rb
64
+
65
+ commit e71cc414755e51c3336551e3f011f2f39ea601ee
66
+ Author: Thomas Leitner <t_leitner@gmx.at>
67
+ Date: Sun Dec 11 15:32:52 2011 +0100
68
+
69
+ Fixed test cases to correctly behave with new footnote rel output
70
+
71
+ test/testcases/block/12_extension/options.html
72
+ test/testcases/block/12_extension/options2.html
73
+ test/testcases/block/14_table/table_with_footnote.html
74
+
75
+ commit b3b2ebc233160f4f649f0d0aed070d7540781c4f
76
+ Merge: a58ba5b ef70112
77
+ Author: gettalong <t_leitner@gmx.at>
78
+ Date: Sun Dec 11 06:26:18 2011 -0800
79
+
80
+ Merge pull request #4 from joefiorini/master
81
+
82
+ HTML5 Compatibility for Footnotes
83
+
84
+ Replacing the rev='footnote' with rel='reference'.
85
+
86
+ commit a58ba5b364081e896e2a49cc06db5aec643f8bb4
87
+ Author: Thomas Leitner <t_leitner@gmx.at>
88
+ Date: Sun Dec 11 12:38:37 2011 +0100
89
+
90
+ Fixed bug RF#29426: Content of <style> tags is treated as raw text now
91
+
92
+ lib/kramdown/parser/html.rb
93
+ test/testcases/block/09_html/parse_as_raw.html
94
+ test/testcases/block/09_html/parse_as_raw.htmlinput
95
+ test/testcases/block/09_html/parse_as_raw.text
96
+
97
+ commit 14800a606565ff7d1759fea9815be1f9eff9b633
98
+ Author: Thomas Leitner <t_leitner@gmx.at>
99
+ Date: Sun Dec 11 12:27:52 2011 +0100
100
+
101
+ Fixed bug RF#29350: Parsing of HTML tags with mismatched case now works
102
+
103
+ lib/kramdown/parser/html.rb
104
+ lib/kramdown/parser/kramdown/html.rb
105
+ test/test_files.rb
106
+ test/testcases/block/09_html/parse_as_raw.htmlinput
107
+ test/testcases/block/09_html/parse_as_raw.text
108
+ test/testcases/block/09_html/parse_as_span.htmlinput
109
+ test/testcases/block/09_html/parse_as_span.text
110
+ test/testcases/block/09_html/parse_block_html.text
111
+ test/testcases/span/05_html/normal.html
112
+ test/testcases/span/05_html/normal.text
113
+
114
+ commit b585efb3086c3462a573b57d060dfd203070bcc1
115
+ Merge: 64a4e7e 3a72b72
116
+ Author: Thomas Leitner <t_leitner@gmx.at>
117
+ Date: Sat Sep 24 14:41:34 2011 +0200
118
+
119
+ Merge branch 'master' of github.com:gettalong/kramdown
120
+
121
+ commit 3a72b72564d4f788fa1423dd8eb1089e355b0a4c
122
+ Merge: e6c1b12 df5e705
123
+ Author: gettalong <t_leitner@gmx.at>
124
+ Date: Sat Sep 24 05:28:10 2011 -0700
125
+
126
+ Merge pull request #5 from jacius/span
127
+
128
+ span tags must have a separate closing tag to be valid HTML.
129
+
130
+ commit e6c1b12fa45c7b3284c4b41247ade9ff4b4379a4
131
+ Merge: 9188906 1270445
132
+ Author: gettalong <t_leitner@gmx.at>
133
+ Date: Sat Sep 24 05:24:32 2011 -0700
134
+
135
+ Merge pull request #6 from postmodern/patch-1
136
+
137
+ Fixed a typo. --output not --ouput
138
+
139
+ commit 12704459192bdcbf9b02d1d90483c8d835f3e9f1
140
+ Author: Postmodern <postmodern.mod3@gmail.com>
141
+ Date: Thu Aug 4 18:57:59 2011 -0700
142
+
143
+ Fixed a typo. --output not --ouput
144
+
145
+ bin/kramdown
146
+
147
+ commit df5e705ef41ca2c47b5b0d54509cdfb80c2d5f4d
148
+ Author: John Croisant <jacius@gmail.com>
149
+ Date: Sun Jul 10 23:52:35 2011 -0500
150
+
151
+ span tags must have a separate closing tag to be valid HTML.
152
+
153
+ "<span />" is invalid markup in HTML 4 and 5, but valid in XHTML.
154
+ "<span></span>" is valid in all three, so it should be used instead.
155
+
156
+ lib/kramdown/converter/html.rb
157
+ test/testcases/span/05_html/normal.html
158
+ test/testcases/span/05_html/normal.text
159
+
160
+ commit ef7011229e7d93c31c22468e5cfd797051ac280c
161
+ Author: Joe Fiorini <joe@faithfulgeek.org>
162
+ Date: Wed May 11 02:08:38 2011 -0400
163
+
164
+ Replace rev attribute for HTML5 compatibility
165
+
166
+ lib/kramdown/converter/html.rb
167
+ test/testcases/span/04_footnote/footnote_nr.html
168
+ test/testcases/span/04_footnote/markers.html
169
+
170
+ commit 64a4e7e61da0d720ffd702fd6c45cefafc568d24
171
+ Author: Thomas Leitner <t_leitner@gmx.at>
172
+ Date: Tue May 10 20:47:16 2011 +0200
173
+
174
+ Added a TOC converter
175
+
176
+ The TOC converter can be used to get an element tree containing the
177
+ table of contents. Since it uses a custom element type the resulting
178
+ tree cannot be fed directly to any converter.
179
+
180
+ doc/news/release_0_X_X.page
181
+ lib/kramdown/converter.rb
182
+ lib/kramdown/converter/toc.rb
183
+
184
+ commit 5ed13d24d9375771e3a0bd0d4fbe779d0043563b
185
+ Author: Thomas Leitner <t_leitner@gmx.at>
186
+ Date: Tue May 10 07:42:23 2011 +0200
187
+
188
+ Extracted Element class into own file and made some small doc fixes
189
+
190
+ lib/kramdown/document.rb
191
+ lib/kramdown/element.rb
192
+
1
193
  commit 91889069d843273d5847330cdce4b1068e74108f
2
194
  Author: Thomas Leitner <t_leitner@gmx.at>
3
195
  Date: Fri May 6 15:39:50 2011 +0200
data/Rakefile CHANGED
@@ -3,7 +3,7 @@
3
3
  # load all optional developer libraries
4
4
  begin
5
5
  require 'rubygems'
6
- require 'rake/gempackagetask'
6
+ require 'rubygems/package_task'
7
7
  rescue LoadError
8
8
  end
9
9
 
@@ -196,6 +196,7 @@ EOF
196
196
  s.require_path = 'lib'
197
197
  s.executables = ['kramdown']
198
198
  s.default_executable = 'kramdown'
199
+ s.add_development_dependency 'coderay', '~> 1.0.0'
199
200
 
200
201
  #### Documentation
201
202
 
@@ -211,7 +212,7 @@ EOF
211
212
  s.rubyforge_project = 'kramdown'
212
213
  end
213
214
 
214
- Rake::GemPackageTask.new(spec) do |pkg|
215
+ Gem::PackageTask.new(spec) do |pkg|
215
216
  pkg.need_zip = true
216
217
  pkg.need_tar = true
217
218
  end
@@ -233,7 +234,7 @@ EOF
233
234
  rf.configure
234
235
  rf.login
235
236
 
236
- rf.userconfig["release_notes"] = REL_PAGE.blocks['content'].content.force_encoding('ASCII-8BIT')
237
+ rf.userconfig["release_notes"] = REL_PAGE.blocks['content'].content
237
238
  rf.userconfig["preformatted"] = false
238
239
 
239
240
  files = %w[.gem .tgz .zip].collect {|ext| "pkg/kramdown-#{Kramdown::VERSION}" + ext}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.3
1
+ 0.13.4
@@ -35,7 +35,7 @@ OptionParser.new do |opts|
35
35
  opts.separator ""
36
36
 
37
37
  opts.on("-i", "--input ARG", "Specify the input format: kramdown (default) or html") {|v| options[:input] = v}
38
- opts.on("-o", "--ouput ARG", "Specify the output format: html (default), kramdown or latex") {|v| format = v}
38
+ opts.on("-o", "--output ARG", "Specify the output format: html (default), kramdown or latex") {|v| format = v}
39
39
 
40
40
  opts.on("-v", "--version", "Show the version of kramdown") do
41
41
  puts Kramdown::VERSION
@@ -90,7 +90,7 @@ It is probably the fastest pure-Ruby Markdown converter available (January 2011)
90
90
  faster than [Maruku] and about 5x faster than [BlueFeather].
91
91
 
92
92
  <p class="a-center">
93
- The latest version of kramdown is <b>0.13.3</b> and it was released on <b>2011-05-06</b>.
93
+ The latest version of kramdown is <b>0.13.4</b> and it was released on <b>2011-12-16</b>.
94
94
  </p>
95
95
 
96
96
  [PHP Markdown Extra]: http://michelf.com/projects/php-markdown/extra/
@@ -46,7 +46,7 @@ different Ruby interpreters:
46
46
  ![ruby 1.8.7p249]({relocatable: img/graph-ruby-1.8.7-249.png})
47
47
  ![ruby 1.8.7p302]({relocatable: img/graph-ruby-1.8.7-302.png})
48
48
  ![ruby 1.9.2p136]({relocatable: img/graph-ruby-1.9.2p136-136.png})
49
- ![jruby 1.6.0]({relocatable: img/graph-jruby-1.6.0-330.png})
49
+ ![ruby 1.9.3p0]({relocatable: img/graph-ruby-1.9.3p0-0.png})
50
50
 
51
51
  [Markdown Test Suite]: http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip
52
52
  [MDTest]: http://www.michelf.com/docs/projets/mdtest-1.0.zip
@@ -34,6 +34,7 @@ module Kramdown
34
34
  autoload :Html, 'kramdown/converter/html'
35
35
  autoload :Latex, 'kramdown/converter/latex'
36
36
  autoload :Kramdown, 'kramdown/converter/kramdown'
37
+ autoload :Toc, 'kramdown/converter/toc'
37
38
 
38
39
  end
39
40
 
@@ -45,7 +45,7 @@ module Kramdown
45
45
 
46
46
  # Highlighting via coderay is available if this constant is +true+.
47
47
  HIGHLIGHTING_AVAILABLE = true
48
- rescue LoadError => e
48
+ rescue LoadError
49
49
  HIGHLIGHTING_AVAILABLE = false # :nodoc:
50
50
  end
51
51
 
@@ -178,7 +178,7 @@ module Kramdown
178
178
  end
179
179
 
180
180
  # A list of all HTML tags that need to have a body (even if the body is empty).
181
- HTML_TAGS_WITH_BODY=['div', 'script', 'iframe', 'textarea', 'a'] # :nodoc:
181
+ HTML_TAGS_WITH_BODY=['div', 'span', 'script', 'iframe', 'textarea', 'a'] # :nodoc:
182
182
 
183
183
  def convert_html_element(el, indent)
184
184
  res = inner(el, indent)
@@ -393,7 +393,7 @@ module Kramdown
393
393
  li.children = Marshal.load(Marshal.dump(data.children))
394
394
  ol.children << li
395
395
 
396
- ref = Element.new(:raw, "<a href=\"#fnref:#{name}\" rev=\"footnote\">&#8617;</a>")
396
+ ref = Element.new(:raw, "<a href=\"#fnref:#{name}\" rel=\"reference\">&#8617;</a>")
397
397
  if li.children.last.type == :p
398
398
  para = li.children.last
399
399
  else
@@ -0,0 +1,82 @@
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
+ require 'rexml/parsers/baseparser'
24
+
25
+ module Kramdown
26
+
27
+ module Converter
28
+
29
+ # Converts a Kramdown::Document to an element tree that represents the table of contents.
30
+ #
31
+ # The returned tree consists of Element objects of type :toc where the root element is just used
32
+ # as container object. Each :toc element contains as value the wrapped :header element and under
33
+ # the attribute key :id the header ID that should be used (note that this ID may not exist in
34
+ # the wrapped element).
35
+ #
36
+ # Since the TOC tree consists of special :toc elements, one cannot directly feed this tree to
37
+ # other converters!
38
+ class Toc < Base
39
+
40
+ def initialize(root, options)
41
+ super
42
+ @toc = Element.new(:toc)
43
+ @stack = []
44
+ @options[:template] = ''
45
+ end
46
+
47
+ def convert(el)
48
+ if el.type == :header && in_toc?(el)
49
+ attr = el.attr.dup
50
+ attr['id'] = generate_id(el.options[:raw_text]) if @options[:auto_ids] && !attr['id']
51
+ add_to_toc(el, attr['id'], @toc) if attr['id']
52
+ else
53
+ el.children.each {|child| convert(child)}
54
+ end
55
+ @toc
56
+ end
57
+
58
+ private
59
+
60
+ def add_to_toc(el, id, toc)
61
+ toc_element = Element.new(:toc, el, :id => id)
62
+
63
+ success = false
64
+ while !success
65
+ if @stack.empty?
66
+ @toc.children << toc_element
67
+ @stack << toc_element
68
+ success = true
69
+ elsif @stack.last.value.options[:level] < el.options[:level]
70
+ @stack.last.children << toc_element
71
+ @stack << toc_element
72
+ success = true
73
+ else
74
+ @stack.pop
75
+ end
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+ end
@@ -23,6 +23,7 @@
23
23
  require 'kramdown/compatibility'
24
24
 
25
25
  require 'kramdown/version'
26
+ require 'kramdown/element'
26
27
  require 'kramdown/error'
27
28
  require 'kramdown/parser'
28
29
  require 'kramdown/converter'
@@ -112,499 +113,5 @@ module Kramdown
112
113
 
113
114
  end
114
115
 
115
-
116
- # Represents all elements in the element tree.
117
- #
118
- # kramdown only uses this one class for representing all available elements in an element tree
119
- # (paragraphs, headers, emphasis, ...). The type of element can be set via the #type accessor.
120
- #
121
- # Following is a description of all supported element types.
122
- #
123
- # == Structural Elements
124
- #
125
- # === :root
126
- #
127
- # [Category] None
128
- # [Usage context] As the root element of a document
129
- # [Content model] Block-level elements
130
- #
131
- # Represents the root of a kramdown document.
132
- #
133
- # The root element contains the following option keys:
134
- #
135
- # :encoding:: When running on Ruby 1.9 this key has to be set to the encoding used for the text
136
- # parts of the kramdown document.
137
- #
138
- # :abbrev_defs:: This key may be used to store the mapping of abbreviation to abbreviation
139
- # definition.
140
- #
141
- #
142
- # === :blank
143
- #
144
- # [Category] Block-level element
145
- # [Usage context] Where block-level elements are expected
146
- # [Content model] Empty
147
- #
148
- # Represents one or more blank lines. It is not allowed to have two or more consecutive blank
149
- # elements.
150
- #
151
- # The +value+ field may contain the original content of the blank lines.
152
- #
153
- #
154
- # === :p
155
- #
156
- # [Category] Block-level element
157
- # [Usage context] Where block-level elements are expected
158
- # [Content model] Span-level elements
159
- #
160
- # Represents a paragraph.
161
- #
162
- # If the option :transparent is +true+, this element just represents a block of text. I.e. this
163
- # element just functions as a container for span-level elements.
164
- #
165
- #
166
- # === :header
167
- #
168
- # [Category] Block-level element
169
- # [Usage context] Where block-level elements are expected
170
- # [Content model] Span-level elements
171
- #
172
- # Represents a header.
173
- #
174
- # The option :level specifies the header level and has to contain a number between 1 and \6. The
175
- # option :raw_text has to contain the raw header text.
176
- #
177
- #
178
- # === :blockquote
179
- #
180
- # [Category] Block-level element
181
- # [Usage context] Where block-level elements are expected
182
- # [Content model] Block-level elements
183
- #
184
- # Represents a blockquote.
185
- #
186
- #
187
- # === :codeblock
188
- #
189
- # [Category] Block-level element
190
- # [Usage context] Where block-level elements are expected
191
- # [Content model] Empty
192
- #
193
- # Represents a code block, i.e. a block of text that should be used as-is.
194
- #
195
- # The +value+ field has to contain the content of the code block.
196
- #
197
- #
198
- # === :ul
199
- #
200
- # [Category] Block-level element
201
- # [Usage context] Where block-level elements are expected
202
- # [Content model] One or more :li elements
203
- #
204
- # Represents an unordered list.
205
- #
206
- #
207
- # === :ol
208
- #
209
- # [Category] Block-level element
210
- # [Usage context] Where block-level elements are expected
211
- # [Content model] One or more :li elements
212
- #
213
- # Represents an ordered list.
214
- #
215
- #
216
- # === :li
217
- #
218
- # [Category] None
219
- # [Usage context] Inside :ol and :ul elements
220
- # [Content model] Block-level elements
221
- #
222
- # Represents a list item of an ordered or unordered list.
223
- #
224
- #
225
- # === :dl
226
- #
227
- # [Category] Block-level element
228
- # [Usage context] Where block-level elements are expected
229
- # [Content model] One or more groups each consisting of one or more :dt elements followed by one
230
- # or more :dd elements.
231
- #
232
- # Represents a definition list which contains groups consisting of terms and definitions for them.
233
- #
234
- #
235
- # === :dt
236
- #
237
- # [Category] None
238
- # [Usage context] Before :dt or :dd elements inside a :dl elment
239
- # [Content model] Span-level elements
240
- #
241
- # Represents the term part of a term-definition group in a definition list.
242
- #
243
- #
244
- # === :dd
245
- #
246
- # [Category] None
247
- # [Usage context] After :dt or :dd elements inside a :dl elment
248
- # [Content model] Block-level elements
249
- #
250
- # Represents the definition part of a term-definition group in a definition list.
251
- #
252
- #
253
- # === :hr
254
- #
255
- # [Category] Block-level element
256
- # [Usage context] Where block-level elements are expected
257
- # [Content model] None
258
- #
259
- # Represents a horizontal line.
260
- #
261
- #
262
- # === :table
263
- #
264
- # [Category] Block-level element
265
- # [Usage context] Where block-level elements are expected
266
- # [Content model] Zero or one :thead elements, one or more :tbody elements, zero or one :tfoot
267
- # elements
268
- #
269
- # Represents a table. Each table row (i.e. :tr element) of the table has to contain the same
270
- # number of :td elements.
271
- #
272
- # The option :alignment has to be an array containing the alignment values, exactly one for each
273
- # column of the table. The possible alignment values are :left, :center, :right and :default.
274
- #
275
- #
276
- # === :thead
277
- #
278
- # [Category] None
279
- # [Usage context] As first element inside a :table element
280
- # [Content model] One or more :tr elements
281
- #
282
- # Represents the table header.
283
- #
284
- #
285
- # === :tbody
286
- #
287
- # [Category] None
288
- # [Usage context] After a :thead element but before a :tfoot element inside a :table element
289
- # [Content model] One or more :tr elements
290
- #
291
- # Represents a table body.
292
- #
293
- #
294
- # === :tfoot
295
- #
296
- # [Category] None
297
- # [Usage context] As last element inside a :table element
298
- # [Content model] One or more :tr elements
299
- #
300
- # Represents the table footer.
301
- #
302
- #
303
- # === :tr
304
- #
305
- # [Category] None
306
- # [Usage context] Inside :thead, :tbody and :tfoot elements
307
- # [Content model] One or more :td elements
308
- #
309
- # Represents a table row.
310
- #
311
- #
312
- # === :td
313
- #
314
- # [Category] None
315
- # [Usage context] Inside :tr elements
316
- # [Content model] As child of :thead/:tr span-level elements, as child of :tbody/:tr and
317
- # :tfoot/:tr block-level elements
318
- #
319
- # Represents a table cell.
320
- #
321
- #
322
- # === :math
323
- #
324
- # [Category] Block/span-level element
325
- # [Usage context] Where block/span-level elements are expected
326
- # [Content model] None
327
- #
328
- # Represents mathematical text that is written in LaTeX.
329
- #
330
- # The +value+ field has to contain the actual mathematical text.
331
- #
332
- # The option :category has to be set to either :span or :block depending on the context where the
333
- # element is used.
334
- #
335
- #
336
- # == Text Markup Elements
337
- #
338
- # === :text
339
- #
340
- # [Category] Span-level element
341
- # [Usage context] Where span-level elements are expected
342
- # [Content model] None
343
- #
344
- # Represents text.
345
- #
346
- # The +value+ field has to contain the text itself.
347
- #
348
- #
349
- # === :br
350
- #
351
- # [Category] Span-level element
352
- # [Usage context] Where span-level elements are expected
353
- # [Content model] None
354
- #
355
- # Represents a hard line break.
356
- #
357
- #
358
- # === :a
359
- #
360
- # [Category] Span-level element
361
- # [Usage context] Where span-level elements are expected
362
- # [Content model] Span-level elements
363
- #
364
- # Represents a link to an URL.
365
- #
366
- # The attribute +href+ has to be set to the URL to which the link points. The attribute +title+
367
- # optionally contains the title of the link.
368
- #
369
- #
370
- # === :img
371
- #
372
- # [Category] Span-level element
373
- # [Usage context] Where span-level elements are expected
374
- # [Content model] None
375
- #
376
- # Represents an image.
377
- #
378
- # The attribute +src+ has to be set to the URL of the image. The attribute +alt+ has to contain a
379
- # text description of the image. The attribute +title+ optionally contains the title of the image.
380
- #
381
- #
382
- # === :codespan
383
- #
384
- # [Category] Span-level element
385
- # [Usage context] Where span-level elements are expected
386
- # [Content model] None
387
- #
388
- # Represents verbatim text.
389
- #
390
- # The +value+ field has to contain the content of the code span.
391
- #
392
- #
393
- # === :footnote
394
- #
395
- # [Category] Span-level element
396
- # [Usage context] Where span-level elements are expected
397
- # [Content model] None
398
- #
399
- # Represents a footnote marker.
400
- #
401
- # The +value+ field has to contain an element whose children are the content of the footnote. The
402
- # option :name has to contain a valid and unique footnote name. A valid footnote name consists of
403
- # a word character or a digit and then optionally followed by other word characters, digits or
404
- # dashes.
405
- #
406
- #
407
- # === :em
408
- #
409
- # [Category] Span-level element
410
- # [Usage context] Where span-level elements are expected
411
- # [Content model] Span-level elements
412
- #
413
- # Represents emphasis of its contents.
414
- #
415
- #
416
- # === :strong
417
- #
418
- # [Category] Span-level element
419
- # [Usage context] Where span-level elements are expected
420
- # [Content model] Span-level elements
421
- #
422
- # Represents strong importance for its contents.
423
- #
424
- #
425
- # === :entity
426
- #
427
- # [Category] Span-level element
428
- # [Usage context] Where span-level elements are expected
429
- # [Content model] None
430
- #
431
- # Represents an HTML entity.
432
- #
433
- # The +value+ field has to contain an instance of Kramdown::Utils::Entities::Entity. The option
434
- # :original can be used to store the original representation of the entity.
435
- #
436
- #
437
- # === :typographic_sym
438
- #
439
- # [Category] Span-level element
440
- # [Usage context] Where span-level elements are expected
441
- # [Content model] None
442
- #
443
- # Represents a typographic symbol.
444
- #
445
- # The +value+ field needs to contain a Symbol representing the specific typographic symbol from
446
- # the following list:
447
- #
448
- # :mdash:: An mdash character (---)
449
- # :ndash:: An ndash character (--)
450
- # :hellip:: An ellipsis (...)
451
- # :laquo:: A left guillemet (<<)
452
- # :raquo:: A right guillemet (>>)
453
- # :laquo_space:: A left guillemet with a space (<< )
454
- # :raquo_space:: A right guillemet with a space ( >>)
455
- #
456
- #
457
- # === :smart_quote
458
- #
459
- # [Category] Span-level element
460
- # [Usage context] Where span-level elements are expected
461
- # [Content model] None
462
- #
463
- # Represents a quotation character.
464
- #
465
- # The +value+ field needs to contain a Symbol representing the specific quotation character:
466
- #
467
- # :lsquo:: Left single quote
468
- # :rsquo:: Right single quote
469
- # :ldquo:: Left double quote
470
- # :rdquo:: Right double quote
471
- #
472
- #
473
- # === :abbreviation
474
- #
475
- # [Category] Span-level element
476
- # [Usage context] Where span-level elements are expected
477
- # [Content model] None
478
- #
479
- # Represents a text part that is an abbreviation.
480
- #
481
- # The +value+ field has to contain the text part that is the abbreviation. The definition of the
482
- # abbreviation is stored in the :root element of the document.
483
- #
484
- #
485
- # == Other Elements
486
- #
487
- # === :html_element
488
- #
489
- # [Category] Block/span-level element
490
- # [Usage context] Where block/span-level elements or raw HTML elements are expected
491
- # [Content model] Depends on the element
492
- #
493
- # Represents an HTML element.
494
- #
495
- # The +value+ field has to contain the name of the HTML element the element is representing.
496
- #
497
- # The option :category has to be set to either :span or :block depending on the whether the
498
- # element is a block-level or a span-level element. The option :content_model has to be set to the
499
- # content model for the element (either :block if it contains block-level elements, :span if it
500
- # contains span-level elements or :raw if it contains raw content).
501
- #
502
- #
503
- # === :xml_comment
504
- #
505
- # [Category] Block/span-level element
506
- # [Usage context] Where block/span-level elements are expected or in raw HTML elements
507
- # [Content model] None
508
- #
509
- # Represents an XML/HTML comment.
510
- #
511
- # The +value+ field has to contain the whole XML/HTML comment including the delimiters.
512
- #
513
- # The option :category has to be set to either :span or :block depending on the context where the
514
- # element is used.
515
- #
516
- #
517
- # === :xml_pi
518
- #
519
- # [Category] Block/span-level element
520
- # [Usage context] Where block/span-level elements are expected or in raw HTML elements
521
- # [Content model] None
522
- #
523
- # Represents an XML/HTML processing instruction.
524
- #
525
- # The +value+ field has to contain the whole XML/HTML processing instruction including the
526
- # delimiters.
527
- #
528
- # The option :category has to be set to either :span or :block depending on the context where the
529
- # element is used.
530
- #
531
- #
532
- # === :comment
533
- #
534
- # [Category] Block/span-level element
535
- # [Usage context] Where block/span-level elements are expected
536
- # [Content model] None
537
- #
538
- # Represents a comment.
539
- #
540
- # The +value+ field has to contain the comment.
541
- #
542
- # The option :category has to be set to either :span or :block depending on the context where the
543
- # element is used.
544
- #
545
- #
546
- # === :raw
547
- #
548
- # [Category] Block/span-level element
549
- # [Usage context] Where block/span-level elements are expected
550
- # [Content model] None
551
- #
552
- # Represents a raw string that should not be modified. For example, the element could contain some
553
- # HTML code that should be output as-is without modification and escaping.
554
- #
555
- # The +value+ field has to contain the actual raw text.
556
- #
557
- # The option :category has to be set to either :span or :block depending on the context where the
558
- # element is used. The option :type can be set to an array of strings to define for which
559
- # converters the raw string is valid.
560
- class Element
561
-
562
- # A symbol representing the element type. For example, :p or :blockquote.
563
- attr_accessor :type
564
-
565
- # The value of the element. The interpretation of this field depends on the type of the element.
566
- # Many elements don't use this field.
567
- attr_accessor :value
568
-
569
- # The child elements of this element.
570
- attr_accessor :children
571
-
572
-
573
- # Create a new Element object of type +type+. The optional parameters +value+, +attr+ and
574
- # +options+ can also be set in this constructor for convenience.
575
- def initialize(type, value = nil, attr = nil, options = nil)
576
- @type, @value, @attr, @options = type, value, (Utils::OrderedHash.new.merge!(attr) if attr), options
577
- @children = []
578
- end
579
-
580
- # The attributes of the element. Uses an Utils::OrderedHash to retain the insertion order.
581
- def attr
582
- @attr ||= Utils::OrderedHash.new
583
- end
584
-
585
- # The options hash for the element. It is used for storing arbitray options.
586
- def options
587
- @options ||= {}
588
- end
589
-
590
- def inspect #:nodoc:
591
- "<kd:#{@type}#{@value.nil? ? '' : ' ' + @value.inspect} #{@attr.inspect}#{options.empty? ? '' : ' ' + @options.inspect}#{@children.empty? ? '' : ' ' + @children.inspect}>"
592
- end
593
-
594
- CATEGORY = {} # :nodoc:
595
- [:blank, :p, :header, :blockquote, :codeblock, :ul, :ol, :dl, :table, :hr].each {|b| CATEGORY[b] = :block}
596
- [:text, :a, :br, :img, :codespan, :footnote, :em, :strong, :entity, :typographic_sym,
597
- :smart_quote, :abbreviation].each {|b| CATEGORY[b] = :span}
598
-
599
- # Return the category of +el+ which can be :block, :span or +nil+.
600
- #
601
- # Most elements have a fixed category, however, some elements can either appear in a block-level
602
- # or a span-level context. These elements need to have the option :category correctly set.
603
- def self.category(el)
604
- CATEGORY[el.type] || el.options[:category]
605
- end
606
-
607
- end
608
-
609
116
  end
610
117