Skip to content

Instantly share code, notes, and snippets.

@lumpenspace
Created July 11, 2024 05:34
Show Gist options
  • Save lumpenspace/fad4ab28b5ce25548da5d2394489b267 to your computer and use it in GitHub Desktop.
Save lumpenspace/fad4ab28b5ce25548da5d2394489b267 to your computer and use it in GitHub Desktop.
quickies
import re
def midrashify(text):
footnotes = []
footnote_count = 0
def replace_with_footnote(match):
nonlocal footnote_count
footnote_count += 1
content = match.group(1)
footnotes.append(content)
return f"[{footnote_count}]"
processed_text = re.sub(r'\(\(\((.*?)\)\)\)', replace_with_footnote, text)
if footnotes:
processed_text += "\n\nFootnotes:\n"
for i, note in enumerate(footnotes, 1):
processed_text += f"{i}. {note}\n"
return processed_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment