From 4c9a79a8f44b61d6533a2dbe671ade85eae2db0e Mon Sep 17 00:00:00 2001 From: dx Date: Tue, 5 May 2020 22:32:18 +0100 Subject: +rule parser for markdown translation Using re.sub, translate certain lines of markdown into html equivalents. Currently supports: '#', '**' and '*'. --- converter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'converter.py') 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 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) + content_parsed.append(line) + markdown_compiled.append({'name': filename, 'content': content_parsed}) + -- cgit v1.2.3-13-gbd6f