Create line break detection

This commit is contained in:
Jose De Freitas 2021-02-24 12:19:43 -05:00
parent f125957be7
commit 8c07faaf2c
2 changed files with 71 additions and 53 deletions

View File

@ -3,7 +3,7 @@ import pathlib
here = pathlib.Path(__file__).parent
file_readme = here / '../../test.md'
with open(file_readme, 'r') as read_readme:
content_readme = read_readme.readlines()
content = read_readme.readlines()
class ContentAbout():
@ -22,7 +22,7 @@ class ContentAbout():
checker = "Content about:"
def __init__(self):
self.result = "🟢 No errors found."
self.result = "🟢 0: perfect."
def trailing_slash(self) -> str:
"""
@ -30,17 +30,19 @@ class ContentAbout():
lines ("Content about:" lines).
"""
for line, value in enumerate(content_readme):
for line, value in enumerate(content):
if self.checker in value:
last = value[-2]
if last != '\\':
if last == ' ':
content_readme[line] = f"{value[:-1]}\\\n"
if last != "\\":
if last == " ":
content[line] = f"{value[:-1]}\\\n"
else:
content_readme[line] = f"{value[:-1]} \\\n"
content[line] = f"{value[:-1]} \\\n"
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
self.result = "🔴 Trailing slash wasn't found.\nFixed."
write_readme.writelines(content)
self.result = "🔴 -1: line break.\nFixed."
return self.result
@ -51,7 +53,7 @@ class ContentAbout():
", ".
"""
# for line, value in enumerate(content_readme):
# for line, value in enumerate(content):
# if self.checker in value:
return self.result

View File

@ -3,62 +3,78 @@ import pathlib
here = pathlib.Path(__file__).parent
file_readme = here / '../../test.md'
with open(file_readme, 'r') as read_readme:
content_readme = read_readme.readlines()
content = read_readme.readlines()
def featured_playlists():
class FeaturedPlaylists():
"""
Looks for trailing slashes and words separated by commas at
every "Featured playlists:" section found in the readme.md file
(this is, the list itself).
Contains methods for the detection of various
rules asigned to the "Featured playlists:" sections.
These methods edit the readme.md file (the awe-
some list) in-place if any of the rules isn't
met.
result (str): return value of the function.
checker (str): detector of the line corresponding the file.
length (int): length of the corresponding line.
Attributes:
checker (str): matches the "Featured playlists:" string.
length (int): minimum length of the line to break line.
result (str): result of the operation.
"""
result = 'No errors found.'
checker = 'Featured playlists:'
checker = "Featured playlists:"
length = 124
for line, value in enumerate(content_readme):
if checker in value:
def __init__(self):
self.result = "🟢 0: perfect."
words = value[len(checker)+1:-4]
# Check for trailing slash
if len(value) < length and value[-2] != '\\':
if value[-2] == ' ':
content_readme[line] = value[:-1] + '\\' + '\n<br/>\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
else:
content_readme[line] = value[:-1] + ' \\' + '\n<br/>\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
def trailing_slash(self):
"""
Looks for backslash and the end of all the matching
lines ("Featured playlists:" lines) and a line
break tag "<br>" at the next line.
"""
result = "Trailing slash wasn't found.\nFixed."
# Check for well-formatted backsticks
if value.count('`') % 2 != 0:
content = words.split(', ')
fix_words = []
for line, value in enumerate(content):
if self.checker in value:
last = value[-2]
if len(value) < self.length:
if last != "\\" and "<br>" not in content[line+1]:
if last == " ":
content[line] = f"{value[:-1]}\\\n<br>\n"
else:
content[line] = f"{value[:-1]} \\\n<br>\n"
for topic in content:
if topic[0] != '`' and topic[-1] != '`':
fix_words.append('`' + topic + '`')
elif topic[-1] != '`':
fix_words.append(topic + '`')
elif topic[0] != '`':
fix_words.append('`' + topic)
else:
fix_words.append(topic)
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content)
content_readme[line] = value[:len(checker)] + ' ' + ', '.join(fix_words) + '. \\\n'
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme)
self.result = "🔴 -1: backslash | line break.\nFixed."
elif last != "\\" and "<br>" in content[line+1]:
if last == " ":
content[line] = f"{value[:-1]}\\\n"
else:
content[line] = f"{value[:-1]} \\\n"
result = "Backsticks weren't found.\nFixed."
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content)
return result
self.result = "🔴 -1: backslash.\nFixed."
elif last == "\\" and "<br>" not in content[line+1]:
content[line+1] = "<br>\n\n"
with open(file_readme, 'w') as write_readme:
write_readme.writelines(content)
self.result = "🔴 -1: line break.\nFixed."
return self.result
def closed_backsticks(self):
"""
Looks that all backsticks of every word are co-
rrectly opened and subsequent closed.
"""
return self.result
print(featured_playlists())
featured_playlists = FeaturedPlaylists()
print(featured_playlists.trailing_slash())