3 finput=open(sys.argv[1], "rt")
5 # read the whole file content to s
6 s = "".join(finput.readlines())
9 # normalize line endings
10 s = re.sub(r"\r\n", "\n", s)
12 # remove trailing whitespaces
13 s = re.sub(r"[ \t]+\n", "\n", s)
15 # compress multiple empty lines
17 s = re.sub(r"\n\n\n", "\n\n", s)
19 # remove empty line before ".." that terminates a code block
20 s = re.sub(r"\n\n\.\.\n", "\n..\n", s)
22 # move :: starting a code block to the end of previous line
23 s = re.sub(r"\n\n::\n", " ::\n", s)
25 # remove extra line breaks before/after _ or ,
26 s = re.sub(r"\n[ \t]*([_,])\n", r"\1", s)
28 # remove extra line breaks after `
29 s = re.sub(r"`\n", "` ", s)
31 # remove extra line breaks before `
32 s = re.sub(r"\n[ \t]*`", " `", s)
34 # remove links to wiki
35 s = re.sub(r"\n[ \t]*`id=\d[^`]+`__\n", "", s)
37 # remove trailing whitespaces one more time
38 s = re.sub(r"[ \t]+\n", "\n", s)
40 foutput=open(sys.argv[2], "wt")