-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatter.py
More file actions
28 lines (19 loc) · 752 Bytes
/
formatter.py
File metadata and controls
28 lines (19 loc) · 752 Bytes
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
class MarkdownFormatter:
@staticmethod
def list_with_heading(heading, values, with_leading_nums=True, sort=True):
answer = '*' + heading + '*\n'
if sort:
values.sort()
if with_leading_nums:
for idx, value in enumerate(values, 1):
answer += str(idx) + ' ' + value.replace('_', '\_') + '\n'
else:
for value in values:
answer += value.replace('_', '\_') + '\n'
return answer
@staticmethod
def map_with_heading(heading, values, with_leading_nums=True):
answer = '*' + heading + '*\n'
for key, val in values.items():
answer += key.replace('_', '\_') + ': ' + val + '\n'
return answer