Skip to content

Instantly share code, notes, and snippets.

@DocShotgun
Last active September 1, 2023 03:21
Show Gist options
  • Select an option

  • Save DocShotgun/f20656b20081c5f4e6b8b7e2386d51fe to your computer and use it in GitHub Desktop.

Select an option

Save DocShotgun/f20656b20081c5f4e6b8b7e2386d51fe to your computer and use it in GitHub Desktop.
Scuffed script to convert markdown roleplay text into novel format
import sys
read_file = open(sys.argv[1],"r")
roleplay_text = read_file.read()
read_file.close()
def convert_md_to_novel(text):
novel = ""
if '*' in text:
parts = text.split('*')
for part in parts:
if (parts.index(part) % 2) == 0 and part.strip() is not "":
part = part.strip()
if part.startswith('"') and part.endswith('"'):
novel = novel + part + ' '
else:
part = '"' + part + '"'
novel = novel + part + ' '
elif (parts.index(part) % 2) != 0 and part.strip() is not "":
novel = novel + part.strip() + ' '
else:
novel = '"' + text.strip() + '"'
return novel.strip()
write_file = open("output.txt","w")
final_text = ""
exclude = r"<>[]()"
lines = roleplay_text.strip().split("\n")
for line in lines:
line = line.strip()
if line is "":
final_text = final_text + "\n"
elif any(elem in line for elem in exclude):
final_text = final_text + line + "\n"
elif line.startswith("{{user}}:"):
line = line.replace("{{user}}:","",1)
final_text = final_text + "{{user}}: " + convert_md_to_novel(line) + "\n"
elif line.startswith("{{char}}:"):
line = line.replace("{{char}}:","",1)
final_text = final_text + "{{char}}: " + convert_md_to_novel(line) + "\n"
else:
final_text = final_text + convert_md_to_novel(line) + "\n"
write_file.write(final_text.strip())
write_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment