-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter.py
37 lines (26 loc) · 971 Bytes
/
formatter.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
from common import log
class Formatter:
def __init__(self, config):
self.__config = config
def get_formatted_content(self, content):
"""
Get formatted content according config.json
:param content: source content
:return: formatted content
"""
log("Formatting content...")
result_content = []
length = self.__config['line_length']
if not isinstance(content, list):
content = [content]
for line in content:
new_lines = []
space_pos = -1
while len(line) > length and space_pos != 0:
temp_line = line[:length]
space_pos = temp_line.rfind(' ')
new_lines.append(line[:space_pos])
line = line[space_pos:]
new_lines.append(line + "\n")
result_content.extend(new_lines)
return result_content