Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save DocShotgun/385cb10b5364d3f3a1e694bbb49d29ed to your computer and use it in GitHub Desktop.
Scuffed script to convert novel style roleplay text into markdown format
import sys
read_file = open(sys.argv[1],"r")
roleplay_text = read_file.read()
read_file.close()
def convert_novel_to_md(text):
md = ""
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('*'):
md = md + part + ' '
else:
part = '*' + part + '*'
md = md + part + ' '
elif (parts.index(part) % 2) != 0 and part.strip() is not "":
md = md + part.strip() + ' '
else:
md = '*' + text.strip() + '*'
return md.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_novel_to_md(line) + "\n"
elif line.startswith("{{char}}:"):
line = line.replace("{{char}}:","",1)
final_text = final_text + "{{char}}: " + convert_novel_to_md(line) + "\n"
else:
final_text = final_text + convert_novel_to_md(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