-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_vdr_manual.py
58 lines (48 loc) · 2.05 KB
/
convert_vdr_manual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python3
# Automated VDR repository mirror and wiki page generator
# Copyright © 2023 Manuel Reimer <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import re
from crosslink import crosslink
input_str = sys.stdin.read()
# Split paragraphs
paragraphs = input_str.split("\n\n")
for index, paragraph in enumerate(paragraphs):
lines = paragraph.split("\n")
# Match for headlines (single line with "underline")
if len(lines) == 2 and re.match(r'^-+$', lines[1]):
# Do not actually make them headers but bold text
print("**" + lines[0] + "**\n")
# Match for headlines (* in front of line)
elif len(lines) == 1 and lines[0][0] == "*":
print("## " + lines[0][2:] + "\n")
# Detect "preformatted tables".
elif " " in lines[0].strip() or " " in paragraph:
# Add two more space characters for a total of four.
for line in lines:
print(" " + line)
print("")
# Detect the footnote list
elif "(1)" in lines[0]:
for number in range(2,4):
paragraph = paragraph.replace(f"({number})", f"<br>({number})")
print(paragraph + "\n")
# All other paragraphs.
else:
# GitHub will misinterpret tildes for "strike-through" if not escaped
paragraph = paragraph.replace("~", "\\~")
# Add crosslinking and print paragraph
print(crosslink(paragraph) + "\n")