kramdown 2.0.0 → 2.1.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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e61a5f6dbf5b13bfcf0164acaf6a0c6e8fa2cd2c39fc7368bf9f54be38e0552
4
- data.tar.gz: e03352fce83854b256596c7718dd2c48251b5851f7e1ca06012d433526b6015b
3
+ metadata.gz: e43c55f31bbce7153d1d863ab7c90bb24aee7741e7df3a0f6d89064286fe2344
4
+ data.tar.gz: c53d7af0318896bae6bdcb9123eb714f9572e4c9918f04d093c7d228c2431b0e
5
5
  SHA512:
6
- metadata.gz: 3bf07ed2b152212b8aa8e50383b7cfc7a38a16d11441f6c5b2790c834020e3ef8ab82e6978bd86b3334740cc4b23a407f66b744ded4ee22bb6e75b210d3668cc
7
- data.tar.gz: 0206cd73d6c8d75470701c197fb89d151e6f3c2c694b20af1068f8c4d03386f065194e92c2c3cea5ec37e72c5f52132ce282d2c80888f229811cefc62f2049ed
6
+ metadata.gz: 351a0939690de3cf44107f5cad613d8d3dc945b6d47d0e78f8bf676081b7887f696e738fb9200779a6821a870161a3110a7e42911e7705cc7d79af59ff061da6
7
+ data.tar.gz: dbd73556bc863c0d6a937705662909440fd1dea33415da9e98ac681e5cd33fbedde37a7311b1082c2bcd556aec2896c10ec1d203ca992783f05eae8e7572aea0
@@ -1,12 +1,13 @@
1
1
  Count Name
2
2
  ======= ====
3
- 909 Thomas Leitner <t_leitner@gmx.at>
3
+ 913 Thomas Leitner <t_leitner@gmx.at>
4
4
  7 Christian Cornelssen <ccorn@1tein.de>
5
5
  6 Gioele Barabucci <gioele@svario.it>
6
6
  4 Ted Pak <powerpak006@gmail.com>
7
7
  4 Shuanglei Tao <tsl0922@gmail.com>
8
8
  4 Gleb Mazovetskiy <glex.spb@gmail.com>
9
9
  4 Dan Allen <dan.j.allen@gmail.com>
10
+ 4 Ashwin Maroli <ashmaroli@gmail.com>
10
11
  4 Arne Brasseur <arne@arnebrasseur.net>
11
12
  3 Henning Perl <perl@fast-sicher.de>
12
13
  3 gettalong <t_leitner@gmx.at>
@@ -59,7 +60,6 @@
59
60
  1 Damien Pollet <damien.pollet@gmail.com>
60
61
  1 Christopher Jefferson <caj21@st-andrews.ac.uk>
61
62
  1 Cédric Boutillier <cedric.boutillier@gmail.com>
62
- 1 Ashwin Maroli <ashmaroli@gmail.com>
63
63
  1 Ashe Connor <ashe@kivikakk.ee>
64
64
  1 Antoine Cotten <hello@acotten.com>
65
65
  1 Andrew <andrew.dale.wylie@gmail.com>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.1.0
@@ -13,6 +13,37 @@ require 'rbconfig'
13
13
  require 'yaml'
14
14
  require 'kramdown'
15
15
 
16
+ def add_kramdown_options(opts, parsed_options, banner: [], ignore: [])
17
+ banner_shown = false
18
+ defined_options = []
19
+ Kramdown::Options.definitions.sort.each do |n, definition|
20
+ next if ignore.include?(n)
21
+
22
+ unless banner_shown
23
+ opts.separator("")
24
+ banner.each {|part| opts.separator(part) }
25
+ opts.separator("")
26
+ banner_shown = true
27
+ end
28
+
29
+ defined_options << n
30
+ no = n.to_s.tr('_', '-')
31
+ if definition.type == Kramdown::Options::Boolean
32
+ opts.on("--[no-]#{no}") {|v| parsed_options[n] = Kramdown::Options.parse(n, v) }
33
+ else
34
+ type = definition.type
35
+ type = String if type == Symbol || type == Object
36
+ opts.on("--#{no} ARG", type) {|v| parsed_options[n] = Kramdown::Options.parse(n, v) }
37
+ end
38
+
39
+ definition.desc.split(/\n/).each do |line|
40
+ opts.separator opts.summary_indent + ' ' * 6 + line
41
+ end
42
+ opts.separator ''
43
+ end
44
+ defined_options
45
+ end
46
+
16
47
  config_file = nil
