mdl 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +19 -5
- data/CHANGELOG.md +41 -19
- data/README.md +3 -3
- data/docs/RULES.md +53 -2
- data/docs/rolling_a_release.md +2 -2
- data/lib/mdl.rb +18 -1
- data/lib/mdl/cli.rb +6 -0
- data/lib/mdl/doc.rb +5 -3
- data/lib/mdl/rules.rb +82 -14
- data/lib/mdl/ruleset.rb +1 -1
- data/lib/mdl/version.rb +1 -1
- data/mdl.gemspec +1 -1
- data/test/rule_tests/code_block_consistency.md +11 -0
- data/test/rule_tests/code_block_consistency_style.rb +1 -0
- data/test/rule_tests/code_block_fenced.md +17 -0
- data/test/rule_tests/code_block_fenced_style.rb +1 -0
- data/test/rule_tests/code_block_indented.md +17 -0
- data/test/rule_tests/code_block_indented_style.rb +1 -0
- data/test/rule_tests/default_test_style.rb +1 -0
- data/test/rule_tests/emphasis_instead_of_headers.md +5 -0
- data/test/rule_tests/fix_102_extra_nodes_in_link_text.md +8 -0
- data/test/rule_tests/header_duplicate_content_different_nesting.md +11 -0
- data/test/rule_tests/header_duplicate_content_different_nesting_style.rb +1 -0
- data/test/rule_tests/header_duplicate_content_no_different_nesting.md +13 -0
- data/test/rule_tests/headers_good_with_issue_numbers.md +12 -0
- data/test/rule_tests/spaces_after_list_marker_style.rb +1 -0
- data/test/test_cli.rb +9 -2
- data/tools/docker/Dockerfile +13 -0
- data/tools/docker/README.md +19 -0
- metadata +28 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 38b73db54b5ec02a8b079558f3cb444c3f29e7ffd0e9a752483115d5c0a13a93
|
4
|
+
data.tar.gz: 47c88efb0b9aa6ac538c769096d02d36170109ef4a7bc9e4370af8d45143c6d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a9c8c520e4f1e31517bb4b34549e45c505f86ed84daff6548092df02a34b594a7b81a8c4972ea93ba14fd75d4ea8a753e5c8f6f67994857d3e55449fbeb55bf
|
7
|
+
data.tar.gz: a8b3d72b3ff83bd86eb72c3b3911d16a5951ebc26372fa40995662f9372931aa192948517eafb7d7a8ec3eb0ede0d226423754c60c037543d7d55023d55f801f
|
data/.travis.yml
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
+
sudo: false
|
2
|
+
dist: trusty
|
1
3
|
language: ruby
|
2
4
|
|
5
|
+
notifications:
|
6
|
+
email: false
|
7
|
+
|
8
|
+
# Temporary disable of jruby testing. There are problems on travis-ci
|
9
|
+
# currently with this. See:
|
10
|
+
#
|
11
|
+
# https://github.com/travis-ci/travis-ci/issues/9826
|
12
|
+
#
|
13
|
+
# before_install:
|
14
|
+
# - unset _JAVA_OPTIONS
|
15
|
+
|
3
16
|
matrix:
|
4
17
|
include:
|
5
|
-
- rvm: 2.
|
6
|
-
- rvm: 2.
|
7
|
-
- rvm: 2.
|
8
|
-
- rvm: jruby-9.1.
|
9
|
-
env: JRUBY_OPTS="--dev"
|
18
|
+
- rvm: 2.3.4
|
19
|
+
- rvm: 2.4.1
|
20
|
+
- rvm: 2.5.1
|
21
|
+
# - rvm: jruby-9.1.9.0
|
22
|
+
# env: JRUBY_OPTS="--dev"
|
23
|
+
# - rvm: jruby-9.2.0.0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [Unreleased]
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
|
7
|
+
## [v0.5.0]
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
* Add md042 to enforce code block style
|
12
|
+
* JSON formatter/output
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
* PR #200: allow different nesting on headers duplication check
|
17
|
+
* MD036 - Ignore multi-line emphasized paragraphs, and emphasized paragraphs
|
18
|
+
that end in punctuation (#140)
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
|
22
|
+
* PR #168: fix issue numbers false positives
|
23
|
+
* Fix issue #102: lint MD039 checking for nodes inside link text
|
24
|
+
|
3
25
|
## [v0.4.0] (2016-08-22)
|
4
26
|
|
5
27
|
### Added
|
@@ -33,7 +55,7 @@
|
|
33
55
|
### Added
|
34
56
|
|
35
57
|
* You can now load your own custom rules with the `-u` option. See
|
36
|
-
[rules.rb](https://github.com/
|
58
|
+
[rules.rb](https://github.com/markdownlint/markdownlint/blob/master/lib/mdl/rules.rb)
|
37
59
|
for an example of what a rules file looks like. Use the `-d` option if you
|
38
60
|
don't want to load markdownlint's default ruleset.
|
39
61
|
* You can now refer to rules by human-readable/writable aliases, such as
|
@@ -55,20 +77,20 @@
|
|
55
77
|
* Crash with MD034 and pipe character (#93, #97)
|
56
78
|
* MD031 failed on nested code blocks (#100, #109)
|
57
79
|
* MD037 crashes on <li> with underscores (#83)
|
58
|
-
* Regression
|
80
|
+
* Regression introduced in v0.2.1 - ignoring rules/tags on the command line
|
59
81
|
caused a crash (#108)
|
60
82
|
* MD027 false positive when line starts with a backtick (#105)
|
61
83
|
|
62
84
|
### Merged pull requests
|
63
85
|
|
64
86
|
* [Add support for nested code fences to MD031/MD032 - David
|
65
|
-
Anson](https://github.com/
|
87
|
+
Anson](https://github.com/markdownlint/markdownlint/pull/109)
|
66
88
|
* [Add missing word to description of MD035 in RULES.md - David
|
67
|
-
Anson](https://github.com/
|
89
|
+
Anson](https://github.com/markdownlint/markdownlint/pull/86)
|
68
90
|
* [Probe for .mdlrc in current and parent directories - Loic
|
69
|
-
Nageleisen](https://github.com/
|
91
|
+
Nageleisen](https://github.com/markdownlint/markdownlint/pull/111)
|
70
92
|
* [MD013: allow excluding code blocks and tables - Loic
|
71
|
-
Nageleisen](https://github.com/
|
93
|
+
Nageleisen](https://github.com/markdownlint/markdownlint/pull/112)
|
72
94
|
|
73
95
|
## [v0.2.1] (2015-04-13)
|
74
96
|
|
@@ -104,7 +126,7 @@
|
|
104
126
|
|
105
127
|
### Merged pull requests
|
106
128
|
|
107
|
-
* [Add parameter (value and default) information to rule documentation. - David Anson](https://github.com/
|
129
|
+
* [Add parameter (value and default) information to rule documentation. - David Anson](https://github.com/markdownlint/markdownlint/pull/76)
|
108
130
|
|
109
131
|
## [v0.1.0] (2015-02-22)
|
110
132
|
|
@@ -119,10 +141,10 @@
|
|
119
141
|
|
120
142
|
### Merged pull requests
|
121
143
|
|
122
|
-
* [MD032 - Lists should be surrounded by blank lines - David Anson](https://github.com/
|
123
|
-
* [MD031 - Fenced code blocks should be surrounded by blank lines - David Anson](https://github.com/
|
124
|
-
* [Clarify how to specify your own style - mjankowski](https://github.com/
|
125
|
-
* [Use single quotes to prevent early escaping - highb](https://github.com/
|
144
|
+
* [MD032 - Lists should be surrounded by blank lines - David Anson](https://github.com/markdownlint/markdownlint/pull/70)
|
145
|
+
* [MD031 - Fenced code blocks should be surrounded by blank lines - David Anson](https://github.com/markdownlint/markdownlint/pull/68)
|
146
|
+
* [Clarify how to specify your own style - mjankowski](https://github.com/markdownlint/markdownlint/pull/65)
|
147
|
+
* [Use single quotes to prevent early escaping - highb](https://github.com/markdownlint/markdownlint/pull/64)
|
126
148
|
|
127
149
|
## [v0.0.1] (2014-09-07)
|
128
150
|
|
@@ -155,11 +177,11 @@
|
|
155
177
|
* MD029 - Ordered list item prefix
|
156
178
|
* MD030 - Spaces after list markers
|
157
179
|
|
158
|
-
[Unreleased]: https://github.com/
|
159
|
-
[v0.4.0]: https://github.com/
|
160
|
-
[v0.3.1]: https://github.com/
|
161
|
-
[v0.3.0]: https://github.com/
|
162
|
-
[v0.2.1]: https://github.com/
|
163
|
-
[v0.2.0]: https://github.com/
|
164
|
-
[v0.1.0]: https://github.com/
|
165
|
-
[v0.0.1]: https://github.com/
|
180
|
+
[Unreleased]: https://github.com/markdownlint/markdownlint/tree/master
|
181
|
+
[v0.4.0]: https://github.com/markdownlint/markdownlint/tree/v0.4.0
|
182
|
+
[v0.3.1]: https://github.com/markdownlint/markdownlint/tree/v0.3.1
|
183
|
+
[v0.3.0]: https://github.com/markdownlint/markdownlint/tree/v0.3.0
|
184
|
+
[v0.2.1]: https://github.com/markdownlint/markdownlint/tree/v0.2.1
|
185
|
+
[v0.2.0]: https://github.com/markdownlint/markdownlint/tree/v0.2.0
|
186
|
+
[v0.1.0]: https://github.com/markdownlint/markdownlint/tree/v0.1.0
|
187
|
+
[v0.0.1]: https://github.com/markdownlint/markdownlint/tree/v0.0.1
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[](https://waffle.io/mivok/markdownlint)
|
2
|
-
[](https://travis-ci.org/markdownlint/markdownlint)
|
3
3
|
[](http://badge.fury.io/rb/mdl)
|
4
4
|
|
5
5
|
# Markdown lint tool
|
@@ -18,7 +18,7 @@ To install from rubygems, run:
|
|
18
18
|
|
19
19
|
To install the latest development version from github:
|
20
20
|
|
21
|
-
git clone https://github.com/
|
21
|
+
git clone https://github.com/markdownlint/markdownlint
|
22
22
|
cd markdownlint
|
23
23
|
rake install
|
24
24
|
|
@@ -79,7 +79,7 @@ For more information on creating style files, see the
|
|
79
79
|
|
80
80
|
## Contributing
|
81
81
|
|
82
|
-
1. Fork it ( <http://github.com/
|
82
|
+
1. Fork it ( <http://github.com/markdownlint/markdownlint/fork> )
|
83
83
|
1. Create your feature branch (`git checkout -b my-new-feature`)
|
84
84
|
1. Commit your changes (`git commit -am 'Add some feature'`)
|
85
85
|
1. Push to the branch (`git push origin my-new-feature`)
|
data/docs/RULES.md
CHANGED
@@ -485,6 +485,8 @@ Tags: headers
|
|
485
485
|
|
486
486
|
Aliases: no-duplicate-header
|
487
487
|
|
488
|
+
Parameters: allow_different_nesting (boolean; default false)
|
489
|
+
|
488
490
|
This rule is triggered if there are multiple headers in the document that have
|
489
491
|
the same text:
|
490
492
|
|
@@ -502,6 +504,21 @@ Rationale: Some markdown parses generate anchors for headers based on the
|
|
502
504
|
header name, and having headers with the same content can cause problems with
|
503
505
|
this.
|
504
506
|
|
507
|
+
If the parameter `allow_different_nesting` is set to `true`, header duplication
|
508
|
+
under different nesting is allowed, like it usually happens in change logs:
|
509
|
+
|
510
|
+
# Change log
|
511
|
+
|
512
|
+
## 2.0.0
|
513
|
+
|
514
|
+
### Bug fixes
|
515
|
+
|
516
|
+
### Features
|
517
|
+
|
518
|
+
## 1.0.0
|
519
|
+
|
520
|
+
### Bug fixes
|
521
|
+
|
505
522
|
## MD025 - Multiple top level headers in the same document
|
506
523
|
|
507
524
|
Tags: headers
|
@@ -856,6 +873,8 @@ is allowed.
|
|
856
873
|
|
857
874
|
Tags: headers, emphasis
|
858
875
|
|
876
|
+
Parameters: punctuation (string; default ".,;:!?")
|
877
|
+
|
859
878
|
Aliases: no-emphasis-as-header
|
860
879
|
|
861
880
|
This check looks for instances where emphasized (i.e. bold or italic) text is
|
@@ -880,8 +899,11 @@ sections:
|
|
880
899
|
|
881
900
|
Consectetur adipiscing elit, sed do eiusmod.
|
882
901
|
|
883
|
-
Note: this rule looks for paragraphs that consist entirely of
|
884
|
-
It won't fire on emphasis used within regular text
|
902
|
+
Note: this rule looks for single line paragraphs that consist entirely of
|
903
|
+
emphasized text. It won't fire on emphasis used within regular text,
|
904
|
+
multi-line emphasized paragraphs, and paragraphs ending in punctuation.
|
905
|
+
Similarly to rule MD026, you can configure what characters are recognized as
|
906
|
+
punctuation.
|
885
907
|
|
886
908
|
## MD037 - Spaces inside emphasis markers
|
887
909
|
|
@@ -994,3 +1016,32 @@ To fix this, add a header to the top of your file:
|
|
994
1016
|
|
995
1017
|
Note: The `level` parameter can be used to change the top level (ex: to h2) in
|
996
1018
|
cases where an h1 is added externally.
|
1019
|
+
|
1020
|
+
## MD046 - Code block style
|
1021
|
+
|
1022
|
+
Tags: code
|
1023
|
+
|
1024
|
+
Aliases: code-block-style
|
1025
|
+
|
1026
|
+
Parameters: style ("fenced", "indented", "consistent", default "fenced")
|
1027
|
+
|
1028
|
+
This rule is truggered what a different code block style is used than the
|
1029
|
+
configured one. For example, in the default configuration this triggers:
|
1030
|
+
|
1031
|
+
Some text.
|
1032
|
+
|
1033
|
+
Code block
|
1034
|
+
|
1035
|
+
Some more text.
|
1036
|
+
|
1037
|
+
To fix this, used fenced code blocks:
|
1038
|
+
|
1039
|
+
Some text.
|
1040
|
+
|
1041
|
+
```ruby
|
1042
|
+
Code block
|
1043
|
+
```
|
1044
|
+
|
1045
|
+
Some more text.
|
1046
|
+
|
1047
|
+
Or the reverse for the `indented` style.
|
data/docs/rolling_a_release.md
CHANGED
@@ -21,7 +21,7 @@ Update the changelog:
|
|
21
21
|
|
22
22
|
This goes at the bottom:
|
23
23
|
|
24
|
-
[v0.2.0]: https://github.com/
|
24
|
+
[v0.2.0]: https://github.com/markdownlint/markdownlint/tree/v0.2.0
|
25
25
|
|
26
26
|
* Changelog entries can and should be added in an 'Unreleased' section as
|
27
27
|
commits are made. However, the following steps can be performed before each
|
@@ -30,7 +30,7 @@ Update the changelog:
|
|
30
30
|
* Use `git diff v0.1.0..v0.2.0 docs/RULES.md | grep '## MD'` to discover
|
31
31
|
what these are.
|
32
32
|
* Search for closed issues:
|
33
|
-
* Go to <https://github.com/
|
33
|
+
* Go to <https://github.com/markdownlint/markdownlint/issues>
|
34
34
|
* Search for `closed:>1900-01-01`, changing the date to the date
|
35
35
|
of the last release.
|
36
36
|
* From this list of issues, make sections for:
|
data/lib/mdl.rb
CHANGED
@@ -6,6 +6,7 @@ require 'mdl/ruleset'
|
|
6
6
|
require 'mdl/style'
|
7
7
|
require 'mdl/version'
|
8
8
|
|
9
|
+
require 'json'
|
9
10
|
require 'kramdown'
|
10
11
|
|
11
12
|
module MarkdownLint
|
@@ -69,6 +70,7 @@ module MarkdownLint
|
|
69
70
|
cli.cli_arguments.flatten!
|
70
71
|
|
71
72
|
status = 0
|
73
|
+
results = []
|
72
74
|
cli.cli_arguments.each do |filename|
|
73
75
|
puts "Checking #{filename}..." if Config[:verbose]
|
74
76
|
doc = Doc.new_from_file(filename, Config[:ignore_front_matter])
|
@@ -86,7 +88,15 @@ module MarkdownLint
|
|
86
88
|
status = 1
|
87
89
|
error_lines.each do |line|
|
88
90
|
line += doc.offset # Correct line numbers for any yaml front matter
|
89
|
-
if Config[:
|
91
|
+
if Config[:json]
|
92
|
+
results << {
|
93
|
+
'filename' => filename,
|
94
|
+
'line' => line,
|
95
|
+
'rule' => id,
|
96
|
+
'aliases' => rule.aliases,
|
97
|
+
'description' => rule.description,
|
98
|
+
}
|
99
|
+
elsif Config[:show_aliases]
|
90
100
|
puts "#{filename}:#{line}: #{rule.aliases.first || id} #{rule.description}"
|
91
101
|
else
|
92
102
|
puts "#{filename}:#{line}: #{id} #{rule.description}"
|
@@ -94,6 +104,13 @@ module MarkdownLint
|
|
94
104
|
end
|
95
105
|
end
|
96
106
|
end
|
107
|
+
|
108
|
+
if Config[:json]
|
109
|
+
puts JSON.generate(results)
|
110
|
+
elsif status != 0
|
111
|
+
puts "\nA detailed description of the rules is available at "\
|
112
|
+
"https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md"
|
113
|
+
end
|
97
114
|
exit status
|
98
115
|
end
|
99
116
|
end
|
data/lib/mdl/cli.rb
CHANGED
@@ -98,6 +98,12 @@ module MarkdownLint
|
|
98
98
|
:proc => Proc.new { puts MarkdownLint::VERSION },
|
99
99
|
:exit => 0
|
100
100
|
|
101
|
+
option :json,
|
102
|
+
:short => '-j',
|
103
|
+
:long => '--json',
|
104
|
+
:description => "JSON output",
|
105
|
+
:boolean => true
|
106
|
+
|
101
107
|
def run(argv=ARGV)
|
102
108
|
parse_options(argv)
|
103
109
|
|
data/lib/mdl/doc.rb
CHANGED
@@ -246,7 +246,7 @@ module MarkdownLint
|
|
246
246
|
# Extracts the text from an element whose children consist of text
|
247
247
|
# elements and other things
|
248
248
|
|
249
|
-
def extract_text(element, prefix="")
|
249
|
+
def extract_text(element, prefix="", restore_whitespace = true)
|
250
250
|
quotes = {
|
251
251
|
:rdquo => '"',
|
252
252
|
:ldquo => '"',
|
@@ -260,7 +260,7 @@ module MarkdownLint
|
|
260
260
|
if e.type == :text
|
261
261
|
e.value
|
262
262
|
elsif [:strong, :em, :p, :codespan].include?(e.type)
|
263
|
-
extract_text(e, prefix).join("\n")
|
263
|
+
extract_text(e, prefix, restore_whitespace).join("\n")
|
264
264
|
elsif e.type == :smart_quote
|
265
265
|
quotes[e.value]
|
266
266
|
end
|
@@ -268,7 +268,9 @@ module MarkdownLint
|
|
268
268
|
# Text blocks have whitespace stripped, so we need to add it back in at
|
269
269
|
# the beginning. Because this might be in something like a blockquote,
|
270
270
|
# we optionally strip off a prefix given to the function.
|
271
|
-
|
271
|
+
if restore_whitespace
|
272
|
+
lines[0] = element_line(element).sub(prefix, "")
|
273
|
+
end
|
272
274
|
lines
|
273
275
|
end
|
274
276
|
|
data/lib/mdl/rules.rb
CHANGED
@@ -33,7 +33,7 @@ rule "MD003", "Header style" do
|
|
33
33
|
# :style can be one of :consistent, :atx, :atx_closed, :setext
|
34
34
|
params :style => :consistent
|
35
35
|
check do |doc|
|
36
|
-
headers = doc.find_type_elements(:header)
|
36
|
+
headers = doc.find_type_elements(:header, false)
|
37
37
|
if headers.empty?
|
38
38
|
nil
|
39
39
|
else
|
@@ -257,7 +257,7 @@ rule "MD022", "Headers should be surrounded by blank lines" do
|
|
257
257
|
aliases 'blanks-around-headers'
|
258
258
|
check do |doc|
|
259
259
|
errors = []
|
260
|
-
doc.find_type_elements(:header).each do |h|
|
260
|
+
doc.find_type_elements(:header, false).each do |h|
|
261
261
|
header_bad = false
|
262
262
|
linenum = doc.element_linenumber(h)
|
263
263
|
# Check previous line
|
@@ -303,7 +303,7 @@ rule "MD023", "Headers must start at the beginning of the line" do
|
|
303
303
|
errors = []
|
304
304
|
# The only type of header with spaces actually parsed as such is setext
|
305
305
|
# style where only the text is indented. We check for that first.
|
306
|
-
doc.find_type_elements(:header).each do |h|
|
306
|
+
doc.find_type_elements(:header, false).each do |h|
|
307
307
|
errors << doc.element_linenumber(h) if doc.element_line(h).match(/^\s/)
|
308
308
|
end
|
309
309
|
# Next we have to look for things that aren't parsed as headers because
|
@@ -332,11 +332,42 @@ end
|
|
332
332
|
rule "MD024", "Multiple headers with the same content" do
|
333
333
|
tags :headers
|
334
334
|
aliases 'no-duplicate-header'
|
335
|
+
params :allow_different_nesting => false
|
335
336
|
check do |doc|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
337
|
+
headers = doc.find_type(:header)
|
338
|
+
allow_different_nesting = params[:allow_different_nesting]
|
339
|
+
|
340
|
+
duplicates = headers.select do |h|
|
341
|
+
headers.any? do |e|
|
342
|
+
e[:location] < h[:location] &&
|
343
|
+
e[:raw_text] == h[:raw_text] &&
|
344
|
+
(allow_different_nesting == false || e[:level] != h[:level])
|
345
|
+
end
|
346
|
+
end.to_set
|
347
|
+
|
348
|
+
if allow_different_nesting
|
349
|
+
same_nesting_duplicates = Set.new
|
350
|
+
stack = []
|
351
|
+
current_level = 0
|
352
|
+
doc.find_type(:header).each do |header|
|
353
|
+
level = header[:level]
|
354
|
+
text = header[:raw_text]
|
355
|
+
|
356
|
+
if current_level > level
|
357
|
+
stack.pop
|
358
|
+
elsif current_level < level
|
359
|
+
stack.push([text])
|
360
|
+
else
|
361
|
+
same_nesting_duplicates.add(header) if stack.last.include?(text)
|
362
|
+
end
|
363
|
+
|
364
|
+
current_level = level
|
365
|
+
end
|
366
|
+
|
367
|
+
duplicates += same_nesting_duplicates
|
368
|
+
end
|
369
|
+
|
370
|
+
duplicates.map { |h| doc.element_linenumber(h) }
|
340
371
|
end
|
341
372
|
end
|
342
373
|
|
@@ -345,7 +376,7 @@ rule "MD025", "Multiple top level headers in the same document" do
|
|
345
376
|
aliases 'single-h1'
|
346
377
|
params :level => 1
|
347
378
|
check do |doc|
|
348
|
-
headers = doc.find_type(:header).select { |h| h[:level] == params[:level] }
|
379
|
+
headers = doc.find_type(:header, false).select { |h| h[:level] == params[:level] }
|
349
380
|
if not headers.empty? and doc.element_linenumber(headers[0]) == 1
|
350
381
|
headers[1..-1].map { |h| doc.element_linenumber(h) }
|
351
382
|
end
|
@@ -544,11 +575,20 @@ end
|
|
544
575
|
rule "MD036", "Emphasis used instead of a header" do
|
545
576
|
tags :headers, :emphasis
|
546
577
|
aliases 'no-emphasis-as-header'
|
578
|
+
params :punctuation => '.,;:!?'
|
547
579
|
check do |doc|
|
548
580
|
# We are looking for a paragraph consisting entirely of emphasized
|
549
581
|
# (italic/bold) text.
|
550
|
-
|
551
|
-
|
582
|
+
errors = []
|
583
|
+
doc.find_type_elements(:p, false).each do |p|
|
584
|
+
next if p.children.length > 1
|
585
|
+
next unless [:em, :strong].include?(p.children[0].type)
|
586
|
+
lines = doc.extract_text(p.children[0], "", false)
|
587
|
+
next if lines.length > 1
|
588
|
+
next if lines[0].match(/[#{params[:punctuation]}]$/)
|
589
|
+
errors << doc.element_linenumber(p)
|
590
|
+
end
|
591
|
+
errors
|
552
592
|
end
|
553
593
|
end
|
554
594
|
|
@@ -579,10 +619,12 @@ rule "MD039", "Spaces inside link text" do
|
|
579
619
|
tags :whitespace, :links
|
580
620
|
aliases 'no-space-in-links'
|
581
621
|
check do |doc|
|
582
|
-
doc.element_linenumbers(
|
583
|
-
|
584
|
-
|
585
|
-
|
622
|
+
doc.element_linenumbers(
|
623
|
+
doc.find_type_elements(:a).select{|e|
|
624
|
+
e.children[0].type == :text and (
|
625
|
+
e.children.first.value.start_with?(" ") or
|
626
|
+
e.children.last.value.end_with?(" "))}
|
627
|
+
)
|
586
628
|
end
|
587
629
|
end
|
588
630
|
|
@@ -608,3 +650,29 @@ rule "MD041", "First line in file should be a top level header" do
|
|
608
650
|
or first_header[:level] != params[:level]
|
609
651
|
end
|
610
652
|
end
|
653
|
+
|
654
|
+
rule "MD046", "Code block style" do
|
655
|
+
tags :code
|
656
|
+
aliases 'code-block-style'
|
657
|
+
params :style => :fenced
|
658
|
+
check do |doc|
|
659
|
+
style = @params[:style]
|
660
|
+
doc.element_linenumbers(
|
661
|
+
doc.find_type_elements(:codeblock).select do |i|
|
662
|
+
# for consistent we determine the first one
|
663
|
+
if style == :consistent
|
664
|
+
if doc.element_line(i).start_with?(" ")
|
665
|
+
style = :indented
|
666
|
+
else
|
667
|
+
style = :fenced
|
668
|
+
end
|
669
|
+
end
|
670
|
+
if @params[:style] == :fenced
|
671
|
+
doc.element_line(i).start_with?(" ")
|
672
|
+
else
|
673
|
+
!doc.element_line(i).start_with?(" ")
|
674
|
+
end
|
675
|
+
end
|
676
|
+
)
|
677
|
+
end
|
678
|
+
end
|
data/lib/mdl/ruleset.rb
CHANGED
data/lib/mdl/version.rb
CHANGED
data/mdl.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["mark@mivok.net"]
|
11
11
|
spec.summary = %q{Markdown lint tool}
|
12
12
|
spec.description = %q{Style checker/lint tool for markdown files}
|
13
|
-
spec.homepage = "http://github.com/
|
13
|
+
spec.homepage = "http://github.com/markdownlint/markdownlint"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -0,0 +1 @@
|
|
1
|
+
rule 'MD046', :style => :consistent
|
@@ -0,0 +1 @@
|
|
1
|
+
rule 'MD046', :style => :fenced
|
@@ -0,0 +1 @@
|
|
1
|
+
rule 'MD046', :style => :indented
|
@@ -33,3 +33,8 @@ even though the emphasized text is on its own line.
|
|
33
33
|
|
34
34
|
This is another **normal** paragraph with some text in it. This also should
|
35
35
|
not trigger the rule.
|
36
|
+
|
37
|
+
**This is an entire paragraph that has been emphasized, and shouldn't be
|
38
|
+
detected as a header because it's on multiple lines**
|
39
|
+
|
40
|
+
**This also shouldn't be detected as a header as it ends in punctuation.**
|
@@ -0,0 +1,8 @@
|
|
1
|
+
[test _test_ test](www.test.com)
|
2
|
+
[test `test` test](www.test.com)
|
3
|
+
[test *test* test](www.test.com)
|
4
|
+
[test *test* *test* test](www.test.com)
|
5
|
+
[test *test* *test* *test* test](www.test.com)
|
6
|
+
[test **test** test](www.test.com)
|
7
|
+
[test __test__ test](www.test.com)
|
8
|
+
[this should not raise](www.shouldnotraise.com)
|
@@ -0,0 +1 @@
|
|
1
|
+
rule "MD024", :allow_different_nesting => true
|
data/test/test_cli.rb
CHANGED
@@ -183,14 +183,21 @@ class TestCli < Minitest::Test
|
|
183
183
|
def test_directory_scanning
|
184
184
|
path = File.expand_path("./fixtures/dir_with_md_and_markdown", File.dirname(__FILE__))
|
185
185
|
result = run_cli("#{path}")
|
186
|
-
|
186
|
+
lines_output = result[:stdout].lines
|
187
|
+
interested_lines = lines_output[0..(lines_output.count - 3)]
|
188
|
+
files_with_issues = interested_lines.map { |l| l.split(":")[0] }.sort
|
187
189
|
assert_equal(files_with_issues, ["#{path}/bar.markdown", "#{path}/foo.md"])
|
188
190
|
end
|
189
191
|
|
190
192
|
def test_ignore_front_matter
|
191
193
|
path = File.expand_path("./fixtures/front_matter", File.dirname(__FILE__))
|
192
194
|
result = run_cli("-i -r MD001,MD041,MD034 #{path}")
|
193
|
-
|
195
|
+
|
196
|
+
expected = \
|
197
|
+
"#{path}/jekyll_post.md:16: MD001 Header levels should only increment by one level at a time"\
|
198
|
+
"\n\nA detailed description of the rules is available at https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md\n"
|
199
|
+
|
200
|
+
assert_equal(result[:stdout], expected)
|
194
201
|
end
|
195
202
|
|
196
203
|
private
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Docker container for markdownlint
|
2
|
+
|
3
|
+
## Using the docker image
|
4
|
+
|
5
|
+
To check a single file:
|
6
|
+
|
7
|
+
docker run --rm -v ${PWD}:/data mivok/markdownlint myfile.md
|
8
|
+
|
9
|
+
Or, to check all files in a directory:
|
10
|
+
|
11
|
+
docker run --rm -v ${PWD}:/data mivok/markdownlint .
|
12
|
+
|
13
|
+
## Building from a docker file
|
14
|
+
|
15
|
+
The following will tag and upload a new release. Replace X.Y.Z as appropriate.
|
16
|
+
|
17
|
+
docker build -t mivok/markdownlint:latest -t mivok/markdownlint:X.Y.Z .
|
18
|
+
docker push mivok/markdownlint:latest
|
19
|
+
docker push mivok/markdownling:X.Y.Z
|
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.5.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: 2018-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -181,8 +181,14 @@ files:
|
|
181
181
|
- test/rule_tests/bulleted_list_2_space_indent_style.rb
|
182
182
|
- test/rule_tests/bulleted_list_4_space_indent.md
|
183
183
|
- test/rule_tests/bulleted_list_not_at_beginning_of_line.md
|
184
|
+
- test/rule_tests/code_block_consistency.md
|
185
|
+
- test/rule_tests/code_block_consistency_style.rb
|
184
186
|
- test/rule_tests/code_block_dollar.md
|
185
187
|
- test/rule_tests/code_block_dollar_fence.md
|
188
|
+
- test/rule_tests/code_block_fenced.md
|
189
|
+
- test/rule_tests/code_block_fenced_style.rb
|
190
|
+
- test/rule_tests/code_block_indented.md
|
191
|
+
- test/rule_tests/code_block_indented_style.rb
|
186
192
|
- test/rule_tests/consecutive_blank_lines.md
|
187
193
|
- test/rule_tests/consistent_bullet_styles_asterisk.md
|
188
194
|
- test/rule_tests/consistent_bullet_styles_dash.md
|
@@ -202,7 +208,11 @@ files:
|
|
202
208
|
- test/rule_tests/first_line_top_level_header_atx_style.rb
|
203
209
|
- test/rule_tests/first_line_top_level_header_setext.md
|
204
210
|
- test/rule_tests/first_line_top_level_header_setext_style.rb
|
211
|
+
- test/rule_tests/fix_102_extra_nodes_in_link_text.md
|
205
212
|
- test/rule_tests/header_duplicate_content.md
|
213
|
+
- test/rule_tests/header_duplicate_content_different_nesting.md
|
214
|
+
- test/rule_tests/header_duplicate_content_different_nesting_style.rb
|
215
|
+
- test/rule_tests/header_duplicate_content_no_different_nesting.md
|
206
216
|
- test/rule_tests/header_multiple_toplevel.md
|
207
217
|
- test/rule_tests/header_mutliple_h1_no_toplevel.md
|
208
218
|
- test/rule_tests/header_trailing_punctuation.md
|
@@ -212,6 +222,7 @@ files:
|
|
212
222
|
- test/rule_tests/headers_good.md
|
213
223
|
- test/rule_tests/headers_good_setext_with_atx.md
|
214
224
|
- test/rule_tests/headers_good_setext_with_atx_style.rb
|
225
|
+
- test/rule_tests/headers_good_with_issue_numbers.md
|
215
226
|
- test/rule_tests/headers_surrounding_space_atx.md
|
216
227
|
- test/rule_tests/headers_surrounding_space_setext.md
|
217
228
|
- test/rule_tests/headers_with_spaces_at_the_beginning.md
|
@@ -270,9 +281,11 @@ files:
|
|
270
281
|
- test/test_ruledocs.rb
|
271
282
|
- test/test_rules.rb
|
272
283
|
- tools/README.md
|
284
|
+
- tools/docker/Dockerfile
|
285
|
+
- tools/docker/README.md
|
273
286
|
- tools/test_location.rb
|
274
287
|
- tools/view_markdown.rb
|
275
|
-
homepage: http://github.com/
|
288
|
+
homepage: http://github.com/markdownlint/markdownlint
|
276
289
|
licenses:
|
277
290
|
- MIT
|
278
291
|
metadata: {}
|
@@ -292,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
305
|
version: '0'
|
293
306
|
requirements: []
|
294
307
|
rubyforge_project:
|
295
|
-
rubygems_version: 2.
|
308
|
+
rubygems_version: 2.7.6
|
296
309
|
signing_key:
|
297
310
|
specification_version: 4
|
298
311
|
summary: Markdown lint tool
|
@@ -316,8 +329,14 @@ test_files:
|
|
316
329
|
- test/rule_tests/bulleted_list_2_space_indent_style.rb
|
317
330
|
- test/rule_tests/bulleted_list_4_space_indent.md
|
318
331
|
- test/rule_tests/bulleted_list_not_at_beginning_of_line.md
|
332
|
+
- test/rule_tests/code_block_consistency.md
|
333
|
+
- test/rule_tests/code_block_consistency_style.rb
|
319
334
|
- test/rule_tests/code_block_dollar.md
|
320
335
|
- test/rule_tests/code_block_dollar_fence.md
|
336
|
+
- test/rule_tests/code_block_fenced.md
|
337
|
+
- test/rule_tests/code_block_fenced_style.rb
|
338
|
+
- test/rule_tests/code_block_indented.md
|
339
|
+
- test/rule_tests/code_block_indented_style.rb
|
321
340
|
- test/rule_tests/consecutive_blank_lines.md
|
322
341
|
- test/rule_tests/consistent_bullet_styles_asterisk.md
|
323
342
|
- test/rule_tests/consistent_bullet_styles_dash.md
|
@@ -337,7 +356,11 @@ test_files:
|
|
337
356
|
- test/rule_tests/first_line_top_level_header_atx_style.rb
|
338
357
|
- test/rule_tests/first_line_top_level_header_setext.md
|
339
358
|
- test/rule_tests/first_line_top_level_header_setext_style.rb
|
359
|
+
- test/rule_tests/fix_102_extra_nodes_in_link_text.md
|
340
360
|
- test/rule_tests/header_duplicate_content.md
|
361
|
+
- test/rule_tests/header_duplicate_content_different_nesting.md
|
362
|
+
- test/rule_tests/header_duplicate_content_different_nesting_style.rb
|
363
|
+
- test/rule_tests/header_duplicate_content_no_different_nesting.md
|
341
364
|
- test/rule_tests/header_multiple_toplevel.md
|
342
365
|
- test/rule_tests/header_mutliple_h1_no_toplevel.md
|
343
366
|
- test/rule_tests/header_trailing_punctuation.md
|
@@ -347,6 +370,7 @@ test_files:
|
|
347
370
|
- test/rule_tests/headers_good.md
|
348
371
|
- test/rule_tests/headers_good_setext_with_atx.md
|
349
372
|
- test/rule_tests/headers_good_setext_with_atx_style.rb
|
373
|
+
- test/rule_tests/headers_good_with_issue_numbers.md
|
350
374
|
- test/rule_tests/headers_surrounding_space_atx.md
|
351
375
|
- test/rule_tests/headers_surrounding_space_setext.md
|
352
376
|
- test/rule_tests/headers_with_spaces_at_the_beginning.md
|