forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarkdownBear.py
107 lines (99 loc) · 5.02 KB
/
MarkdownBear.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import json
from coalib.bearlib.abstractions.Linter import linter
from coalib.bears.requirements.NpmRequirement import NpmRequirement
@linter(executable='remark',
use_stdin=True,
output_format='corrected',
result_message='The text does not comply to the set style.')
class MarkdownBear:
"""
Check and correct Markdown style violations automatically.
See <https://github.com/wooorm/remark-lint> for details about the tool
below.
"""
LANGUAGES = {"Markdown"}
REQUIREMENTS = {NpmRequirement('remark', '3')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
CAN_FIX = {'Formatting'}
@staticmethod
def create_arguments(filename, file, config_file,
markdown_bullets: str="-",
markdown_closed_headings: bool=False,
markdown_setext_headings: bool=False,
markdown_emphasis: str="*",
markdown_strong: str="*",
markdown_encode_entities: bool=False,
markdown_codefence: str="`",
markdown_fences: bool=True,
markdown_list_indent: str="1",
markdown_loose_tables: bool=False,
markdown_spaced_tables: bool=True,
markdown_list_increment: bool=True,
markdown_horizontal_rule: str='*',
markdown_horizontal_rule_spaces: bool=False,
markdown_horizontal_rule_repeat: int=3):
"""
:param markdown_bullets:
Character to use for bullets in lists. Can be "-", "*" or "+".
:param markdown_closed_headings:
Whether to close Atx headings or not. if true, extra # marks will
be required after the heading. eg: `## Heading ##`.
:param markdown_setext_headings:
Whether to use setext headings. A setext heading uses underlines
instead of # marks.
:param markdown_emphasis:
Character to wrap strong emphasis by. Can be "_" or "*".
:param markdown_strong:
Character to wrap slight emphasis by. Can be "_" or "*".
:param markdown_encode_entities:
Whether to encode symbols that are not ASCII into special HTML
characters.
:param markdown_codefence:
Used to find which characters to use for code fences. Can be "`" or
"~".
:param markdown_fences:
Use fences for code blocks.
:param markdown_list_indent:
Used to find spacing after bullet in lists. Can be "1", "tab" or
"mixed".
- "1" - 1 space after bullet.
- "tab" - Use tab stops to begin a sentence after the bullet.
- "mixed" - Use "1" when the list item is only 1 line, "tab" if it
spans multiple.
:param markdown_loose_tables:
Whether to use pipes for the outermost borders in a table.
:param markdown_spaced_tables:
Whether to add space between pipes in a table.
:param markdown_list_increment:
Whether an ordered lists numbers should be incremented.
:param markdown_horizontal_rule:
The horizontal rule character. Can be '*', '_' or '-'.
:param markdown_horizontal_rule_spaces:
Whether spaces should be added between horizontal rule characters.
:param markdown_horizontal_rule_repeat:
The number of times the horizontal rule character will be repeated.
"""
remark_configs = {
"bullet": markdown_bullets, # - or *
"closeAtx": markdown_closed_headings, # Bool
"setext": markdown_setext_headings, # Bool
"emphasis": markdown_emphasis, # char (_ or *)
"strong": markdown_strong, # char (_ or *)
"entities": markdown_encode_entities, # Bool
"fence": markdown_codefence, # char (~ or `)
"fences": markdown_fences, # Bool
"listItemIndent": markdown_list_indent, # int or "tab"
# or "mixed"
"looseTable": markdown_loose_tables, # Bool
"spacedTable": markdown_spaced_tables, # Bool
"incrementListMarker": markdown_list_increment, # Bool
"rule": markdown_horizontal_rule, # - or * or _
"ruleSpaces": markdown_horizontal_rule_spaces, # Bool
"ruleRepetition": markdown_horizontal_rule_repeat, # int
}
config_json = json.dumps(remark_configs)
# Remove { and } as remark adds them on its own
settings = config_json[1:-1]
return '--no-color', '--quiet', '--setting', settings