17
48
  begin
18
49
  config_dir = case RbConfig::CONFIG['host_os']
@@ -30,6 +61,7 @@ end
30
61
  options = {}
31
62
  format = ['html']
32
63
 
64
+ defined_options = []
33
65
  OptionParser.new do |opts|
34
66
  opts.banner = "Usage: kramdown [options] [FILE FILE ...]"
35
67
  opts.summary_indent = ' ' * 4
@@ -42,6 +74,20 @@ OptionParser.new do |opts|
42
74
  "html, or markdown") {|v| options[:input] = v }
43
75
  opts.on("-o", "--output ARG", Array, "Specify one or more output formats separated by commas: " \
44
76
  "html (default),", "kramdown, latex, man or remove_html_tags") {|v| format = v }
77
+ opts.on("-x", "--extension EXT", Array, "Load one or more extensions (without the 'kramdown-' " \
78
+ "prefix) separated", "by commas (e.g. parser-gfm,syntax-coderay)",
79
+ "Note: Use this option before other options!") do |exts|
80
+ exts.each do |ext|
81
+ begin
82
+ require "kramdown-#{ext}"
83
+ new_options = add_kramdown_options(opts, options, banner: ["#{ext} options:"],
84
+ ignore: defined_options)
85
+ defined_options.concat(new_options)
86
+ rescue LoadError
87
+ $stderr.puts "Couldn't load extension #{ext}, ignoring"
88
+ end
89
+ end
90
+ end
45
91
  opts.separator ""
46
92
  opts.on("--no-config-file", "Do not read any configuration file. Default behavior is to check " \
47
93
  "for a", "configuration file and read it if it exists.") { config_file = nil }
@@ -59,25 +105,8 @@ OptionParser.new do |opts|
59
105
  exit
60
106
  end
61
107
 
62
- opts.separator ""
63
- opts.separator "kramdown options:"
64
- opts.separator ""
65
-
66
- Kramdown::Options.definitions.sort.each do |n, definition|
67
- no = n.to_s.tr('_', '-')
68
- if definition.type == Kramdown::Options::Boolean
69
- opts.on("--[no-]#{no}") {|v| options[n] = Kramdown::Options.parse(n, v) }
70
- else
71
- type = definition.type
72
- type = String if type == Symbol || type == Object
73
- opts.on("--#{no} ARG", type) {|v| options[n] = Kramdown::Options.parse(n, v) }
74
- end
75
-
76
- definition.desc.split(/\n/).each do |line|
77
- opts.separator opts.summary_indent + ' ' * 6 + line
78
- end
79
- opts.separator ''
80
- end
108
+ new_options = add_kramdown_options(opts, options, banner: ["kramdown options:"])
109
+ defined_options.concat(new_options)
81
110
  end.parse!
82
111
 
83
112
  begin
@@ -25,8 +25,10 @@ module Kramdown::Converter::SyntaxHighlighter
25
25
  opts = options(converter, type)
26
26
  call_opts[:default_lang] = opts[:default_lang]
27
27
  return nil unless lang || opts[:default_lang] || opts[:guess_lang]
28
+
28
29
  lexer = ::Rouge::Lexer.find_fancy(lang || opts[:default_lang], text)
29
- return nil if opts[:disable] || !lexer || lexer.tag == "plaintext"
30
+ return nil if opts[:disable] || !lexer || (lexer.tag == "plaintext" && !opts[:guess_lang])
31
+
30
32
  opts[:css_class] ||= 'highlight' # For backward compatibility when using Rouge 2.0
