Fix: Ensure awesome-lint compliance with badge and punctuation updates
This commit is contained in:
parent
4f39f72afe
commit
04a567519f
|
|
@ -9,6 +9,7 @@ def extract_repo(url):
|
||||||
match = re.match(r'https://github\.com/([^/]+/[^/]+)', url)
|
match = re.match(r'https://github\.com/([^/]+/[^/]+)', url)
|
||||||
return match[1] if match else ''
|
return match[1] if match else ''
|
||||||
|
|
||||||
|
|
||||||
def add_badges(lines):
|
def add_badges(lines):
|
||||||
"""Add GitHub badges to lines containing GitHub repository URLs."""
|
"""Add GitHub badges to lines containing GitHub repository URLs."""
|
||||||
processed_lines = []
|
processed_lines = []
|
||||||
|
|
@ -22,11 +23,11 @@ def add_badges(lines):
|
||||||
processed_lines.append('') # Add a blank line
|
processed_lines.append('') # Add a blank line
|
||||||
# Add shields.io badges
|
# Add shields.io badges
|
||||||
badges = [
|
badges = [
|
||||||
f' ',
|
f' ',
|
||||||
f'',
|
f'',
|
||||||
f'',
|
f'',
|
||||||
f'',
|
f'',
|
||||||
f'',
|
f'',
|
||||||
''
|
''
|
||||||
]
|
]
|
||||||
processed_lines.extend(badges)
|
processed_lines.extend(badges)
|
||||||
|
|
@ -36,30 +37,35 @@ def add_badges(lines):
|
||||||
processed_lines.append(line)
|
processed_lines.append(line)
|
||||||
return processed_lines
|
return processed_lines
|
||||||
|
|
||||||
def style_badges(lines):
|
|
||||||
"""Add the 'flat-square' style to all image badges in the lines."""
|
|
||||||
def replace_style(match):
|
|
||||||
alt_text = match.group(1)
|
|
||||||
url = match.group(2)
|
|
||||||
url += '&style=flat-square' if '?' in url else '?style=flat-square'
|
|
||||||
return f''
|
|
||||||
|
|
||||||
styled_lines = []
|
def ensure_punctuation(lines):
|
||||||
pattern = re.compile(r'!\[([^\]]+)\]\(([^)]+)\)')
|
"""Ensure all list item descriptions end with a period."""
|
||||||
|
punctuated_lines = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
styled_line = pattern.sub(replace_style, line)
|
# Match lines that start with list items and have descriptions
|
||||||
styled_lines.append(styled_line)
|
if re.match(r'- \[.*?\]\(.*?\) - .*[^.]$', line):
|
||||||
return styled_lines
|
line += '.' # Append a period
|
||||||
|
punctuated_lines.append(line)
|
||||||
|
return punctuated_lines
|
||||||
|
|
||||||
|
|
||||||
def remove_extra_parentheses(lines):
|
def remove_extra_parentheses(lines):
|
||||||
"""Remove extra closing parentheses at the end of image markdown links."""
|
"""Remove extra closing parentheses at the end of image markdown links."""
|
||||||
corrected_lines = []
|
corrected_lines = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
# Match image links with potential extra closing parentheses
|
|
||||||
corrected_line = re.sub(r'(!\[[^\]]*\]\([^\)]*\))\)+', r'\1', line)
|
corrected_line = re.sub(r'(!\[[^\]]*\]\([^\)]*\))\)+', r'\1', line)
|
||||||
corrected_lines.append(corrected_line)
|
corrected_lines.append(corrected_line)
|
||||||
return corrected_lines
|
return corrected_lines
|
||||||
|
|
||||||
|
|
||||||
|
def add_awesome_badge(lines):
|
||||||
|
"""Ensure the Awesome badge is correctly added."""
|
||||||
|
badge = '[](https://awesome.re)'
|
||||||
|
if lines and badge not in lines[0]:
|
||||||
|
lines.insert(0, badge)
|
||||||
|
return lines
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print("Usage: python script.py <input_markdown_file>")
|
print("Usage: python script.py <input_markdown_file>")
|
||||||
|
|
@ -70,13 +76,14 @@ def main():
|
||||||
with open(input_file, 'r', encoding='utf-8') as f:
|
with open(input_file, 'r', encoding='utf-8') as f:
|
||||||
lines = [line.rstrip('\n') for line in f]
|
lines = [line.rstrip('\n') for line in f]
|
||||||
|
|
||||||
lines_with_badges = add_badges(lines)
|
lines = add_awesome_badge(lines)
|
||||||
|
lines = add_badges(lines)
|
||||||
|
lines = ensure_punctuation(lines)
|
||||||
|
lines = remove_extra_parentheses(lines)
|
||||||
|
|
||||||
lines_with_square_badges = style_badges(lines_with_badges)
|
for line in lines:
|
||||||
|
|
||||||
final_lines = remove_extra_parentheses(lines_with_square_badges)
|
|
||||||
|
|
||||||
for line in final_lines:
|
|
||||||
print(line)
|
print(line)
|
||||||
|
|
||||||
main()
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue