Skip to content

Instantly share code, notes, and snippets.

@Chrysaloid
Last active June 1, 2026 23:27
Show Gist options
  • Select an option

  • Save Chrysaloid/96939fba99232145ab6d41f06cf34be6 to your computer and use it in GitHub Desktop.

Select an option

Save Chrysaloid/96939fba99232145ab6d41f06cf34be6 to your computer and use it in GitHub Desktop.
Use this https://chromewebstore.google.com/detail/chatgpt-to-markdown-pro-c/adghjpdmpbcmppeafpodcjpagmegdpci extension to export a ChatGPT conversation to a known folder and convert them with this script so you can paste them (or their fragments) to Discord
from pathlib import Path
import re
import subprocess
folder = Path("G:/Biblioteki Windows/Pobrane")
filePath = next(folder.glob("*ChatGPT_Export.md"), None)
if not filePath:
print("Nothing to export")
input("Press ENTER to continue...")
exit(0)
with filePath.open("rt") as f:
content = f.read()
flags = re.MULTILINE
content = re.sub(r"[\t ]+$", "", content, flags=flags) # remove whitespace at the end of lines
content = re.sub(r"```\n([^\n]+)\n\n```", r"```\g<1>", content, flags=flags) # fix duplicate code block beginnings
content = re.sub(r"```\n```", "```", content, flags=flags) # fix duplicate code block endings
content = re.sub(r"\n\n+", "\n", content, flags=flags) # multiple new lines to sinle new line
content = re.sub(r"```\n(?!---|You:)", "```", content, flags=flags) # fix code block endings
content = re.sub(r"^(( )+)\1", r"\g<1>", content, flags=flags) # halve the numbers of spaces at the start of the line
content = re.sub(r"(?<![\n ]) +", " ", content, flags=flags) # replace multiple spaces not at the start of the line with a sinle space
content = re.sub(r"\nChatGPT:", r"\n\n\n✨ChatGPT:✨", content, flags=flags) # highlight ChatGPT and You headings
content = re.sub(r"(^|\n)You:", r"\g<1>\g<1>\g<1>🙂You:🙂", content, flags=flags)
newFile = folder / "ChatGPT.txt"
with newFile.open("wt") as f:
f.write(content)
if not content.endswith("\n"):
f.write("\n")
subprocess.Popen(["code", newFile], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
# chrome extension: https://chromewebstore.google.com/detail/chatgpt-to-markdown-pro-c/adghjpdmpbcmppeafpodcjpagmegdpci
# python "ChatGPT export to Discord.py"
@Chrysaloid

Copy link
Copy Markdown
Author

Updated replacement logic to fix export errors from chatgpt-to-markdown (I think). Mainly the duplicated code block delimiters "```"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment