mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
0d9e2748b1
commit
c9d5ed8091
|
@ -39,8 +39,8 @@ def manual_deny_follow_request(session, base_dir: str,
|
||||||
if deny_handle in open(rejected_follows_filename).read():
|
if deny_handle in open(rejected_follows_filename).read():
|
||||||
remove_from_follow_requests(base_dir, nickname, domain,
|
remove_from_follow_requests(base_dir, nickname, domain,
|
||||||
deny_handle, debug)
|
deny_handle, debug)
|
||||||
print(deny_handle + ' has already been rejected as a follower of ' +
|
print(deny_handle +
|
||||||
nickname)
|
' has already been rejected as a follower of ' + nickname)
|
||||||
return
|
return
|
||||||
|
|
||||||
remove_from_follow_requests(base_dir, nickname, domain, deny_handle, debug)
|
remove_from_follow_requests(base_dir, nickname, domain, deny_handle, debug)
|
||||||
|
|
78
markdown.py
78
markdown.py
|
@ -34,8 +34,8 @@ def _markdown_emphasis_html(markdown: str) -> str:
|
||||||
'_,': '</ul>,',
|
'_,': '</ul>,',
|
||||||
'_\n': '</ul>\n'
|
'_\n': '</ul>\n'
|
||||||
}
|
}
|
||||||
for md, html in replacements.items():
|
for md_str, html in replacements.items():
|
||||||
markdown = markdown.replace(md, html)
|
markdown = markdown.replace(md_str, html)
|
||||||
|
|
||||||
if markdown.startswith('**'):
|
if markdown.startswith('**'):
|
||||||
markdown = markdown[2:] + '<b>'
|
markdown = markdown[2:] + '<b>'
|
||||||
|
@ -60,26 +60,26 @@ def _markdown_replace_quotes(markdown: str) -> str:
|
||||||
return markdown
|
return markdown
|
||||||
lines = markdown.split('\n')
|
lines = markdown.split('\n')
|
||||||
result = ''
|
result = ''
|
||||||
prevQuoteLine = None
|
prev_quote_line = None
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if '> ' not in line:
|
if '> ' not in line:
|
||||||
result += line + '\n'
|
result += line + '\n'
|
||||||
prevQuoteLine = None
|
prev_quote_line = None
|
||||||
continue
|
continue
|
||||||
lineStr = line.strip()
|
line_str = line.strip()
|
||||||
if not lineStr.startswith('> '):
|
if not line_str.startswith('> '):
|
||||||
result += line + '\n'
|
result += line + '\n'
|
||||||
prevQuoteLine = None
|
prev_quote_line = None
|
||||||
continue
|
continue
|
||||||
lineStr = lineStr.replace('> ', '', 1).strip()
|
line_str = line_str.replace('> ', '', 1).strip()
|
||||||
if prevQuoteLine:
|
if prev_quote_line:
|
||||||
newPrevLine = prevQuoteLine.replace('</i></blockquote>\n', '')
|
new_prev_line = prev_quote_line.replace('</i></blockquote>\n', '')
|
||||||
result = result.replace(prevQuoteLine, newPrevLine) + ' '
|
result = result.replace(prev_quote_line, new_prev_line) + ' '
|
||||||
lineStr += '</i></blockquote>\n'
|
line_str += '</i></blockquote>\n'
|
||||||
else:
|
else:
|
||||||
lineStr = '<blockquote><i>' + lineStr + '</i></blockquote>\n'
|
line_str = '<blockquote><i>' + line_str + '</i></blockquote>\n'
|
||||||
result += lineStr
|
result += line_str
|
||||||
prevQuoteLine = lineStr
|
prev_quote_line = line_str
|
||||||
|
|
||||||
if '</blockquote>\n' in result:
|
if '</blockquote>\n' in result:
|
||||||
result = result.replace('</blockquote>\n', '</blockquote>')
|
result = result.replace('</blockquote>\n', '</blockquote>')
|
||||||
|
@ -94,37 +94,37 @@ def _markdown_replace_links(markdown: str, images: bool = False) -> str:
|
||||||
"""Replaces markdown links with html
|
"""Replaces markdown links with html
|
||||||
Optionally replace image links
|
Optionally replace image links
|
||||||
"""
|
"""
|
||||||
replaceLinks = {}
|
replace_links = {}
|
||||||
text = markdown
|
text = markdown
|
||||||
startChars = '['
|
start_chars = '['
|
||||||
if images:
|
if images:
|
||||||
startChars = '!['
|
start_chars = '!['
|
||||||
while startChars in text:
|
while start_chars in text:
|
||||||
if ')' not in text:
|
if ')' not in text:
|
||||||
break
|
break
|
||||||
text = text.split(startChars, 1)[1]
|
text = text.split(start_chars, 1)[1]
|
||||||
markdownLink = startChars + text.split(')')[0] + ')'
|
markdown_link = start_chars + text.split(')')[0] + ')'
|
||||||
if ']' not in markdownLink or \
|
if ']' not in markdown_link or \
|
||||||
'(' not in markdownLink:
|
'(' not in markdown_link:
|
||||||
text = text.split(')', 1)[1]
|
text = text.split(')', 1)[1]
|
||||||
continue
|
continue
|
||||||
if not images:
|
if not images:
|
||||||
replaceLinks[markdownLink] = \
|
replace_links[markdown_link] = \
|
||||||
'<a href="' + \
|
'<a href="' + \
|
||||||
markdownLink.split('(')[1].split(')')[0] + \
|
markdown_link.split('(')[1].split(')')[0] + \
|
||||||
'" target="_blank" rel="nofollow noopener noreferrer">' + \
|
'" target="_blank" rel="nofollow noopener noreferrer">' + \
|
||||||
markdownLink.split(startChars)[1].split(']')[0] + \
|
markdown_link.split(start_chars)[1].split(']')[0] + \
|
||||||
'</a>'
|
'</a>'
|
||||||
else:
|
else:
|
||||||
replaceLinks[markdownLink] = \
|
replace_links[markdown_link] = \
|
||||||
'<img class="markdownImage" src="' + \
|
'<img class="markdownImage" src="' + \
|
||||||
markdownLink.split('(')[1].split(')')[0] + \
|
markdown_link.split('(')[1].split(')')[0] + \
|
||||||
'" alt="' + \
|
'" alt="' + \
|
||||||
markdownLink.split(startChars)[1].split(']')[0] + \
|
markdown_link.split(start_chars)[1].split(']')[0] + \
|
||||||
'" />'
|
'" />'
|
||||||
text = text.split(')', 1)[1]
|
text = text.split(')', 1)[1]
|
||||||
for mdLink, htmlLink in replaceLinks.items():
|
for md_link, html_link in replace_links.items():
|
||||||
markdown = markdown.replace(mdLink, htmlLink)
|
markdown = markdown.replace(md_link, html_link)
|
||||||
return markdown
|
return markdown
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,8 +137,8 @@ def markdown_to_html(markdown: str) -> str:
|
||||||
markdown = _markdown_replace_links(markdown)
|
markdown = _markdown_replace_links(markdown)
|
||||||
|
|
||||||
# replace headers
|
# replace headers
|
||||||
linesList = markdown.split('\n')
|
lines_list = markdown.split('\n')
|
||||||
htmlStr = ''
|
html_str = ''
|
||||||
ctr = 0
|
ctr = 0
|
||||||
titles = {
|
titles = {
|
||||||
"h5": '#####',
|
"h5": '#####',
|
||||||
|
@ -147,15 +147,15 @@ def markdown_to_html(markdown: str) -> str:
|
||||||
"h2": '##',
|
"h2": '##',
|
||||||
"h1": '#'
|
"h1": '#'
|
||||||
}
|
}
|
||||||
for line in linesList:
|
for line in lines_list:
|
||||||
if ctr > 0:
|
if ctr > 0:
|
||||||
htmlStr += '<br>'
|
html_str += '<br>'
|
||||||
for h, hashes in titles.items():
|
for hsh, hashes in titles.items():
|
||||||
if line.startswith(hashes):
|
if line.startswith(hashes):
|
||||||
line = line.replace(hashes, '').strip()
|
line = line.replace(hashes, '').strip()
|
||||||
line = '<' + h + '>' + line + '</' + h + '>'
|
line = '<' + hsh + '>' + line + '</' + hsh + '>'
|
||||||
ctr = -1
|
ctr = -1
|
||||||
break
|
break
|
||||||
htmlStr += line
|
html_str += line
|
||||||
ctr += 1
|
ctr += 1
|
||||||
return htmlStr
|
return html_str
|
||||||
|
|
Loading…
Reference in New Issue