Skip to content

Instantly share code, notes, and snippets.

@capjamesg
Created October 9, 2022 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capjamesg/70ab3fd2eefac7cbb955a1b5deda0efe to your computer and use it in GitHub Desktop.
Save capjamesg/70ab3fd2eefac7cbb955a1b5deda0efe to your computer and use it in GitHub Desktop.
import re
note = "I am presently having coffee with @example. #coffee #lunch #breakfast" #* 10000
person_tags_reference = {
"example": ("Example Person", "example.com/bio"),
}
tags = ["coffee", "lunch", "breakfast"]
tags = {tag: tag for tag in tags}
note_tags = re.findall(r"#(\w+)", note)
person_tags = re.findall(r"@(\w+)", note)
all_tags = list(set(note_tags))
for tag in all_tags:
if tags.get(tag):
note = note.replace(
"#" + tag, f"<a href='https://jamesg.blog/tag/{tags[tag]}'>#{tag}</a>"
)
for tag in list(set(person_tags)):
if person_tags_reference.get(tag):
note = note.replace(
"@" + tag,
f"<a href='https://jamesg.blog/tag/{person_tags_reference[tag][1]}'>@{person_tags_reference[tag][0]}</a>",
)
print(note)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment