A MD file is a text file created using one of several possible dialects of the Markdown language. It is saved in plain text format but includes inline symbols that define how to format the text (e.g. bold, indentations, headers, table formatting). MD files are designed for authoring plain text documentation that can be easily converted to HTML. From: .MD File Extension
Create a Python program that will parse an MD file and create an equivalent HTML file. Do not use any existing modules or programs. Parse the text yourself.
Convert only a subset of the markdowns. (They are described below.)
The output HTML file should have the same name as the input MD file but with the file type '.html'.
Use the following template for your HTML output
Use These MarkDown Tags | |
---|---|
MarkDown | HTML |
# | <h1> ... </h1> |
## | <h2> ... </h2> |
**bold** | <b> ... </b> |
//italic// | <i> ... </i> |
__underlined__ | <u> ... </u> |
Of course you can **__//combine//__** all these. | |
The HTML paragraph tags are <p> ... </p> | |
The HTML line break tag is <br> |
Paragraphs are separated by blank lines. If you want to force a newline within a paragraph, you can use two backslashes followed by a whitespace or the end-of-line. MarkDown tags do not cross paragraph boundaries. All MarkDown tags must be completed within a single paragraph. If not, it is an error.
Parsing a MD file is complicated. To simplify the parser for this problem, MarkDown tags must be completed within a single line.
Add more markdowns to your program (2 or 3). You don't need to do them all.
Create your own .MD file and convert it. (Copy-and-past if you find some text you like.)
Create a graphics program that has a text area where the user can write their own MD text. Have a button that will generate a HTML file from the user's input. You will also need a way to display error messages.
You can see my approach to the problem using a LIFO queue (link above). Can you do it by using recursion?
Markdown Home
Markdown Guide - Getting Started
Markdown Guide - Basic Syntax
tutorial.md
DukoWiki (home)
How would you go about parsing Markdown?
Creating Your Own Markdown Parser
A markdown parser with high extensibility
Create markdown_parser
Parsing Markdown into an Automated Table of Contents
You can test regular expression at regx101.com
Markup spec/BNF
js-play/grammar.md at master - Markdown
Markdown Syntax Reference
Because this is a demo and the input file is small you could use the Python read method to read the whole file with one read. The read() method can return a specified number of bytes from a file. The default is -1 and means "read the whole file". You could also read a line at a time.