aboutsummaryrefslogtreecommitdiff
path: root/converter.py
diff options
context:
space:
mode:
authordx <aryadevchavali1@gmail.com>2020-05-05 22:32:18 +0100
committerdx <aryadevchavali1@gmail.com>2020-05-06 00:54:40 +0100
commit4c9a79a8f44b61d6533a2dbe671ade85eae2db0e (patch)
treec3d43db6126f493c2822786d029c60f30dd800cc /converter.py
parent4d51607a8f54745affe6d6ab20850375dc032916 (diff)
downloadmdhtml-4c9a79a8f44b61d6533a2dbe671ade85eae2db0e.tar.gz
mdhtml-4c9a79a8f44b61d6533a2dbe671ade85eae2db0e.tar.bz2
mdhtml-4c9a79a8f44b61d6533a2dbe671ade85eae2db0e.zip
+rule parser for markdown translation
Using re.sub, translate certain lines of markdown into html equivalents. Currently supports: '#', '**' and '*'.
Diffstat (limited to 'converter.py')
-rw-r--r--converter.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/converter.py b/converter.py
index 6d8ae8d..33b4959 100644
--- a/converter.py
+++ b/converter.py
@@ -32,3 +32,19 @@ header = []
with open(options.header, 'r') as file:
header = file.readlines()
+"""Read and compile markdown to HTML"""
+markdown_compiled = []
+for filename in markdown_files:
+ file_lines = []
+ with open(filename, 'r') as file:
+ file_lines = file.readlines()
+ content_parsed = []
+ 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)
+ content_parsed.append(line)
+ markdown_compiled.append({'name': filename, 'content': content_parsed})
+