kramdown 0.13.7 → 0.13.8

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.

@@ -117,7 +117,7 @@ module Kramdown
117
117
  end
118
118
 
119
119
  def convert_header(el, opts)
120
- type = @options[:latex_headers][el.options[:level] - 1]
120
+ type = @options[:latex_headers][output_header_level(el.options[:level]) - 1]
121
121
  if ((id = el.attr['id']) ||
122
122
  (@options[:auto_ids] && (id = generate_id(el.options[:raw_text])))) && in_toc?(el)
123
123
  "\\#{type}{#{inner(el, opts)}}\\hypertarget{#{id}}{}\\label{#{id}}\n\n"
@@ -19,6 +19,35 @@
19
19
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
  #++
21
21
  #
22
+ # = kramdown
23
+ #
24
+ # kramdown is yet-another-markdown-parser but fast, pure Ruby, using a strict syntax definition and
25
+ # supporting several common extensions.
26
+ #
27
+ # The kramdown library is mainly written to support the kramdown-to-HTML conversion chain. However,
28
+ # due to its flexibility it supports other input and output formats as well. Here is a list of the
29
+ # supported formats:
30
+ #
31
+ # * input formats: kramdown (a Markdown superset), Markdown, HTML
32
+ # * output formats: HTML, kramdown, LaTeX (and therefore PDF)
33
+ #
34
+ # All the documentation on the available input and output formats is available at
35
+ # http://kramdown.rubyforge.org.
36
+ #
37
+ # == Usage
38
+ #
39
+ # kramdown has a basic *Cloth API, so using kramdown is as easy as
40
+ #
41
+ # require 'kramdown'
42
+ #
43
+ # Kramdown::Document.new(text).to_html
44
+ #
45
+ # For detailed information have a look at the Kramdown::Document class.
46
+ #
47
+ # == License
48
+ #
49
+ # GPLv3 - see the COPYING file.
50
+
22
51
 
23
52
  require 'kramdown/compatibility'
24
53
 
@@ -241,6 +241,16 @@ footnote.
241
241
 
242
242
  Default: 1
243
243
  Used by: HTML converter
244
+ EOF
245
+
246
+ define(:enable_coderay, Boolean, true, <<EOF)
247
+ Use coderay for syntax highlighting
248
+
249
+ If this option is `true`, coderay is used by the HTML converter for
250
+ syntax highlighting the content of code spans and code blocks.
251
+
252
+ Default: true
253
+ Used by: HTML converter
244
254
  EOF
245
255
 
246
256
  define(:coderay_wrap, Symbol, :div, <<EOF)
@@ -294,7 +304,7 @@ Used by: HTML converter
294
304
  EOF
295
305
 
296
306
  define(:coderay_default_lang, Symbol, nil, <<EOF)
297
- Sets the default language for highlighting.
307
+ Sets the default language for highlighting code blocks
298
308
 
299
309
  If no language is set for a code block, the default language is used
300
310
  instead. The value has to be one of the languages supported by coderay
@@ -359,7 +369,7 @@ Defines the LaTeX commands for different header levels
359
369
  The commands for the header levels one to six can be specified by
360
370
  separating them with commas.
361
371
 
362
- Default: section,subsection,subsubsection,paragraph,subparagraph,subsubparagraph
372
+ Default: section,subsection,subsubsection,paragraph,subparagraph,subparagraph
363
373
  Used by: Latex converter
364
374
  EOF
365
375
  simple_array_validator(val, :latex_headers, 6)
@@ -399,6 +409,17 @@ span HTML tags.
399
409
 
400
410
  Default: false
401
411
  Used by: RemoveHtmlTags converter
412
+ EOF
413
+
414
+ define(:header_offset, Integer, 0, <<EOF)
415
+ Sets the output offset for headers
416
+
417
+ If this option is c (may also be negative) then a header with level n
418
+ will be output as a header with level c+n. If c+n is lower than 1,
419
+ level 1 will be used. If c+n is greater than 6, level 6 will be used.
420
+
421
+ Default: 0
422
+ Used by: HTML converter, Kramdown converter, Latex converter
402
423
  EOF
403
424
 
404
425
  end
@@ -42,7 +42,8 @@ module Kramdown
42
42
  def replace_abbreviations(el, regexps = nil)
43
43
  return if @root.options[:abbrev_defs].empty?
44
44
  if !regexps
