Skip to content

Commit

Permalink
Add consistent option
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymzh committed Jun 7, 2018
1 parent 7f6482c commit 2893101
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ Tags: code

Aliases: code-block-style

Parameters: style ("fenced", "indented", default "fenced")
Parameters: style ("fenced", "indented", "consistent", default "fenced")

This rule is truggered what a different code block style is used than the
configured one. For example, in the default configuration this triggers:
Expand Down
9 changes: 9 additions & 0 deletions lib/mdl/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,17 @@ def check_blockquote(errors, elements)
aliases 'code-block-style'
params :style => :fenced
check do |doc|
style = @params[:style]
doc.element_linenumbers(
doc.find_type_elements(:codeblock).select do |i|
# for consistent we determine the first one
if style == :consistent
if doc.element_line(i).start_with?(" ")
style = :indented
else
style = :fenced
end
end
if @params[:style] == :fenced
doc.element_line(i).start_with?(" ")
else
Expand Down
6 changes: 0 additions & 6 deletions test/rule_tests/code_block.md

This file was deleted.

11 changes: 11 additions & 0 deletions test/rule_tests/code_block_consistency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This is text.

This is a
code block.

And here is more text

```
and here is a different {MD046:8}
code block
```
1 change: 1 addition & 0 deletions test/rule_tests/code_block_consistency_style.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rule 'MD046', :style => :consistent
17 changes: 17 additions & 0 deletions test/rule_tests/code_block_fenced.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
This is text.

This is a {MD046}
code block.

And here is more text

```
This is a code block that won't trigger.
```

But we'll do another:

And this {MD046}
will.

Final text is here
1 change: 1 addition & 0 deletions test/rule_tests/code_block_fenced_style.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rule 'MD046', :style => :fenced
17 changes: 17 additions & 0 deletions test/rule_tests/code_block_indented.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
This is text.

This is a
code block.

And here is more text

```
This is {MD046:8} also a code block.
```

But we'll do another:

And this
will.

Final text is here
1 change: 1 addition & 0 deletions test/rule_tests/code_block_indented_style.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rule 'MD046', :style => :indented
1 change: 0 additions & 1 deletion test/rule_tests/code_block_style.rb

This file was deleted.

0 comments on commit 2893101

Please sign in to comment.