mdl 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mdl.rb +8 -8
- data/lib/mdl/doc.rb +8 -6
- data/lib/mdl/rules.rb +17 -3
- data/lib/mdl/style.rb +16 -2
- data/lib/mdl/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2ef1682330d4d7498e347b19aaa6a18c8006ac62b811e93dc4f1b87ba9e73ef
|
4
|
+
data.tar.gz: 4711609a70fdd931788e6c50b05c3a515c813f3bb0e52ba6716f9ea666ada0a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bef5fff1c8e926baa7299487a17d711b4c79368b0722fd990c2b1d6e5ffcc046c6385ae5d863e4ad3cc708bec77239167a41c4ae78c9064fe1f7a45f9fcaafb
|
7
|
+
data.tar.gz: e8275c46e8c465f849b9766178b17f02644165f5c20ef6fbb030281b7ff917dc870ff5443aa0a94b05c28e3d195c2093f6213f6177551587c7e7b87017d491a7
|
data/lib/mdl.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
require_relative 'mdl/cli'
|
2
|
+
require_relative 'mdl/config'
|
3
|
+
require_relative 'mdl/doc'
|
4
|
+
require_relative 'mdl/kramdown_parser'
|
5
|
+
require_relative 'mdl/ruleset'
|
6
|
+
require_relative 'mdl/style'
|
7
|
+
require_relative 'mdl/version'
|
8
8
|
|
9
9
|
require 'kramdown'
|
10
10
|
|
@@ -88,7 +88,6 @@ module MarkdownLint
|
|
88
88
|
error_lines.each do |line|
|
89
89
|
line += doc.offset # Correct line numbers for any yaml front matter
|
90
90
|
if Config[:json]
|
91
|
-
require 'json'
|
92
91
|
results << {
|
93
92
|
'filename' => filename,
|
94
93
|
'line' => line,
|
@@ -106,6 +105,7 @@ module MarkdownLint
|
|
106
105
|
end
|
107
106
|
|
108
107
|
if Config[:json]
|
108
|
+
require 'json'
|
109
109
|
puts JSON.generate(results)
|
110
110
|
elsif status != 0
|
111
111
|
puts "\nA detailed description of the rules is available at "\
|
data/lib/mdl/doc.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'kramdown'
|
2
|
-
|
2
|
+
require_relative 'kramdown_parser'
|
3
3
|
|
4
4
|
module MarkdownLint
|
5
5
|
##
|
@@ -44,7 +44,7 @@ module MarkdownLint
|
|
44
44
|
@lines = text.split(/\R/)
|
45
45
|
@parsed = Kramdown::Document.new(text, :input => 'MarkdownLint')
|
46
46
|
@elements = @parsed.root.children
|
47
|
-
|
47
|
+
add_annotations(@elements)
|
48
48
|
end
|
49
49
|
|
50
50
|
##
|
@@ -190,7 +190,7 @@ module MarkdownLint
|
|
190
190
|
if item.type != :li
|
191
191
|
raise "list_style called with non-list element"
|
192
192
|
end
|
193
|
-
line = element_line(item).strip
|
193
|
+
line = element_line(item).strip.gsub(/^>\s+/,'')
|
194
194
|
if line.start_with?('*')
|
195
195
|
:asterisk
|
196
196
|
elsif line.start_with?('+')
|
@@ -277,12 +277,14 @@ module MarkdownLint
|
|
277
277
|
private
|
278
278
|
|
279
279
|
##
|
280
|
-
# Adds a 'level' option to all elements to show how nested they
|
280
|
+
# Adds a 'level' and 'parent' option to all elements to show how nested they
|
281
|
+
# are
|
281
282
|
|
282
|
-
def
|
283
|
+
def add_annotations(elements, level=1, parent=nil)
|
283
284
|
elements.each do |e|
|
284
285
|
e.options[:element_level] = level
|
285
|
-
|
286
|
+
e.options[:parent] = parent
|
287
|
+
add_annotations(e.children, level+1, e)
|
286
288
|
end
|
287
289
|
end
|
288
290
|
|
data/lib/mdl/rules.rb
CHANGED
@@ -470,7 +470,7 @@ rule "MD030", "Spaces after list markers" do
|
|
470
470
|
# the items in it have multiple paragraphs/other block items.
|
471
471
|
srule = items.map { |i| i.children.length }.max > 1 ? "multi" : "single"
|
472
472
|
items.each do |i|
|
473
|
-
actual_spaces = doc.element_line(i).match(/^\s*\S+(\s+)/)[1].length
|
473
|
+
actual_spaces = doc.element_line(i).gsub(/^> /,'').match(/^\s*\S+(\s+)/)[1].length
|
474
474
|
required_spaces = params["#{list_type}_#{srule}".to_sym]
|
475
475
|
errors << doc.element_linenumber(i) if required_spaces != actual_spaces
|
476
476
|
end
|
@@ -669,8 +669,22 @@ rule "MD046", "Code block style" do
|
|
669
669
|
style = :fenced
|
670
670
|
end
|
671
671
|
end
|
672
|
-
if
|
673
|
-
|
672
|
+
if style == :fenced
|
673
|
+
# if our parent is a list or a codeblock, we need to ignore
|
674
|
+
# its spaces, plus 4 more
|
675
|
+
parent = i.options[:parent]
|
676
|
+
ignored_spaces = 0
|
677
|
+
if parent
|
678
|
+
parent.options.delete(:children)
|
679
|
+
parent.options.delete(:parent)
|
680
|
+
if [:li, :codeblock].include?(parent.type)
|
681
|
+
linenum = doc.element_linenumbers([parent]).first
|
682
|
+
indent = doc.indent_for(doc.lines[linenum - 1])
|
683
|
+
ignored_spaces = indent + 4
|
684
|
+
end
|
685
|
+
end
|
686
|
+
start = ' ' * ignored_spaces
|
687
|
+
doc.element_line(i).start_with?("#{start} ")
|
674
688
|
else
|
675
689
|
!doc.element_line(i).start_with?(" ")
|
676
690
|
end
|
data/lib/mdl/style.rb
CHANGED
@@ -50,9 +50,23 @@ module MarkdownLint
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.load(style_file, rules)
|
53
|
-
unless style_file.include?("/")
|
54
|
-
|
53
|
+
unless style_file.include?("/") || style_file.end_with?(".rb")
|
54
|
+
tmp = File.expand_path("../styles/#{style_file}.rb", __FILE__)
|
55
|
+
unless File.exist?(tmp)
|
56
|
+
STDERR.puts "#{style_file} does not appear to be a built-in style." +
|
57
|
+
" If you meant to pass in your own style file, it must contain" +
|
58
|
+
" a '/' or end in '.rb'. See https://github.com/markdownlint/" +
|
59
|
+
"markdownlint/blob/master/docs/configuration.md"
|
60
|
+
exit(1)
|
61
|
+
end
|
62
|
+
style_file = tmp
|
63
|
+
end
|
64
|
+
|
65
|
+
unless File.exist?(style_file)
|
66
|
+
STDERR.puts "Style '#{style_file}' does not exist."
|
67
|
+
exit(1)
|
55
68
|
end
|
69
|
+
|
56
70
|
style = new(rules)
|
57
71
|
style.instance_eval(File.read(style_file), style_file)
|
58
72
|
rules.select! {|r| style.rules.include?(r)}
|
data/lib/mdl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Harrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.7.
|
194
|
+
rubygems_version: 2.7.7
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Markdown lint tool
|