kramdown 0.13.8 → 0.14.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.
- data/CONTRIBUTERS +3 -2
- data/ChangeLog +169 -0
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/doc/documentation.page +1 -1
- data/doc/quickref.page +10 -0
- data/doc/sidebar.template +2 -2
- data/doc/syntax.page +32 -3
- data/lib/kramdown/converter/base.rb +18 -1
- data/lib/kramdown/converter/html.rb +12 -9
- data/lib/kramdown/converter/latex.rb +1 -1
- data/lib/kramdown/parser/base.rb +2 -2
- data/lib/kramdown/parser/html.rb +7 -2
- data/lib/kramdown/parser/kramdown/autolink.rb +1 -5
- data/lib/kramdown/parser/kramdown/codeblock.rb +5 -2
- data/lib/kramdown/utils/html.rb +7 -5
- data/lib/kramdown/version.rb +1 -1
- data/test/test_files.rb +1 -0
- data/test/testcases/block/04_header/setext_header.html +1 -1
- data/test/testcases/block/04_header/setext_header.text +1 -1
- data/test/testcases/block/06_codeblock/highlighting.text +1 -1
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.html +24 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.options +2 -0
- data/test/testcases/block/06_codeblock/with_lang_in_fenced_block.text +33 -0
- data/test/testcases/block/07_horizontal_rule/error.html +2 -2
- data/test/testcases/block/09_html/html_to_native/typography.html +1 -1
- data/test/testcases/block/12_extension/options3.text +2 -2
- data/test/testcases/block/14_table/simple.html +7 -7
- data/test/testcases/block/16_toc/toc_exclude.html +35 -0
- data/test/testcases/block/16_toc/toc_exclude.options +1 -0
- data/test/testcases/block/16_toc/toc_exclude.text +19 -0
- data/test/testcases/span/01_link/inline.html +1 -1
- data/test/testcases/span/01_link/reference.html +3 -3
- data/test/testcases/span/03_codespan/highlighting.html +1 -1
- data/test/testcases/span/03_codespan/highlighting.text +1 -1
- data/test/testcases/span/text_substitutions/typography.options +1 -0
- metadata +9 -4
- data/test/testcases/block/04_header/setext_header.html.19 +0 -30
- data/test/testcases/span/text_substitutions/typography.html.19 +0 -18
data/CONTRIBUTERS
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
Count Name
|
2
2
|
======= ====
|
3
|
-
|
3
|
+
537 Thomas Leitner <t_leitner@gmx.at>
|
4
|
+
6 Gioele Barabucci <gioele@svario.it>
|
4
5
|
3 gettalong <t_leitner@gmx.at>
|
5
6
|
3 Ben Armston <ben.armston@googlemail.com>
|
6
7
|
3 Alex Marandon <contact@alexmarandon.com>
|
7
8
|
2 Bran <m.versum@gmail.com>
|
8
9
|
1 tomykaira <tomykaira@gmail.com>
|
10
|
+
1 Tim Bates <tim@rumpuslabs.com>
|
9
11
|
1 Postmodern <postmodern.mod3@gmail.com>
|
10
12
|
1 Michal Till <michal.till@gmail.com>
|
11
13
|
1 John Croisant <jacius@gmail.com>
|
12
14
|
1 Joe Fiorini <joe@faithfulgeek.org>
|
13
|
-
1 Gioele Barabucci <gioele@svario.it>
|
14
15
|
1 Damien Pollet <damien.pollet@gmail.com>
|
15
16
|
1 Alex Tomlins <alex.tomlins@digital.cabinet-office.gov.uk>
|
data/ChangeLog
CHANGED
@@ -1,3 +1,145 @@
|
|
1
|
+
commit a29151de6a88eefbd0a181331ebae298ee441d27
|
2
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
3
|
+
Date: Sun Sep 16 07:58:38 2012 +0200
|
4
|
+
|
5
|
+
Updated release notes and version
|
6
|
+
|
7
|
+
doc/news/release_0_14_0.page
|
8
|
+
doc/sidebar.template
|
9
|
+
lib/kramdown/version.rb
|
10
|
+
|
11
|
+
commit eacc89ce68a87bb1d1d68fb76efa5ca2a55bebd1
|
12
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
13
|
+
Date: Wed Sep 12 22:06:29 2012 +0200
|
14
|
+
|
15
|
+
Backwards incompatible change: code language now specified via special class
|
16
|
+
|
17
|
+
Using lang='LANGUAGE' for specifying the code language of code
|
18
|
+
blocks/spans is not good because it conflicts with the normal
|
19
|
+
usage of the lang attr.
|
20
|
+
|
21
|
+
Therefore the code language must now be specified via a special
|
22
|
+
class 'language-LANGUAGE' which is also the way how it is done
|
23
|
+
in the HTML5 spec.
|
24
|
+
|
25
|
+
doc/converter/html.page
|
26
|
+
doc/documentation.page
|
27
|
+
doc/news/release_0_5_0.page
|
28
|
+
lib/kramdown/converter/base.rb
|
29
|
+
lib/kramdown/converter/html.rb
|
30
|
+
lib/kramdown/converter/latex.rb
|
31
|
+
lib/kramdown/parser/html.rb
|
32
|
+
lib/kramdown/parser/kramdown/codeblock.rb
|
33
|
+
test/testcases/block/06_codeblock/highlighting.text
|
34
|
+
test/testcases/block/06_codeblock/with_lang_in_fenced_block.html
|
35
|
+
test/testcases/block/06_codeblock/with_lang_in_fenced_block.text
|
36
|
+
test/testcases/block/12_extension/options3.text
|
37
|
+
test/testcases/span/03_codespan/highlighting.html
|
38
|
+
test/testcases/span/03_codespan/highlighting.text
|
39
|
+
|
40
|
+
commit f7424c0c9d38aea6ad781ad66d19a2a4d429263e
|
41
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
42
|
+
Date: Wed Sep 12 21:37:20 2012 +0200
|
43
|
+
|
44
|
+
Fixed typo in syntax doc
|
45
|
+
|
46
|
+
doc/syntax.page
|
47
|
+
|
48
|
+
commit 967b6dac2ae71638ba00a5ac67dd0f2d9e7d60d2
|
49
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
50
|
+
Date: Wed Sep 12 20:50:35 2012 +0200
|
51
|
+
|
52
|
+
Implemented support for setting language on fenced code block starting line
|
53
|
+
|
54
|
+
Patch based on a series of commits by @unibr (Bran) with some needed fixes
|
55
|
+
|
56
|
+
doc/quickref.page
|
57
|
+
doc/syntax.page
|
58
|
+
lib/kramdown/parser/kramdown/codeblock.rb
|
59
|
+
test/testcases/block/06_codeblock/with_lang_in_fenced_block.html
|
60
|
+
test/testcases/block/06_codeblock/with_lang_in_fenced_block.options
|
61
|
+
test/testcases/block/06_codeblock/with_lang_in_fenced_block.text
|
62
|
+
|
63
|
+
commit fb903f8fd1ae1ed3a37f3adae41b5e48f72d16ba
|
64
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
65
|
+
Date: Fri Sep 7 17:09:01 2012 +0200
|
66
|
+
|
67
|
+
Added failing test case to exclusion list
|
68
|
+
|
69
|
+
test/test_files.rb
|
70
|
+
|
71
|
+
commit 6fdc0ca4483ead67adbb2034f85b81c8529a4451
|
72
|
+
Merge: 4d4e5f6 f2ccb8e
|
73
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
74
|
+
Date: Fri Sep 7 16:06:19 2012 +0200
|
75
|
+
|
76
|
+
Merge branch 'notoc' of https://github.com/rumpuslabs/kramdown
|
77
|
+
|
78
|
+
commit f2ccb8e9e9ead6ca90f039e0e8d9e5af7b86409d
|
79
|
+
Author: Tim Bates <tim@rumpuslabs.com>
|
80
|
+
Date: Wed Sep 5 23:27:32 2012 +0930
|
81
|
+
|
82
|
+
Exclude headers from TOC using `.no_toc` class.
|
83
|
+
|
84
|
+
Applying {:.no_toc} to a header will prevent it from being included in
|
85
|
+
the table of contents.
|
86
|
+
|
87
|
+
doc/converter/html.page
|
88
|
+
lib/kramdown/converter/base.rb
|
89
|
+
test/testcases/block/16_toc/toc_exclude.html
|
90
|
+
test/testcases/block/16_toc/toc_exclude.options
|
91
|
+
test/testcases/block/16_toc/toc_exclude.text
|
92
|
+
|
93
|
+
commit 4d4e5f6471d395f554833ecd8899dc42bf509971
|
94
|
+
Author: Gioele Barabucci <gioele@svario.it>
|
95
|
+
Date: Wed Aug 29 19:55:57 2012 +0200
|
96
|
+
|
97
|
+
Use Unicode regexes on Ruby 1.8.x and 1.9.x
|
98
|
+
|
99
|
+
lib/kramdown/parser/kramdown/autolink.rb
|
100
|
+
|
101
|
+
commit 51315236ee6d2bdee4ec6cddd32b7c82408c34ec
|
102
|
+
Author: Gioele Barabucci <gioele@svario.it>
|
103
|
+
Date: Wed Aug 29 19:51:53 2012 +0200
|
104
|
+
|
105
|
+
Check for encoding support instead of version string
|
106
|
+
|
107
|
+
lib/kramdown/converter/html.rb
|
108
|
+
lib/kramdown/parser/base.rb
|
109
|
+
lib/kramdown/parser/html.rb
|
110
|
+
|
111
|
+
commit 4bd036c0df4eacc31ee0e7b5b38c9ec5164f86ab
|
112
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
113
|
+
Date: Tue Sep 4 17:26:38 2012 +0200
|
114
|
+
|
115
|
+
Fixed test cases to correspond with new default entity fallback
|
116
|
+
|
117
|
+
test/testcases/block/04_header/setext_header.html
|
118
|
+
test/testcases/block/04_header/setext_header.html.19
|
119
|
+
test/testcases/block/04_header/setext_header.text
|
120
|
+
test/testcases/block/07_horizontal_rule/error.html
|
121
|
+
test/testcases/block/09_html/html_to_native/typography.html
|
122
|
+
test/testcases/block/14_table/simple.html
|
123
|
+
test/testcases/span/01_link/inline.html
|
124
|
+
test/testcases/span/01_link/reference.html
|
125
|
+
test/testcases/span/text_substitutions/typography.html.19
|
126
|
+
test/testcases/span/text_substitutions/typography.options
|
127
|
+
|
128
|
+
commit c41870969ca13535ac16b564eb5ab34833d001e3
|
129
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
130
|
+
Date: Tue Sep 4 16:59:51 2012 +0200
|
131
|
+
|
132
|
+
Use symbolic entities as default fallback for predefined XML entities
|
133
|
+
|
134
|
+
lib/kramdown/utils/html.rb
|
135
|
+
|
136
|
+
commit ec5bf062031cb1116d1b45b7d85955a9e651cfde
|
137
|
+
Merge: 69fbdcb 462c80c
|
138
|
+
Author: Thomas Leitner <t_leitner@gmx.at>
|
139
|
+
Date: Tue Sep 4 16:47:12 2012 +0200
|
140
|
+
|
141
|
+
Merge branch 'num-entities' of https://github.com/gioele/kramdown
|
142
|
+
|
1
143
|
commit 69fbdcbf2b3585f92819f941f695f2ab10d2051f
|
2
144
|
Author: Thomas Leitner <t_leitner@gmx.at>
|
3
145
|
Date: Fri Aug 31 18:35:39 2012 +0200
|
@@ -85,6 +227,17 @@ test/testcases/block/06_codeblock/disable-highlighting.html
|
|
85
227
|
test/testcases/block/06_codeblock/disable-highlighting.options
|
86
228
|
test/testcases/block/06_codeblock/disable-highlighting.text
|
87
229
|
|
230
|
+
commit 462c80c67ea839b84e2a2c5bf6d3a752cb7cf9cc
|
231
|
+
Author: Gioele Barabucci <gioele@svario.it>
|
232
|
+
Date: Wed Aug 29 19:06:58 2012 +0200
|
233
|
+
|
234
|
+
Use numeric entities as default fallback if :as_code is not available
|
235
|
+
|
236
|
+
Numeric entities can be used directly both in HTML, XHTML, and XML files. On
|
237
|
+
the contrary, symbolic entities are allowed only in HTML files.
|
238
|
+
|
239
|
+
lib/kramdown/utils/html.rb
|
240
|
+
|
88
241
|
commit df8ff9df6968993e73fcc3a8a08db94e4683a23d
|
89
242
|
Author: Gioele Barabucci <gioele@svario.it>
|
90
243
|
Date: Wed Aug 29 18:52:39 2012 +0200
|
@@ -96,6 +249,22 @@ Date: Wed Aug 29 18:52:39 2012 +0200
|
|
96
249
|
|
97
250
|
Rakefile
|
98
251
|
|
252
|
+
commit a08339310d066b81e55f3bc488ac33892135eee3
|
253
|
+
Author: Gioele Barabucci <gioele@svario.it>
|
254
|
+
Date: Wed Aug 29 18:52:05 2012 +0200
|
255
|
+
|
256
|
+
Check for method existence instead of Ruby version
|
257
|
+
|
258
|
+
lib/kramdown/utils/html.rb
|
259
|
+
|
260
|
+
commit 245c79ccb8c6410d807ce51e429abe4de322ba86
|
261
|
+
Author: Gioele Barabucci <gioele@svario.it>
|
262
|
+
Date: Wed Aug 29 18:45:23 2012 +0200
|
263
|
+
|
264
|
+
Read entity output configuration only once
|
265
|
+
|
266
|
+
lib/kramdown/utils/html.rb
|
267
|
+
|
99
268
|
commit 46bd5f670b674fe3dcd310069e334ac4d7a0b008
|
100
269
|
Author: Thomas Leitner <t_leitner@gmx.at>
|
101
270
|
Date: Tue Aug 28 18:12:07 2012 +0200
|
data/Rakefile
CHANGED
@@ -85,7 +85,6 @@ if defined? Webgen
|
|
85
85
|
Webgen::WebgenTask.new('htmldoc') do |site|
|
86
86
|
site.clobber_outdir = true
|
87
87
|
site.config_block = lambda do |config|
|
88
|
-
YAML::ENGINE.yamler = 'syck'
|
89
88
|
config['sources'] = [['/', "Webgen::Source::FileSystem", 'doc']]
|
90
89
|
config['output'] = ['Webgen::Output::FileSystem', 'htmldoc']
|
91
90
|
config.default_processing_pipeline('Page' => 'erb,tags,kramdown,blocks,fragments')
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.14.0
|
data/doc/documentation.page
CHANGED
data/doc/quickref.page
CHANGED
@@ -147,6 +147,16 @@ many tildes as the starting line.
|
|
147
147
|
~~~~~~~~~~~~
|
148
148
|
{kdexample}
|
149
149
|
|
150
|
+
The following is a code block with a language specified:
|
151
|
+
|
152
|
+
{kdexample::}
|
153
|
+
~~~ ruby
|
154
|
+
def what?
|
155
|
+
42
|
156
|
+
end
|
157
|
+
~~~
|
158
|
+
{kdexample}
|
159
|
+
|
150
160
|
|
151
161
|
## Horizontal Rules
|
152
162
|
|
data/doc/sidebar.template
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<h2>News</h2>
|
2
2
|
|
3
|
-
<p>The latest version of kramdown is <b>0.
|
4
|
-
on <b>2012-
|
3
|
+
<p>The latest version of kramdown is <b>0.14.0</b> and it was released
|
4
|
+
on <b>2012-09-16</b>.</p>
|
5
5
|
|
6
6
|
<p>More <a href="{relocatable: news.html}">news</a>…</p>
|
7
7
|
|
data/doc/syntax.page
CHANGED
@@ -399,6 +399,30 @@ example:
|
|
399
399
|
This type of code block is especially useful for copy-pasted code since you don't need to indent the
|
400
400
|
code.
|
401
401
|
|
402
|
+
### Language of Code Blocks
|
403
|
+
|
404
|
+
You can tell kramdown the language of a code block by using an [IAL](#inline-attribute-lists):
|
405
|
+
|
406
|
+
~~~
|
407
|
+
def what?
|
408
|
+
42
|
409
|
+
end
|
410
|
+
~~~
|
411
|
+
{: .language-ruby}
|
412
|
+
|
413
|
+
The specially named class `language-ruby` tells kramdown that this code block is written in the Ruby
|
414
|
+
language. Such information can be used, for example, by converters to do syntax highlighting on the
|
415
|
+
code block.
|
416
|
+
|
417
|
+
Fenced code blocks provide an easier way to specify the language, namely by appending the language
|
418
|
+
of the code block to the end of the starting line:
|
419
|
+
|
420
|
+
~~~ ruby
|
421
|
+
def what?
|
422
|
+
42
|
423
|
+
end
|
424
|
+
~~~
|
425
|
+
|
402
426
|
|
403
427
|
## Lists
|
404
428
|
|
@@ -1229,8 +1253,8 @@ want to force the literal meaning of an asterisk or an underscore you can backsl
|
|
1229
1253
|
|
1230
1254
|
## Code Spans
|
1231
1255
|
|
1232
|
-
This is the span-level equivalent of the code block element. You can markup a text
|
1233
|
-
by surrounding it with backticks `` ` ``. For example:
|
1256
|
+
This is the span-level equivalent of the [code block](#code-blocks) element. You can markup a text
|
1257
|
+
part as code span by surrounding it with backticks `` ` ``. For example:
|
1234
1258
|
|
1235
1259
|
Use `<html>` tags for this.
|
1236
1260
|
|
@@ -1252,6 +1276,11 @@ literal meaning of a backtick you can backslash-escape it:
|
|
1252
1276
|
This is a ` literal backtick.
|
1253
1277
|
As \`are\` these!
|
1254
1278
|
|
1279
|
+
As with [code blocks](#language-of-code-blocks) you can set the language of a code span by using an
|
1280
|
+
[IAL](#inline-attribute-lists):
|
1281
|
+
|
1282
|
+
This is a Ruby code fragment `x = Class.new`{:.language-ruby}
|
1283
|
+
|
1255
1284
|
|
1256
1285
|
## HTML Spans
|
1257
1286
|
|
@@ -1531,7 +1560,7 @@ class names
|
|
1531
1560
|
{:id: .cls1 .cls2}
|
1532
1561
|
{:id: class="cls1" .cls2}
|
1533
1562
|
{:id: class="something" class="cls1" .cls2}
|
1534
|
-
{:id: class="cls1 cls2}
|
1563
|
+
{:id: class="cls1 cls2"}
|
1535
1564
|
|
1536
1565
|
As can be seen from the example of the class names, attributes that are defined earlier are
|
1537
1566
|
overwritten by ones with the same name defined later.
|
@@ -132,7 +132,7 @@ module Kramdown
|
|
132
132
|
# Return +true+ if the header element +el+ should be used for the table of contents (as
|
133
133
|
# specified by the +toc_levels+ option).
|
134
134
|
def in_toc?(el)
|
135
|
-
@options[:toc_levels].include?(el.options[:level])
|
135
|
+
@options[:toc_levels].include?(el.options[:level]) and ((not el.attr['class'].split.include?('no_toc')) rescue true)
|
136
136
|
end
|
137
137
|
|
138
138
|
# Return the output header level given a level.
|
@@ -142,6 +142,23 @@ module Kramdown
|
|
142
142
|
[[level + @options[:header_offset], 6].min, 1].max
|
143
143
|
end
|
144
144
|
|
145
|
+
# Extract the code block/span language from the attributes.
|
146
|
+
def extract_code_language(attr)
|
147
|
+
if attr['class'] && attr['class'] =~ /\blanguage-\w+\b/
|
148
|
+
attr['class'].scan(/\blanguage-(\w+)\b/).first.first
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# See #extract_code_language
|
153
|
+
#
|
154
|
+
# *Warning*: This version will modify the given attributes if a language is present.
|
155
|
+
def extract_code_language!(attr)
|
156
|
+
lang = extract_code_language(attr)
|
157
|
+
attr['class'] = attr['class'].sub(/\blanguage-\w+\b/, '').strip if lang
|
158
|
+
attr.delete('class') if lang && attr['class'].empty?
|
159
|
+
lang
|
160
|
+
end
|
161
|
+
|
145
162
|
# Generate an unique alpha-numeric ID from the the string +str+ for use as a header ID.
|
146
163
|
#
|
147
164
|
# Uses the option +auto_id_prefix+: the value of this option is prepended to every generated
|
@@ -109,12 +109,13 @@ module Kramdown
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def convert_codeblock(el, indent)
|
112
|
-
|
113
|
-
|
112
|
+
attr = el.attr.dup
|
113
|
+
lang = extract_code_language!(attr)
|
114
|
+
if @coderay_enabled && (lang || @options[:coderay_default_lang])
|
114
115
|
opts = {:wrap => @options[:coderay_wrap], :line_numbers => @options[:coderay_line_numbers],
|
115
116
|
:line_number_start => @options[:coderay_line_number_start], :tab_width => @options[:coderay_tab_width],
|
116
117
|
:bold_every => @options[:coderay_bold_every], :css => @options[:coderay_css]}
|
117
|
-
lang = (
|
118
|
+
lang = (lang || @options[:coderay_default_lang]).to_sym
|
118
119
|
result = CodeRay.scan(el.value, lang).html(opts).chomp << "\n"
|
119
120
|
"#{' '*indent}<div#{html_attributes(attr)}>#{result}#{' '*indent}</div>\n"
|
120
121
|
else
|
@@ -131,7 +132,9 @@ module Kramdown
|
|
131
132
|
end.join('')
|
132
133
|
end
|
133
134
|
end
|
134
|
-
|
135
|
+
code_attr = {}
|
136
|
+
code_attr['class'] = "language-#{lang}" if lang
|
137
|
+
"#{' '*indent}<pre#{html_attributes(attr)}><code#{html_attributes(code_attr)}>#{result}\n</code></pre>\n"
|
135
138
|
end
|
136
139
|
end
|
137
140
|
|
@@ -267,10 +270,10 @@ module Kramdown
|
|
267
270
|
end
|
268
271
|
|
269
272
|
def convert_codespan(el, indent)
|
270
|
-
|
271
|
-
|
272
|
-
result = CodeRay.scan(el.value,
|
273
|
-
"<code#{html_attributes(attr)}>#{result}</code>"
|
273
|
+
lang = extract_code_language(el.attr)
|
274
|
+
if @coderay_enabled && lang
|
275
|
+
result = CodeRay.scan(el.value, lang.to_sym).html(:wrap => :span, :css => @options[:coderay_css]).chomp
|
276
|
+
"<code#{html_attributes(el.attr)}>#{result}</code>"
|
274
277
|
else
|
275
278
|
"<code#{html_attributes(el.attr)}>#{escape_html(el.value)}</code>"
|
276
279
|
end
|
@@ -393,7 +396,7 @@ module Kramdown
|
|
393
396
|
text.each_byte do |b|
|
394
397
|
result << (b > 128 ? b.chr : "&#%03d;" % b)
|
395
398
|
end
|
396
|
-
result.force_encoding(text.encoding) if
|
399
|
+
result.force_encoding(text.encoding) if result.respond_to?(:force_encoding)
|
397
400
|
result
|
398
401
|
end
|
399
402
|
|
@@ -97,7 +97,7 @@ module Kramdown
|
|
97
97
|
|
98
98
|
def convert_codeblock(el, opts)
|
99
99
|
show_whitespace = el.attr['class'].to_s =~ /\bshow-whitespaces\b/
|
100
|
-
lang = el.attr
|
100
|
+
lang = extract_code_language(el.attr)
|
101
101
|
if show_whitespace || lang
|
102
102
|
options = []
|
103
103
|
options << "showspaces=%s,showtabs=%s" % (show_whitespace ? ['true', 'true'] : ['false', 'false'])
|
data/lib/kramdown/parser/base.rb
CHANGED
@@ -62,7 +62,7 @@ module Kramdown
|
|
62
62
|
def initialize(source, options)
|
63
63
|
@source = source
|
64
64
|
@options = Kramdown::Options.merge(options)
|
65
|
-
@root = Element.new(:root, nil, nil, :encoding => (
|
65
|
+
@root = Element.new(:root, nil, nil, :encoding => (source.encoding rescue nil))
|
66
66
|
@warnings = []
|
67
67
|
@text_type = :text
|
68
68
|
end
|
@@ -115,7 +115,7 @@ module Kramdown
|
|
115
115
|
# method works correctly under Ruby 1.8 and Ruby 1.9.
|
116
116
|
def extract_string(range, strscan)
|
117
117
|
result = nil
|
118
|
-
if
|
118
|
+
if strscan.string.respond_to?(:encoding)
|
119
119
|
begin
|
120
120
|
enc = strscan.string.encoding
|
121
121
|
strscan.string.force_encoding('ASCII-8BIT')
|
data/lib/kramdown/parser/html.rb
CHANGED
@@ -383,8 +383,9 @@ module Kramdown
|
|
383
383
|
if c.type == :text
|
384
384
|
mem << c.value
|
385
385
|
elsif c.type == :entity
|
386
|
-
|
387
|
-
|
386
|
+
value_char = c.value.char
|
387
|
+
if value_char.respond_to?(:encode)
|
388
|
+
mem << value_char.encode(@root.options[:encoding])
|
388
389
|
elsif [60, 62, 34, 38].include?(c.value.code_point)
|
389
390
|
mem << c.value.code_point.chr
|
390
391
|
end
|
@@ -405,6 +406,10 @@ module Kramdown
|
|
405
406
|
set_basics(el, :codespan)
|
406
407
|
else
|
407
408
|
set_basics(el, :codeblock)
|
409
|
+
if el.children.size == 1 && el.children.first.value == 'code'
|
410
|
+
value = (el.children.first.attr['class'] || '').scan(/\blanguage-\w+\b/).first
|
411
|
+
el.attr['class'] = "#{value} #{el.attr['class']}".rstrip if value
|
412
|
+
end
|
408
413
|
end
|
409
414
|
el.value = result.first.value
|
410
415
|
el.children.clear
|
@@ -32,11 +32,7 @@ module Kramdown
|
|
32
32
|
ACHARS = '[[:alnum:]]'
|
33
33
|
end
|
34
34
|
AUTOLINK_START_STR = "<((mailto|https?|ftps?):.+?|[-.#{ACHARS}]+@[-#{ACHARS}]+(?:\.[-#{ACHARS}]+)*\.[a-z]+)>"
|
35
|
-
|
36
|
-
AUTOLINK_START = /#{AUTOLINK_START_STR}/u
|
37
|
-
else
|
38
|
-
AUTOLINK_START = /#{AUTOLINK_START_STR}/
|
39
|
-
end
|
35
|
+
AUTOLINK_START = /#{AUTOLINK_START_STR}/u
|
40
36
|
|
41
37
|
# Parse the autolink at the current location.
|
42
38
|
def parse_autolink
|
@@ -44,13 +44,16 @@ module Kramdown
|
|
44
44
|
|
45
45
|
|
46
46
|
FENCED_CODEBLOCK_START = /^~{3,}/
|
47
|
-
FENCED_CODEBLOCK_MATCH = /^(~{3,})\s*?\n(.*?)^\1~*\s*?\n/m
|
47
|
+
FENCED_CODEBLOCK_MATCH = /^(~{3,})\s*?(\w+)?\s*?\n(.*?)^\1~*\s*?\n/m
|
48
48
|
|
49
49
|
# Parse the fenced codeblock at the current location.
|
50
50
|
def parse_codeblock_fenced
|
51
51
|
if @src.check(FENCED_CODEBLOCK_MATCH)
|
52
52
|
@src.pos += @src.matched_size
|
53
|
-
|
53
|
+
el = new_block_el(:codeblock, @src[3])
|
54
|
+
lang = @src[2].to_s.strip
|
55
|
+
el.attr['class'] = "language-#{lang}" unless lang.empty?
|
56
|
+
@tree.children << el
|
54
57
|
true
|
55
58
|
else
|
56
59
|
false
|
data/lib/kramdown/utils/html.rb
CHANGED
@@ -36,15 +36,17 @@ module Kramdown
|
|
36
36
|
#
|
37
37
|
# This method uses the option +entity_output+ to determine the output form for the entity.
|
38
38
|
def entity_to_str(e, original = nil)
|
39
|
-
|
39
|
+
entity_output = @options[:entity_output]
|
40
|
+
|
41
|
+
if e.char.respond_to?(:encoding) && entity_output == :as_char &&
|
40
42
|
(c = e.char.encode(@root.options[:encoding]) rescue nil) && !ESCAPE_MAP.has_key?(c)
|
41
43
|
c
|
42
|
-
elsif (
|
44
|
+
elsif (entity_output == :as_input || entity_output == :as_char) && original
|
43
45
|
original
|
44
|
-
elsif
|
45
|
-
"&##{e.code_point};"
|
46
|
-
else
|
46
|
+
elsif (entity_output == :symbolic || ESCAPE_MAP.has_key?(e.char)) && !e.name.nil?
|
47
47
|
"&#{e.name};"
|
48
|
+
else # default to :numeric
|
49
|
+
"&##{e.code_point};"
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
data/lib/kramdown/version.rb
CHANGED
data/test/test_files.rb
CHANGED
@@ -157,6 +157,7 @@ class TestFiles < Test::Unit::TestCase
|
|
157
157
|
'test/testcases/span/03_codespan/highlighting.html', # bc of span elements inside code element
|
158
158
|
'test/testcases/block/04_header/with_auto_ids.html', # bc of auto_ids=true option
|
159
159
|
'test/testcases/block/04_header/header_type_offset.html', # bc of header_offset option
|
160
|
+
'test/testcases/block/16_toc/toc_exclude.html', # bc of different attribute ordering
|
160
161
|
]
|
161
162
|
Dir[File.dirname(__FILE__) + '/testcases/**/*.html'].each do |html_file|
|
162
163
|
next if EXCLUDE_HTML_KD_FILES.any? {|f| html_file =~ /#{f}$/}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<pre><code class="language-ruby">def what?
|
2
|
+
42
|
3
|
+
end
|
4
|
+
</code></pre>
|
5
|
+
|
6
|
+
<pre class="class1"><code class="language-ruby">def what?
|
7
|
+
42
|
8
|
+
end
|
9
|
+
</code></pre>
|
10
|
+
|
11
|
+
<pre><code class="language-ruby">def what?
|
12
|
+
42
|
13
|
+
end
|
14
|
+
</code></pre>
|
15
|
+
|
16
|
+
<pre class="language-python"><code class="language-ruby">def what?
|
17
|
+
42
|
18
|
+
end
|
19
|
+
</code></pre>
|
20
|
+
|
21
|
+
<pre class="language-python"><code class="language-ruby">def what?
|
22
|
+
42
|
23
|
+
end
|
24
|
+
</code></pre>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
~~~ ruby
|
2
|
+
def what?
|
3
|
+
42
|
4
|
+
end
|
5
|
+
~~~
|
6
|
+
|
7
|
+
~~~ ruby
|
8
|
+
def what?
|
9
|
+
42
|
10
|
+
end
|
11
|
+
~~~
|
12
|
+
{:.class1}
|
13
|
+
|
14
|
+
~~~
|
15
|
+
def what?
|
16
|
+
42
|
17
|
+
end
|
18
|
+
~~~
|
19
|
+
{: .language-ruby}
|
20
|
+
|
21
|
+
~~~ ruby
|
22
|
+
def what?
|
23
|
+
42
|
24
|
+
end
|
25
|
+
~~~
|
26
|
+
{: .language-python}
|
27
|
+
|
28
|
+
~~~ ruby
|
29
|
+
def what?
|
30
|
+
42
|
31
|
+
end
|
32
|
+
~~~
|
33
|
+
{: class="language-python"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<p>_ * _</p>
|
2
2
|
|
3
|
-
<p
|
3
|
+
<p>— * * *</p>
|
4
4
|
|
5
5
|
<p>_ - *</p>
|
6
6
|
|
7
|
-
<p
|
7
|
+
<p>———————————————- test</p>
|
@@ -1 +1 @@
|
|
1
|
-
<p>This is
|
1
|
+
<p>This is … something “to remember”!</p>
|
@@ -30,11 +30,11 @@
|
|
30
30
|
</tr>
|
31
31
|
<tr>
|
32
32
|
<td>cell1</td>
|
33
|
-
<td
|
34
|
-
<td
|
33
|
+
<td> </td>
|
34
|
+
<td> </td>
|
35
35
|
</tr>
|
36
36
|
<tr>
|
37
|
-
<td
|
37
|
+
<td> </td>
|
38
38
|
<td>cell2</td>
|
39
39
|
<td>cell3</td>
|
40
40
|
</tr>
|
@@ -66,9 +66,9 @@
|
|
66
66
|
<tbody>
|
67
67
|
<tr>
|
68
68
|
<td>This is a <code>span | with</code> a pipe.</td>
|
69
|
-
<td
|
70
|
-
<td
|
71
|
-
<td
|
69
|
+
<td> </td>
|
70
|
+
<td> </td>
|
71
|
+
<td> </td>
|
72
72
|
</tr>
|
73
73
|
<tr>
|
74
74
|
<td>Some <em>span</em></td>
|
@@ -153,7 +153,7 @@
|
|
153
153
|
</thead>
|
154
154
|
<tbody>
|
155
155
|
<tr>
|
156
|
-
<td
|
156
|
+
<td> </td>
|
157
157
|
<td>cell2</td>
|
158
158
|
</tr>
|
159
159
|
</tbody>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<h1 class="no_toc" id="contents">Contents</h1>
|
2
|
+
|
3
|
+
<ul id="markdown-toc">
|
4
|
+
<li><a href="#header-level-1">Header level 1</a> <ul>
|
5
|
+
<li><a href="#header-level-2">Header level 2</a> <ul>
|
6
|
+
<li><a href="#header-level-3">Header level 3</a> <ul>
|
7
|
+
<li><a href="#header-level-4">Header level 4</a></li>
|
8
|
+
</ul>
|
9
|
+
</li>
|
10
|
+
</ul>
|
11
|
+
</li>
|
12
|
+
</ul>
|
13
|
+
</li>
|
14
|
+
<li><a href="#other-header-level-1">Other header level 1</a> <ul>
|
15
|
+
<li><a href="#other-header-level-2">Other header level 2</a> <ul>
|
16
|
+
<li><a href="#other-header-level-3">Other header level 3</a></li>
|
17
|
+
</ul>
|
18
|
+
</li>
|
19
|
+
</ul>
|
20
|
+
</li>
|
21
|
+
</ul>
|
22
|
+
|
23
|
+
<h1 id="header-level-1">Header level 1</h1>
|
24
|
+
|
25
|
+
<h2 id="header-level-2">Header level 2</h2>
|
26
|
+
|
27
|
+
<h3 id="header-level-3">Header level 3</h3>
|
28
|
+
|
29
|
+
<h4 id="header-level-4">Header level 4</h4>
|
30
|
+
|
31
|
+
<h1 id="other-header-level-1">Other header level 1</h1>
|
32
|
+
|
33
|
+
<h2 id="other-header-level-2">Other header level 2</h2>
|
34
|
+
|
35
|
+
<h3 id="other-header-level-3">Other header level 3</h3>
|
@@ -0,0 +1 @@
|
|
1
|
+
:auto_ids: true
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Contents
|
2
|
+
{:.no_toc}
|
3
|
+
|
4
|
+
* Here comes the table of content
|
5
|
+
{:toc}
|
6
|
+
|
7
|
+
# Header level 1
|
8
|
+
|
9
|
+
## Header level 2
|
10
|
+
|
11
|
+
### Header level 3
|
12
|
+
|
13
|
+
#### Header level 4
|
14
|
+
|
15
|
+
# Other header level 1
|
16
|
+
|
17
|
+
## Other header level 2
|
18
|
+
|
19
|
+
### Other header level 3
|
@@ -23,14 +23,14 @@ the text</a></p>
|
|
23
23
|
<p>[no url] invalid.html
|
24
24
|
[no url]:</p>
|
25
25
|
|
26
|
-
<p
|
26
|
+
<p>“title”</p>
|
27
27
|
|
28
28
|
<p>test <a href="invalid.html">url but no title</a>
|
29
29
|
test [urldef]</p>
|
30
30
|
|
31
|
-
<p>[urldef]: some.url
|
31
|
+
<p>[urldef]: some.url ‘title”</p>
|
32
32
|
|
33
33
|
<p>some <a href="with spaces.html" title="title">with spaces</a></p>
|
34
34
|
|
35
|
-
<p>this <a href="occasion.html">is a
|
35
|
+
<p>this <a href="occasion.html">is a ‘special’ occasion for /all/ of us</a></p>
|
36
36
|
|
@@ -1 +1 @@
|
|
1
|
-
<p>You can say <code><span class="CodeRay">x = <span style="color:#036;font-weight:bold">Class</span>.new</span></code>, for example.</p>
|
1
|
+
<p>You can say <code class="language-ruby"><span class="CodeRay">x = <span style="color:#036;font-weight:bold">Class</span>.new</span></code>, for example.</p>
|
@@ -1 +1 @@
|
|
1
|
-
You can say `x = Class.new`{
|
1
|
+
You can say `x = Class.new`{:.language-ruby}, for example.
|
@@ -0,0 +1 @@
|
|
1
|
+
:entity_output: symbolic
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kramdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coderay
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- test/testcases/span/ial/simple.text
|
188
188
|
- test/testcases/span/math/normal.html
|
189
189
|
- test/testcases/span/math/normal.text
|
190
|
+
- test/testcases/span/text_substitutions/typography.options
|
190
191
|
- test/testcases/span/text_substitutions/entities_as_input.options
|
191
192
|
- test/testcases/span/text_substitutions/typography.html
|
192
193
|
- test/testcases/span/text_substitutions/entities.html
|
@@ -206,7 +207,6 @@ files:
|
|
206
207
|
- test/testcases/span/text_substitutions/entities.text
|
207
208
|
- test/testcases/span/text_substitutions/entities_symbolic.html
|
208
209
|
- test/testcases/span/text_substitutions/entities_numeric.html
|
209
|
-
- test/testcases/span/text_substitutions/typography.html.19
|
210
210
|
- test/testcases/span/text_substitutions/entities_as_input.text
|
211
211
|
- test/testcases/span/text_substitutions/entities_as_input.html
|
212
212
|
- test/testcases/span/text_substitutions/greaterthan.text
|
@@ -358,7 +358,6 @@ files:
|
|
358
358
|
- test/testcases/block/04_header/atx_header.html
|
359
359
|
- test/testcases/block/04_header/header_type_offset.kramdown
|
360
360
|
- test/testcases/block/04_header/setext_header_no_newline_at_end.text
|
361
|
-
- test/testcases/block/04_header/setext_header.html.19
|
362
361
|
- test/testcases/block/04_header/atx_header_no_newline_at_end.text
|
363
362
|
- test/testcases/block/04_header/setext_header.html
|
364
363
|
- test/testcases/block/04_header/with_auto_id_prefix.html
|
@@ -432,17 +431,22 @@ files:
|
|
432
431
|
- test/testcases/block/16_toc/no_toc.html
|
433
432
|
- test/testcases/block/16_toc/toc_levels.html
|
434
433
|
- test/testcases/block/16_toc/toc_levels.text
|
434
|
+
- test/testcases/block/16_toc/toc_exclude.html
|
435
435
|
- test/testcases/block/16_toc/toc_with_footnotes.html
|
436
436
|
- test/testcases/block/16_toc/toc_with_footnotes.text
|
437
|
+
- test/testcases/block/16_toc/toc_exclude.options
|
437
438
|
- test/testcases/block/16_toc/toc_levels.options
|
439
|
+
- test/testcases/block/16_toc/toc_exclude.text
|
438
440
|
- test/testcases/block/01_blank_line/spaces.html
|
439
441
|
- test/testcases/block/01_blank_line/tabs.text
|
440
442
|
- test/testcases/block/01_blank_line/spaces.text
|
441
443
|
- test/testcases/block/01_blank_line/tabs.html
|
442
444
|
- test/testcases/block/06_codeblock/highlighting.html
|
443
445
|
- test/testcases/block/06_codeblock/highlighting.options
|
446
|
+
- test/testcases/block/06_codeblock/with_lang_in_fenced_block.html
|
444
447
|
- test/testcases/block/06_codeblock/whitespace.text
|
445
448
|
- test/testcases/block/06_codeblock/disable-highlighting.text
|
449
|
+
- test/testcases/block/06_codeblock/with_lang_in_fenced_block.options
|
446
450
|
- test/testcases/block/06_codeblock/with_eob_marker.text
|
447
451
|
- test/testcases/block/06_codeblock/tilde_syntax.html
|
448
452
|
- test/testcases/block/06_codeblock/no_newline_at_end_1.text
|
@@ -465,6 +469,7 @@ files:
|
|
465
469
|
- test/testcases/block/06_codeblock/no_newline_at_end.html
|
466
470
|
- test/testcases/block/06_codeblock/error.text
|
467
471
|
- test/testcases/block/06_codeblock/normal.text
|
472
|
+
- test/testcases/block/06_codeblock/with_lang_in_fenced_block.text
|
468
473
|
- test/testcases/encoding.html
|
469
474
|
- test/test_files.rb
|
470
475
|
homepage: http://kramdown.rubyforge.org
|
@@ -1,30 +0,0 @@
|
|
1
|
-
<h2>test</h2>
|
2
|
-
|
3
|
-
<h1>test2</h1>
|
4
|
-
|
5
|
-
<h2>test</h2>
|
6
|
-
<p>para</p>
|
7
|
-
|
8
|
-
<pre><code> header =
|
9
|
-
</code></pre>
|
10
|
-
|
11
|
-
<p>=</p>
|
12
|
-
|
13
|
-
<p>This is a para.
|
14
|
-
With two lines.
|
15
|
-
And not a header.
|
16
|
-
=================</p>
|
17
|
-
|
18
|
-
<blockquote>
|
19
|
-
<p>Blockquote.
|
20
|
-
Not a Header
|
21
|
-
—</p>
|
22
|
-
</blockquote>
|
23
|
-
|
24
|
-
<h2 id="id">header</h2>
|
25
|
-
|
26
|
-
<h1 id="id">header</h1>
|
27
|
-
|
28
|
-
<h2>header{#noid}</h2>
|
29
|
-
|
30
|
-
<h2>header</h2>
|
@@ -1,18 +0,0 @@
|
|
1
|
-
<p>This is… something—this too–!</p>
|
2
|
-
|
3
|
-
<p>This «is» some text, « this » too!</p>
|
4
|
-
|
5
|
-
<p>“Fancy quotes” are ‘cool’, even in the ’80s!
|
6
|
-
Je t’ aime. You’re a funny one! Thomas’ name
|
7
|
-
Mark’s name. “…you”
|
8
|
-
“‘Nested’ quotes are ‘possible’”, too!
|
9
|
-
‘“Otherway” is “round”’!</p>
|
10
|
-
|
11
|
-
<p>‘Opening now!’</p>
|
12
|
-
|
13
|
-
<p>’80s are really cool.</p>
|
14
|
-
|
15
|
-
<p><em>Cluster</em>’s Last Stand.</p>
|
16
|
-
|
17
|
-
<p>Nam liber tempor
|
18
|
-
“…At vero eos et accusam”</p>
|