From f5911018610504e6d299ce4e465406fcd31277bf Mon Sep 17 00:00:00 2001
From: dx
Date: Wed, 6 May 2020 00:51:28 +0100
Subject: +support for paragraphing
By checking at every line break whether paragraphing has been started, I
can generate paragraphs quickly
---
converter.py | 19 +++++++++++++++----
1 file 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 for the object capture
- # Sub rules
- line = sub(r"#(.*)", r"\g<1>
", line)
- line = sub(r"\*\*(.*)\*\*", r"\g<1>", line)
- line = sub(r"\*(.*)\*", r"\g<1>", line)
+ # Rules
+ if search(r"^#(.*)", line):
+ line = sub(r"^#(.*)", r"\g<1>
", line)
+ elif line.strip() == '' and started_paragraphing:
+ line = "
\n"
+ started_paragraphing = False
+ else:
+ # simple text
+ line = sub(r"\*\*(.*)\*\*", r"\g<1>", line)
+ line = sub(r"\*(.*)\*", r"\g<1>", line)
+ if not started_paragraphing:
+ started_paragraphing = True
+ line = "\n" + line
content_parsed.append(line)
markdown_compiled.append({'name': filename, 'content': content_parsed})
--
cgit v1.2.3-13-gbd6f