31
33
  formatter = formatter_class(opts).new(opts)
32
34
  formatter.format(lexer.lex(text))
@@ -16,8 +16,8 @@ module Kramdown
16
16
  # Parse the blank line at the current postition.
17
17
  def parse_blank_line
18
18
  @src.pos += @src.matched_size
19
- if @tree.children.last && @tree.children.last.type == :blank
20
- @tree.children.last.value << @src.matched
19
+ if (last_child = @tree.children.last) && last_child.type == :blank
20
+ last_child.value << @src.matched
21
21
  else
22
22
  @tree.children << new_block_el(:blank, @src.matched)
23
23
  end
@@ -19,8 +19,9 @@ module Kramdown
19
19
 
20
20
  # Return +true+ if we are after a block boundary.
21
21
  def after_block_boundary?
22
- !@tree.children.last || @tree.children.last.type == :blank ||
23
- (@tree.children.last.type == :eob && @tree.children.last.value.nil?) || @block_ial
22
+ last_child = @tree.children.last
23
+ !last_child || last_child.type == :blank ||
24
+ (last_child.type == :eob && last_child.value.nil?) || @block_ial
24
25
  end
25
26
 
26
27
  # Return +true+ if we are before a block boundary.
@@ -163,10 +163,10 @@ module Kramdown
163
163
  elsif @src.check(EXT_BLOCK_START)
164
164
  parse_extension_start_tag(:block)
165
165
  elsif @src.scan(IAL_BLOCK_START)
166
- if @tree.children.last && @tree.children.last.type != :blank &&
167
- (@tree.children.last.type != :eob ||
168
- [:link_def, :abbrev_def, :footnote_def].include?(@tree.children.last.value))
169
- parse_attribute_list(@src[1], @tree.children.last.options[:ial] ||= {})
166
+ if (last_child = @tree.children.last) && last_child.type != :blank &&
167
+ (last_child.type != :eob ||
168
+ [:link_def, :abbrev_def, :footnote_def].include?(last_child.value))
169
+ parse_attribute_list(@src[1], last_child.options[:ial] ||= {})
170
170
  @tree.children << new_block_el(:eob, :ial) unless @src.check(IAL_BLOCK_START)
171
171
  else
172
172
  parse_attribute_list(@src[1], @block_ial ||= {})
@@ -187,12 +187,12 @@ module Kramdown
187
187
  if @src.check(EXT_SPAN_START)
188
188
  parse_extension_start_tag(:span)
189
189
  elsif @src.check(IAL_SPAN_START)
190
- if @tree.children.last && @tree.children.last.type != :text
190
+ if (last_child = @tree.children.last) && last_child.type != :text
191
191
  @src.pos += @src.matched_size
192
192
  attr = {}
193
193
  parse_attribute_list(@src[1], attr)
194
- update_ial_with_ial(@tree.children.last.options[:ial] ||= {}, attr)
195
- update_attr_with_ial(@tree.children.last.attr, attr)
194
+ update_ial_with_ial(last_child.options[:ial] ||= {}, attr)
195
+ update_attr_with_ial(last_child.attr, attr)
196
196
  else
197
197
  warning("Found span IAL after text - ignoring it")
198
198
  add_text(@src.getch)
@@ -92,8 +92,9 @@ module Kramdown
92
92
  emit_warning = !@src[1]
93
93
  link_id = normalize_link_id(@src[1] || alt_text)
94
94
  if @link_defs.key?(link_id)
95
- add_link(el, @link_defs[link_id][0], @link_defs[link_id][1], alt_text,
96
- @link_defs[link_id][2] && @link_defs[link_id][2].options[:ial])
95
+ link_def = @link_defs[link_id]
96
+ add_link(el, link_def[0], link_def[1], alt_text,
97
+ link_def[2] && link_def[2].options[:ial])
97
98
  else
98
99
  if emit_warning
