Skip to content

Commit

Permalink
Merge branch 'main' into issue-12
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-pham authored Oct 5, 2021
2 parents f19c46e + 0271c41 commit 8f4d10c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
14 changes: 7 additions & 7 deletions dist/test2.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<!doctype html>
<html lang="br">
<html lang="en=CA">
<head>
<meta charset="utf-8">
<title># this is heading level 1</title>
<title># This is heading level 1</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1># this is heading level 1</h1>
<h1># This is heading level 1</h1>


<p>>>>>>>> issue-10
</p>
>>>>>>> issue-10

</p><em>italic Text attributes</em>,
<hr/>
<strong>bold used for test.</strong>
<p>
</body>
</html>

37 changes: 13 additions & 24 deletions magic_ssg.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,24 @@ def generate_txt_content(file_path, title):


def generate_md_content(file_path, title):
count = 0
i = 0
global pline1
global pline2
global pline3
pline1 = ""
pline2 = ""
pline3 = ""

titled_format = "<h1>{}</h1>\n\n\n{}"
content = ""

with open(file_path, "r", encoding="utf8") as input_file:
for lines in input_file.readlines():
# the line has italic markdown

pline1 = re.sub(r'\*([^\s\*.]{1}.*?)\*|_([^\s\_.]{1}.*?)_',
lambda s: "<i>{}</i>".format(s[0][1:-1]), lines)
# the line has horizontal rule in markdown
pline2 = re.sub(r'(^---$)',
lambda s: "<hr/>".format(s[0]), lines)

# the line has bold markdown
pline3 = re.sub(r'(__[^\r\n\_].*?__)|(\*\*[^\r\n\*].*?\*\*)',
lambda s: "<b>{}</b>".format(s[0][2:-2]), lines)

content = pline1 + "</p>" + "\n"
content = content + pline3
content = "<p>" + content
lines = ''.join(input_file.readlines()[2:])

# the line has bold markdown
content = re.sub(
'\*\*([^\s\*.]{1}.*?)\*\*|__([^\s_.]{1}.*?)__', r'<strong>\1</strong>', lines)
# the line has italic markdown
content = re.sub(
'\*([^\s\*.]{1}.*?)\*|_([^\s\_.]{1}.*?)_', r'<em>\2</em>', content)
# the line has horizontal rule in markdown
content = re.sub(
'(\n|(\n<p>))\s{0,3}((---)|(\*\*\*))\s{0,3}((</p>\n)|\n)', r'\n<hr/>\n', content)

content = "</p>" + content + "<p>"
content = titled_format.format(title, content)
return content

Expand Down
10 changes: 1 addition & 9 deletions test2.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# this is heading level 1
# This is heading level 1

<<<<<<< HEAD
_Text attributes italic_,

---

**bold used for test**.
=======
_italic Text attributes_,

---

**bold used for test.**
>>>>>>> issue-10

0 comments on commit 8f4d10c

Please sign in to comment.