import argparse, re, sys
def fd_fn_forward(post_id, note_id):
return f""
def fd_fn_reverse(post_id, note_id, note_txt):
return f"
{note_txt} ";
if __name__ == "__main__":
p = argparse.ArgumentParser(description="CC notes formatter")
p.add_argument("--text", "-t", help="Text file", required=True)
p.add_argument("--divider", "-d", help="In-text markup divider for notes", default="## Notes")
p.add_argument("--output", "-o", help="Output file", required=True)
p.add_argument("--format", "-f", help="Output format (cc, html)", default="cc")
args = p.parse_args()
notes = {}
with open(args.text) as fp:
text = fp.read()
s = text.split(args.divider)
if len(s) != 2:
print(f"Problem spliting text with divider {args.divider}.")
exit(0)
NOTES = s[1].splitlines()
## notes
for l in NOTES:
n = re.search(r'\[\d+\\]', l)
if n:
notes[l[n.start()+1:n.end()-2]] = l[n.end():].strip()
txt_lines = []
if args.format == "html":
POST_ID = 512
notes_lines = ["Notes
", f"")
if args.output:
with open(args.output, 'w') as fp:
fp.writelines(txt_lines)
if args.format == "html":
fp.writelines(s + '\n' for s in notes_lines)
else:
sys.stdout.writelines(txt_lines)
if args.format == "html":
sys.stdout.writelines(s + '\n' for s in notes_lines)