|Python
|HTML
Markdown is awesome! All your README.md are made in Markdown, but do you know how GitHub are rendering them?
It’s time to code a Markdown to HTML!
- All your files will be interpreted/compiled on Ubuntu 18.04 LTS using python3 (version 3.7 or higher)
- The first line of all your files should be exactly #!/usr/bin/python3
- A README.md file, at the root of the folder of the project, is mandatory
- Your code should use the PEP 8 style (version 1.7.*)
- All your files must be executable
- All your modules should be documented: python3 -c 'print(import("my_module").doc)'
- Your code should not be executed when imported (by using if name == "main":)
Write a script markdown2html.py
that takes an argument 2 strings:
-
First argument is the name of the Markdown file
-
Second argument is the output file name Requirements:
-
If the number of arguments is less than 2: print in STDERR Usage: ./markdown2html.py README.md README.html and exit 1
-
If the Markdown file doesn’t exist: print in STDER Missing and exit 1
-
Otherwise, print nothing and exit 0
khalfan@vagrant:~/$ ./markdown2html.py
Usage: ./markdown2html.py README.md README.html
khalfan@vagrant:~/$ echo $?
1
khalfan@vagrant:~/$
khalfan@vagrant:~/$ ./markdown2html.py README.md README.html
Missing README.md
khalfan@vagrant:~/$ echo $?
1
khalfan@vagrant:~/$
khalfan@vagrant:~/$ echo "Test" > README.md
khalfan@vagrant:~/$ ./markdown2html.py README.md README.html
khalfan@vagrant:~/$
- GitHub repository: alx-frontend-for-fun
- File: markdown2html.py
Improve markdown2html.py by parsing Headings Markdown syntax for generating HTML:
Syntax: (you can assume it will be strictly this syntax)
Markdown | HTML generated |
---|---|
# Heading level 1 | |
## Heading level 2 | |
### Heading level 3 | |
#### Heading level 4 | |
##### Heading level 5 | |
###### Heading level 6 |
khalfan@vagrant:~/$ cat README.md
# My title
## My title2
# My title3
#### My title4
### My title5
khalfan@vagrant:~/$ ./markdown2html.py README.md README.html
khalfan@vagrant:~/$ cat README.html
<h1>My title</h1>
<h2>My title2</h2>
<h1>My title3</h1>
<h4>My title4</h4>
<h3>My title5</h3>
khalfan@vagrant:~/$
Spacing and new lines between HTML tags don’t need to be exactly this one
- GitHub repository: alx-frontend-for-fun
- File:
markdown2html.py
Improve markdown2html.py
by parsing Unordered listing syntax for generating HTML:
Syntax
: (you can assume it will be strictly this syntax)
Markdown:
- Hello
- Bye
HTML generated:
<ul>
<li>Hello</li>
<li>Bye</li>
</ul>
khalfan@vagrant:~/$ cat README.md
# My title
- Hello
- Bye
khalfan@vagrant:~/$ ./markdown2html.py README.md README.html
khalfan@vagrant:~/$ cat README.html
<h1>My title</h1>
<ul>
<li>Hello</li>
<li>Bye</li>
</ul>
khalfan@vagrant:~/$
Spacing and new lines between HTML tags don’t need to be exactly this one
- GitHub repository:
alx-frontend-for-fun
- File:
markdown2html.py
Improve markdown2html.py
by parsing Ordered listing syntax for generating HTML:
Syntax
: (you can assume it will be strictly this syntax)
Markdown:
* Hello
* Bye
HTML generated:
<ol>
<li>Hello</li>
<li>Bye</li>
</ol>
khalfan@vagrant:~/$ cat README.md
# My title
* Hello
* Bye
khalfan@vagrant:~/$ ./markdown2html.py README.md README.html
khalfan@vagrant:~/$ cat README.html
<h1>My title</h1>
<ol>
<li>Hello</li>
<li>Bye</li>
</ol>
khalfan@vagrant:~/$
Spacing and new lines between HTML tags don’t need to be exactly this one
- GitHub repository: alx-frontend-for-fun
- File: markdown2html.py
Improve markdown2html.py
by parsing paragraph syntax for generating HTML:
Syntax: (you can assume it will be strictly this syntax)
Markdown:
Hello
I'm a text
with 2 lines
HTML generated:
<p>
Hello
</p>
<p>
I'm a text
<br />
with 2 lines
</p>
khalfan@vagrant:~/$ cat README.md
# My title
- Hello
- Bye
Hello
I'm a text
with 2 lines
khalfan@vagrant:~/$ ./markdown2html.py README.md README.html
khalfan@vagrant:~/$ cat README.html
<h1>My title</h1>
<ul>
<li>Hello</li>
<li>Bye</li>
</ul>
<p>
Hello
</p>
<p>
I'm a text
<br/>
with 2 lines
</p>
khalfan@vagrant:~/$
Spacing and new lines between HTML tags don’t need to be exactly this one
- GitHub repository: alx-frontend-for-fun
- File:
markdown2html.py
Improve markdown2html.py
by parsing bold syntax for generating HTML:
Syntax: (you can assume it will be strictly this syntax)
Markdown | HTML generated |
---|---|
Hello | Hello |
Hello | Hello |
khalfan@vagrant:~/$ cat README.md
# My title
- He**l**lo
- Bye
Hello
I'm **a** text
with __2 lines__
**Or in bold**
khalfan@vagrant:~/$ ./markdown2html.py README.md README.html
khalfan@vagrant:~/$ cat README.html
<h1>My title</h1>
<ul>
<li>He<b>l</b>lo</li>
<li>Bye</li>
</ul>
<p>
Hello
</p>
<p>
I'm <b>a</b> text
<br/>
with <em>2 lines</em>
</p>
<p>
<b>Or in bold</b>
</p>
khalfan@vagrant:~/$
Spacing and new lines between HTML tags don’t need to be exactly this one
- GitHub repository:
alx-frontend-for-fun
- File:
markdown2html.py
Improve markdown2html.py
by parsing bold syntax for generating HTML:
Syntax: (you can assume it will be strictly this syntax)
Markdown | HTML generated | description |
---|---|---|
[[Hello]] | 8b1a9953c4611296a827abf8c47804d7 | convert in MD5 (lowercase) the content |
((Hello Chicago)) | Hello hiago | remove all c (case insensitive) from the content |
khalfan@vagrant:~/$ cat README.md
# My title
- He**l**lo
- Bye
Hello
I'm **a** text
with __2 lines__
((I will live in Caracas))
But it's [[private]]
So cool!
khalfan@vagrant:~/$ ./markdown2html.py README.md README.html
khalfan@vagrant:~/$ cat README.html
<h1>My title</h1>
<ul>
<li>He<b>l</b>lo</li>
<li>Bye</li>
</ul>
<p>
Hello
</p>
<p>
I'm <b>a</b> text
<br/>
with <em>2 lines</em>
</p>
<p>
I will live in araas
</p>
<p>
But it's 2c17c6393771ee3048ae34d6b380c5ec
</p>
<p>
So cool!
</p>
khalfan@vagrant:~/$
Spacing and new lines between HTML tags don’t need to be exactly this one
- GitHub repository: alx-frontend-for-fun
- File: markdown2html.py