99
100
  warning("No link definition for link ID '#{link_id}' found on line #{start_line_number}")
@@ -72,7 +72,7 @@ module Kramdown
72
72
  parse_first_list_line(@src[1].length, @src[2])
73
73
  list.children << item
74
74
 
75
- item.value.sub!(self.class::LIST_ITEM_IAL) do |_match|
75
+ item.value.sub!(self.class::LIST_ITEM_IAL) do
76
76
  parse_attribute_list($1, item.options[:ial] ||= {})
77
77
  ''
78
78
  end
@@ -122,22 +122,24 @@ module Kramdown
122
122
 
123
123
  it.children = temp.children
124
124
  it.value = nil
125
- next if it.children.empty?
125
+
126
+ it_children = it.children
127
+ next if it_children.empty?
126
128
 
127
129
  # Handle the case where an EOB marker is inserted by a block IAL for the first paragraph
128
- it.children.delete_at(1) if it.children.first.type == :p &&
129
- it.children.length >= 2 && it.children[1].type == :eob && it.children.first.options[:ial]
130
+ it_children.delete_at(1) if it_children.first.type == :p &&
131
+ it_children.length >= 2 && it_children[1].type == :eob && it_children.first.options[:ial]
130
132
 
131
- if it.children.first.type == :p &&
132
- (it.children.length < 2 || it.children[1].type != :blank ||
133
- (it == list.children.last && it.children.length == 2 && !eob_found)) &&
133
+ if it_children.first.type == :p &&
134
+ (it_children.length < 2 || it_children[1].type != :blank ||
135
+ (it == list.children.last && it_children.length == 2 && !eob_found)) &&
134
136
  (list.children.last != it || list.children.size == 1 ||
135
- list.children[0..-2].any? {|cit| !cit.children.first || cit.children.first.type != :p || cit.children.first.options[:transparent] })
136
- it.children.first.children.first.value << "\n" if it.children.size > 1 && it.children[1].type != :blank
137
- it.children.first.options[:transparent] = true
137
+ list.children[0..-2].any? {|cit| !cit.children.first || cit.children.first.type != :p || cit.children.first.options[:transparent] })
138
+ it_children.first.children.first.value << "\n" if it_children.size > 1 && it_children[1].type != :blank
139
+ it_children.first.options[:transparent] = true
138
140
  end
139
141
 
140
- last = (it.children.last.type == :blank ? it.children.pop : nil)
142
+ last = (it_children.last.type == :blank ? it_children.pop : nil)
141
143
  end
142
144
 
143
145
  @tree.children << last if !last.nil? && !eob_found
@@ -222,27 +224,29 @@ module Kramdown
222
224
 
223
225
  parse_blocks(it, it.value)
224
226
  it.value = nil
225
- next if it.children.empty?
227
+ it_children = it.children
228
+ next if it_children.empty?
226
229
 
227
- last = (it.children.last.type == :blank ? it.children.pop : nil)
230
+ last = (it_children.last.type == :blank ? it_children.pop : nil)
228
231
 
229
- if it.children.first && it.children.first.type == :p && !it.options.delete(:first_as_para)
230
- it.children.first.children.first.value << "\n" if it.children.size > 1
231
- it.children.first.options[:transparent] = true
232
+ if it_children.first && it_children.first.type == :p && !it.options.delete(:first_as_para)
233
+ it_children.first.children.first.value << "\n" if it_children.size > 1
234
+ it_children.first.options[:transparent] = true
232
235
  end
233
236
  end
234
237
 
235
- if @tree.children.length >= 1 && @tree.children.last.type == :dl
236
- @tree.children[-1].children.concat(deflist.children)
237
- elsif @tree.children.length >= 2 && @tree.children[-1].type == :blank &&
238
- @tree.children[-2].type == :dl
239
- @tree.children.pop
240
- @tree.children[-1].children.concat(deflist.children)
238
+ children = @tree.children
239
+ if children.length >= 1 && children.last.type == :dl
240
+ children[-1].children.concat(deflist.children)
241
+ elsif children.length >= 2 && children[-1].type == :blank &&
242
+ children[-2].type == :dl
243
+ children.pop
244
+ children[-1].children.concat(deflist.children)
241
245
  else
