Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added reference link formatting into the markdown #10

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion graham.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,41 @@
if os.path.isfile(FILE):
os.remove(FILE)


def update_links_in_md(joined):

matches = re.findall(b"\[\d+\]", joined)

if not matches:
return joined

for match in set(matches):

def update_links(match):
counter[0] += 1
note_name = f"{title}_note{note_number}"
if counter[0] == 1:
return bytes(f"[{note_number}](#{note_name})", 'utf-8')
elif counter[0] == 2:
return bytes(f"<a name={note_name}>[{note_number}]</a>", 'utf-8')


counter = [0]

note_number = int(match.decode().strip("[]"))
match_regex = match.replace(b"[", b"\[").replace(b"]", b"\]")

joined = re.sub(match_regex, update_links, joined)


return joined


for entry in reversed(rss.entries):
URL = entry['link']
TITLE = entry['title']


try:
with urllib.request.urlopen(URL) as website:
content = website.read().decode('unicode_escape', "utf-8")
Expand All @@ -46,7 +77,10 @@
if re.match(r"^[\p{Z}\s]*(?:[^\p{Z}\s][\p{Z}\s]*){5,100}$", p)
else "\n"+p+"\n") for p in parsed.split("\n")]

file.write(" ".join(parsed).encode())
encoded = " ".join(parsed).encode()
update_with_links = update_links_in_md(encoded)
file.write(update_with_links)

print(f"✅ {ART_NO:03} {TITLE}")

with open(FILE, 'a+', newline='\n') as f:
Expand Down