aboutsummaryrefslogtreecommitdiff
path: root/converter.py
diff options
context:
space:
mode:
authordx <aryadevchavali1@gmail.com>2020-05-06 00:51:28 +0100
committerdx <aryadevchavali1@gmail.com>2020-05-06 00:54:40 +0100
commitf5911018610504e6d299ce4e465406fcd31277bf (patch)
tree4d907abd874af714a3e3a5ff09de19de2c4e065a /converter.py
parent9d9a604b830e113bf944af9bff6ea2cb91cfb054 (diff)
downloadmdhtml-f5911018610504e6d299ce4e465406fcd31277bf.tar.gz
mdhtml-f5911018610504e6d299ce4e465406fcd31277bf.tar.bz2
mdhtml-f5911018610504e6d299ce4e465406fcd31277bf.zip
+support for paragraphing
By checking at every line break whether paragraphing has been started, I can generate paragraphs quickly
Diffstat (limited to 'converter.py')
-rw-r--r--converter.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/converter.py b/converter.py
index afa28a3..9c8ee77 100644
--- a/converter.py
+++ b/converter.py
@@ -42,12 +42,23 @@ for filename in markdown_files:
with open(filename, 'r') as file:
file_lines = file.readlines()
content_parsed = []
+ started_paragraphing = False
+
for line in file_lines:
# NOTE: When parsing regexes, use \g<number> for the object capture
- # Sub rules
- line = sub(r"#(.*)", r"<h1>\g<1></h1>", line)
- line = sub(r"\*\*(.*)\*\*", r"<strong>\g<1></strong>", line)
- line = sub(r"\*(.*)\*", r"<i>\g<1></i>", line)
+ # Rules
+ if search(r"^#(.*)", line):
+ line = sub(r"^#(.*)", r"<h1>\g<1></h1>", line)
+ elif line.strip() == '' and started_paragraphing:
+ line = "</p>\n"
+ started_paragraphing = False
+ else:
+ # simple text
+ line = sub(r"\*\*(.*)\*\*", r"<strong>\g<1></strong>", line)
+ line = sub(r"\*(.*)\*", r"<i>\g<1></i>", line)
+ if not started_paragraphing:
+ started_paragraphing = True
+ line = "<p>\n" + line
content_parsed.append(line)
markdown_compiled.append({'name': filename, 'content': content_parsed})