242
- @tree.children << deflist
246
+ children << deflist
243
247
  end
244
248
 
245
- @tree.children << last if last
249
+ children << last if last
246
250
 
247
251
  true
248
252
  end
@@ -36,13 +36,13 @@ module Kramdown
36
36
  result << @src.scan(PARAGRAPH_MATCH)
37
37
  end
38
38
  result.rstrip!
39
- if @tree.children.last && @tree.children.last.type == :p
40
- last_item_in_para = @tree.children.last.children.last
39
+ if (last_child = @tree.children.last) && last_child.type == :p
40
+ last_item_in_para = last_child.children.last
41
41
  if last_item_in_para && last_item_in_para.type == @text_type
42
42
  joiner = (extract_string((pos - 3)...pos, @src) == " \n" ? " \n" : "\n")
43
43
  last_item_in_para.value << joiner << result
44
44
  else
45
- add_text(result, @tree.children.last)
45
+ add_text(result, last_child)
46
46
  end
47
47
  else
48
48
  @tree.children << new_block_el(:p, nil, nil, location: start_line_number)
@@ -81,7 +81,7 @@ module Kramdown
81
81
  cells.concat(l)
82
82
  else
83
83
  delim = (c.value.scan(/`+/).max || '') + '`'
84
- tmp = "#{delim}#{' ' if delim.size > 1}#{c.value}#{' ' if delim.size > 1}#{delim}"
84
+ tmp = +"#{delim}#{' ' if delim.size > 1}#{c.value}#{' ' if delim.size > 1}#{delim}"
85
85
  (cells.empty? ? cells : cells.last) << tmp
86
86
  end
87
87
  end
@@ -10,6 +10,6 @@
10
10
  module Kramdown
11
11
 
12
12
  # The kramdown version.
13
- VERSION = '2.0.0'
13
+ VERSION = '2.1.0'
14
14
 
15
15
  end
@@ -1,5 +1,5 @@
1
1
  .\" generated by kramdown
2
- .TH "KRAMDOWN" "1" "November 2016"
2
+ .TH "KRAMDOWN" "1" "January 2019"
3
3
  .SH NAME
4
4
  kramdown \- a fast, pure\-Ruby Markdown\-superset converter
5
5
  .SH "SYNOPSIS"
@@ -20,6 +20,13 @@ Specify the input format\. Available input formats: \fIkramdown\fP (this is the
20
20
  \fB\-o\fP \fIFORMAT\fP, \fB\-\-output\fP \fIFORMAT\fP
21
21
  Specify one or more output formats separated by commas: \fIhtml\fP (default), \fIkramdown\fP, \fIlatex\fP, \fIman\fP or \fIremove_html_tags\fP\&\. The converter \fIpdf\fP is available through the \fBkramdown\-converter\-pdf\fP gem\.
22
22
  .TP
23
+ \fB\-x\fP \fIEXT\fP, \fB\-\-extension\fP \fIEXT\fP
24
+ Load one or more extensions\. The name of the extension should not include the \fBkramdown\-\fP prefix, e\.g\. just \fBparser\-gfm\fP\&\. Multiple extensions can be loaded by separating them with commas\.
25
+ .RS
26
+ .P
27
+ Note: This option has to be used before any other options that rely on the extension already being loaded\.
28
+ .RE
29
+ .TP
23
30
  \fB\-\-no\-config\-file\fP
24
31
  Do not read any configuration file\. Default behavior is to check for a configuration file and read it if it exists\.
25
32
  .TP
@@ -72,6 +72,7 @@ class TestFiles < Minitest::Test
72
72
  'test/testcases/block/06_codeblock/rouge/multiple.html', # bc of double surrounding <div>
73
73
  'test/testcases/block/06_codeblock/highlighting.html', # bc of span elements inside code element
74
74
  'test/testcases/block/06_codeblock/highlighting-opts.html', # bc of span elements inside code element
75
+ 'test/testcases/block/06_codeblock/guess_lang_css_class.html', # bc of double surrounding <div>
75
76
  'test/testcases/block/12_extension/options3.html', # bc of rouge
76
77
  'test/testcases/block/14_table/empty_tag_in_cell.html', # bc of tidy
77
78
  'test/testcases/block/15_math/mathjax_preview.html', # bc of mathjax preview
@@ -211,6 +212,7 @@ class TestFiles < Minitest::Test
211
212
  'test/testcases/block/06_codeblock/whitespace.html', # bc of entity to char conversion
212
213
  'test/testcases/block/06_codeblock/rouge/simple.html', # bc of double surrounding <div>
213
214
  'test/testcases/block/06_codeblock/rouge/multiple.html', # bc of double surrounding <div>
215
+ 'test/testcases/block/06_codeblock/guess_lang_css_class.html', # bc of double surrounding <div>
214
216
  'test/testcases/block/06_codeblock/highlighting.html', # bc of span elements inside code element
215
217
  'test/testcases/block/06_codeblock/highlighting-opts.html', # bc of span elements inside code element
216
218
  'test/testcases/block/11_ial/simple.html', # bc of change of ordering of attributes in header
@@ -0,0 +1,15 @@
1
+ <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Foo
2
+ def bar
3
+ puts 'Hello'
4
+ end
5
+ end
6
+ </code></pre>
7
+ </div></div>
8
+
9
+ <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Foo
10
+ def bar
11
+ puts 'Hello'
12
+ end
13
+ end
14
+ </code></pre>
15
+ </div></div>
@@ -0,0 +1,2 @@
1
+ :syntax_highlighter_opts:
2
+ guess_lang: true
@@ -0,0 +1,13 @@
1
+ ~~~
2
+ class Foo
3
+ def bar
4
+ puts 'Hello'
5
+ end
6
+ end
7
+ ~~~
8
+
9
+ class Foo
10
+ def bar
11
+ puts 'Hello'
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ <p>This is a <code class="highlighter-rouge">code-span</code></p>
@@ -0,0 +1,2 @@
1
+ :syntax_highlighter_opts:
2
+ guess_lang: true
@@ -0,0 +1 @@
1
+ This is a `code-span`
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Leitner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-20 00:00:00.000000000 Z
11
+ date: 2019-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -194,6 +194,9 @@ files:
194
194
  - test/testcases/block/06_codeblock/disable-highlighting.text
195
195
  - test/testcases/block/06_codeblock/error.html
196
196
  - test/testcases/block/06_codeblock/error.text
197
+ - test/testcases/block/06_codeblock/guess_lang_css_class.html
198
+ - test/testcases/block/06_codeblock/guess_lang_css_class.options
199
+ - test/testcases/block/06_codeblock/guess_lang_css_class.text
197
200
  - test/testcases/block/06_codeblock/highlighting-minted-with-opts.latex
198
201
  - test/testcases/block/06_codeblock/highlighting-minted-with-opts.options
199
202
  - test/testcases/block/06_codeblock/highlighting-minted-with-opts.text
@@ -503,6 +506,9 @@ files:
503
506
  - test/testcases/span/03_codespan/highlighting-minted.text
504
507
  - test/testcases/span/03_codespan/highlighting.html
505
508
  - test/testcases/span/03_codespan/highlighting.text
509
+ - test/testcases/span/03_codespan/normal-css-class.html
510
+ - test/testcases/span/03_codespan/normal-css-class.options
511
+ - test/testcases/span/03_codespan/normal-css-class.text
506
512
  - test/testcases/span/03_codespan/normal.html
507
513
  - test/testcases/span/03_codespan/normal.text
508
514
  - test/testcases/span/03_codespan/rouge/disabled.html