45
- regexps = [Regexp.union(*@root.options[:abbrev_defs].keys.map {|k| /#{Regexp.escape(k)}/})]
45
+ sorted_abbrevs = @root.options[:abbrev_defs].keys.sort {|a,b| b.length <=> a.length}
46
+ regexps = [Regexp.union(*sorted_abbrevs.map {|k| /#{Regexp.escape(k)}/})]
46
47
  regexps << /(?=(?:\W|^)#{regexps.first}(?!\w))/ # regexp should only match on word boundaries
47
48
  end
48
49
  el.children.map! do |child|
@@ -23,6 +23,6 @@
23
23
  module Kramdown
24
24
 
25
25
  # The kramdown version.
26
- VERSION = '0.13.7'
26
+ VERSION = '0.13.8'
27
27
 
28
28
  end
@@ -35,66 +35,78 @@ Show the help.
35
35
  .SH KRAMDOWN OPTIONS
36
36
 
37
37
  .TP
38
- .B \-\-[no\-]remove-span-html-tags
38
+ .B \-\-template ARG
39
39
 
40
- Remove span HTML tags
40
+ The name of an ERB template file that should be used to wrap the output
41
41
 
42
- If this option is `true`, the RemoveHtmlTags converter removes
43
- span HTML tags.
42
+ This is used to wrap the output in an environment so that the output can
43
+ be used as a stand-alone document. For example, an HTML template would
44
+ provide the needed header and body tags so that the whole output is a
45
+ valid HTML file. If no template is specified, the output will be just
46
+ the converted text.
44
47
 
45
- Default: false
46
- Used by: RemoveHtmlTags converter
48
+ When resolving the template file, the given template name is used first.
49
+ If such a file is not found, the converter extension is appended. If the
50
+ file still cannot be found, the templates name is interpreted as a
51
+ template name that is provided by kramdown (without the converter
52
+ extension).
53
+
54
+ kramdown provides a default template named 'document' for each converter.
55
+
56
+ Default: ''
57
+ Used by: all converters
47
58
 
48
59
 
49
60
  .TP
50
- .B \-\-coderay-tab-width ARG
61
+ .B \-\-[no\-]auto-ids
51
62
 
52
- The tab width used in highlighted code
63
+ Use automatic header ID generation
53
64
 
54
- Used by: HTML converter
65
+ If this option is `true`, ID values for all headers are automatically
66
+ generated if no ID is explicitly specified.
67
+
68
+ Default: true
69
+ Used by: HTML/Latex converter
55
70
 
56
71
 
57
72
  .TP
58
- .B \-\-toc-levels ARG
73
+ .B \-\-auto-id-prefix ARG
59
74
 
60
- Defines the levels that are used for the table of contents
75
+ Prefix used for automatically generated heaer IDs
61
76
 
62
- The individual levels can be specified by separating them with commas
63
- (e.g. 1,2,3) or by using the range syntax (e.g. 1..3). Only the
64
- specified levels are used for the table of contents.
77
+ This option can be used to set a prefix for the automatically generated
78
+ header IDs so that there is no conflict when rendering multiple kramdown
79
+ documents into one output file separately. The prefix should only
80
+ contain characters that are valid in an ID!
65
81
 
66
- Default: 1..6
82
+ Default: ''
67
83
  Used by: HTML/Latex converter
68
84
 
69
85
 
70
86
  .TP
71
- .B \-\-[no\-]parse-span-html
87
+ .B \-\-[no\-]parse-block-html
72
88
 
73
- Process kramdown syntax in span HTML tags
89
+ Process kramdown syntax in block HTML tags
74
90
 
75
91
  If this option is `true`, the kramdown parser processes the content of
76
- span HTML tags as text containing span-level elements.
92
+ block HTML tags as text containing block-level elements. Since this is
93
+ not wanted normally, the default is `false`. It is normally better to
94
+ selectively enable kramdown processing via the markdown attribute.
77
95
 
78
- Default: true
96
+ Default: false
79
97
  Used by: kramdown parser
80
98
 
81
99
 
82
100
  .TP
83
- .B \-\-coderay-bold-every ARG
84
-
85
- Defines how often a line number should be made bold
86
-
87
- Default: 10
88
- Used by: HTML converter
89
-
101
+ .B \-\-[no\-]parse-span-html
90
102
 
91
- .TP
92
- .B \-\-line-width ARG
103
+ Process kramdown syntax in span HTML tags
93
104
 
94
- Defines the line width to be used when outputting a document
105
+ If this option is `true`, the kramdown parser processes the content of
106
+ span HTML tags as text containing span-level elements.
95
107
 
96
- Default: 72
97
- Used by: kramdown converter
108
+ Default: true
109
+ Used by: kramdown parser
98
110
 
99
111
 
100
112
  .TP
@@ -115,112 +127,101 @@ Used by: kramdown parser
115
127
 
116
128
 
117
129
  .TP
118
- .B \-\-coderay-css ARG
130
+ .B \-\-footnote-nr ARG
119
131
 
120
- Defines how the highlighted code gets styled
132
+ The number of the first footnote
121
133
 
122
- Possible values are :class (CSS classes are applied to the code
123
- elements, one must supply the needed CSS file) or :style (default CSS
124
- styles are directly applied to the code elements).
134
+ This option can be used to specify the number that is used for the first
135
+ footnote.
125
136
 
126
- Default: style
137
+ Default: 1
127
138
  Used by: HTML converter
128
139
 
129
140
 
130
141
  .TP
131
- .B \-\-latex-headers ARG
142
+ .B \-\-[no\-]enable-coderay
132
143
 
133
- Defines the LaTeX commands for different header levels
144
+ Use coderay for syntax highlighting
134
145
 
135
- The commands for the header levels one to six can be specified by
136
- separating them with commas.
146
+ If this option is `true`, coderay is used by the HTML converter for
147
+ syntax highlighting the content of code spans and code blocks.
137
148
 
138
- Default: section,subsection,subsubsection,paragraph,subparagraph,subsubparagraph
139
- Used by: Latex converter
149
+ Default: true
150
+ Used by: HTML converter
140
151
 
141
152
 
142
153
  .TP
143
- .B \-\-footnote-nr ARG
154
+ .B \-\-coderay-wrap ARG
144
155
 
145
- The number of the first footnote
156
+ Defines how the highlighted code should be wrapped
146
157
 
147
- This option can be used to specify the number that is used for the first
148
- footnote.
158
+ The possible values are :span, :div or nil.
149
159
 
150
- Default: 1
160
+ Default: :div
151
161
  Used by: HTML converter
152
162
 
153
163
 
154
164
  .TP
155
- .B \-\-template ARG
165
+ .B \-\-coderay-line-numbers ARG
156
166
 
157
- The name of an ERB template file that should be used to wrap the output
167
+ Defines how and if line numbers should be shown
158
168
 
159
- This is used to wrap the output in an environment so that the output can
160
- be used as a stand-alone document. For example, an HTML template would
161
- provide the needed header and body tags so that the whole output is a
162
- valid HTML file. If no template is specified, the output will be just
163
- the converted text.
169
+ The possible values are :table, :inline or nil. If this option is
170
+ nil, no line numbers are shown.
164
171
 
165
- When resolving the template file, the given template name is used first.
166
- If such a file is not found, the converter extension is appended. If the
167
- file still cannot be found, the templates name is interpreted as a
168
- template name that is provided by kramdown (without the converter
169
- extension).
172
+ Default: :inline
173
+ Used by: HTML converter
170
174
 
171
- kramdown provides a default template named 'document' for each converter.
172
175
 
173
- Default: ''
174
- Used by: all converters
176
+ .TP
177
+ .B \-\-coderay-line-number-start ARG
175
178
 
179
+ The start value for the line numbers
176
180
 
177
- .TP
178
- .B \-\-coderay-default-lang ARG
181
+ Default: 1
182
+ Used by: HTML converter
179
183
 
180
- Sets the default language for highlighting.
181
184
 
182
- If no language is set for a code block, the default language is used
183
- instead. The value has to be one of the languages supported by coderay
184
- or nil if no default language should be used.
185
+ .TP
186
+ .B \-\-coderay-tab-width ARG
187
+
188
+ The tab width used in highlighted code
185
189
 
186
- Default: nil
187
190
  Used by: HTML converter
188
191
 
189
192
 
190
193
  .TP
191
- .B \-\-coderay-line-numbers ARG
192
-
193
- Defines how and if line numbers should be shown
194
+ .B \-\-coderay-bold-every ARG
194
195
 
195
- The possible values are :table, :inline or nil. If this option is
196
- nil, no line numbers are shown.
196
+ Defines how often a line number should be made bold
197
197
 
198
- Default: :inline
198
+ Default: 10
199
199
  Used by: HTML converter
200
200
 
201
201
 
202
202
  .TP
203
- .B \-\-smart-quotes ARG
203
+ .B \-\-coderay-css ARG
204
204
 
205
- Defines the HTML entity names or code points for smart quote output
205
+ Defines how the highlighted code gets styled
206
206
 
207
- The entities identified by entity name or code point that should be
208
- used for, in order, a left single quote, a right single quote, a left
209
- double and a right double quote are specified by separating them with
210
- commas.
207
+ Possible values are :class (CSS classes are applied to the code
208
+ elements, one must supply the needed CSS file) or :style (default CSS
209
+ styles are directly applied to the code elements).
211
210
 
212
- Default: lsquo,rsquo,ldquo,rdquo
213
- Used by: HTML/Latex converter
211
+ Default: style
212
+ Used by: HTML converter
214
213
 
215
214
 
216
215
  .TP
217
- .B \-\-coderay-wrap ARG
216
+ .B \-\-coderay-default-lang ARG
218
217
 
219
- Defines how the highlighted code should be wrapped
218
+ Sets the default language for highlighting code blocks
220
219
 
221
- The possible values are :span, :div or nil.
220
+ If no language is set for a code block, the default language is used
221
+ instead. The value has to be one of the languages supported by coderay
222
+ or nil if no default language should be used.
222
223
 
223
- Default: :div
224
+ Default: nil
224
225
  Used by: HTML converter
225
226
 
226
227
 
@@ -240,64 +241,88 @@ Used by: HTML converter, kramdown converter
240
241
 
241
242
 
242
243
  .TP
243
- .B \-\-auto-id-prefix ARG
244
+ .B \-\-toc-levels ARG
244
245
 
245
- Prefix used for automatically generated heaer IDs
246
+ Defines the levels that are used for the table of contents
246
247
 
247
- This option can be used to set a prefix for the automatically generated
248
- header IDs so that there is no conflict when rendering multiple kramdown
249
- documents into one output file separately. The prefix should only
250
- contain characters that are valid in an ID!
248
+ The individual levels can be specified by separating them with commas
249
+ (e.g. 1,2,3) or by using the range syntax (e.g. 1..3). Only the
250
+ specified levels are used for the table of contents.
251
251
 
252
- Default: ''
252
+ Default: 1..6
253
253
  Used by: HTML/Latex converter
254
254
 
255
255
 
256
256
  .TP
257
- .B \-\-[no\-]remove-block-html-tags
257
+ .B \-\-line-width ARG
258
258
 
259
- Remove block HTML tags
259
+ Defines the line width to be used when outputting a document
260
260
 
261
- If this option is `true`, the RemoveHtmlTags converter removes
262
- block HTML tags.
261
+ Default: 72
262
+ Used by: kramdown converter
263
263
 
264
- Default: true
265
- Used by: RemoveHtmlTags converter
264
+
265
+ .TP
266
+ .B \-\-latex-headers ARG
267
+
268
+ Defines the LaTeX commands for different header levels
269
+
270
+ The commands for the header levels one to six can be specified by
271
+ separating them with commas.
272
+
273
+ Default: section,subsection,subsubsection,paragraph,subparagraph,subparagraph
274
+ Used by: Latex converter
266
275
 
267
276
 
268
277
  .TP
269
- .B \-\-coderay-line-number-start ARG
278
+ .B \-\-smart-quotes ARG
270
279
 
271
- The start value for the line numbers
280
+ Defines the HTML entity names or code points for smart quote output
272
281
 
273
- Default: 1
274
- Used by: HTML converter
282
+ The entities identified by entity name or code point that should be
283
+ used for, in order, a left single quote, a right single quote, a left
284
+ double and a right double quote are specified by separating them with
285
+ commas.
286
+
287
+ Default: lsquo,rsquo,ldquo,rdquo
288
+ Used by: HTML/Latex converter
275
289
 
276
290
 
277
291
  .TP
278
- .B \-\-[no\-]auto-ids
292
+ .B \-\-[no\-]remove-block-html-tags
279
293
 
280
- Use automatic header ID generation
294
+ Remove block HTML tags
281
295
 
282
- If this option is `true`, ID values for all headers are automatically
283
- generated if no ID is explicitly specified.
296
+ If this option is `true`, the RemoveHtmlTags converter removes
297
+ block HTML tags.
284
298
 
285
299
  Default: true
286
- Used by: HTML/Latex converter
300
+ Used by: RemoveHtmlTags converter
287
301
 
288
302
 
289
303
  .TP
290
- .B \-\-[no\-]parse-block-html
304
+ .B \-\-[no\-]remove-span-html-tags
291
305
 
292
- Process kramdown syntax in block HTML tags
306
+ Remove span HTML tags
293
307
 
294
- If this option is `true`, the kramdown parser processes the content of
295
- block HTML tags as text containing block-level elements. Since this is
296
- not wanted normally, the default is `false`. It is normally better to
297
- selectively enable kramdown processing via the markdown attribute.
308
+ If this option is `true`, the RemoveHtmlTags converter removes
309
+ span HTML tags.
298
310
 
299
311
  Default: false
300
- Used by: kramdown parser
312
+ Used by: RemoveHtmlTags converter
313
+
314
+
315
+ .TP
316
+ .B \-\-header-offset ARG
317
+
318
+ Sets the output offset for headers
319
+
320
+ If this option is c (may also be negative) then a header with level n
321
+ will be output as a header with level c+n. If c+n is lower than 1,
322
+ level 1 will be used. If c+n is greater than 6, level 6 will be used.
323
+
324
+ Default: 0
325
+ Used by: HTML converter, Kramdown converter, Latex converter
301
326
 
302
327
 
303
328
  .SH EXIT STATUS