Skip to content

Commit a2c2afb

Browse files
authored
Merge branch 'code-differently:main' into feat/lesson_05/quiz
2 parents 46dedc5 + 7587e61 commit a2c2afb

File tree

221 files changed

+30683
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+30683
-322
lines changed

lesson_01/tyranricejr/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# 📝 Markdown To HTML Script
2+
3+
This program turns any Markdown file into a complete HTML document.
4+
5+
#### _Created By: Tyran Rice Jr._
6+
7+
## 📖 How It Works
8+
9+
### 1. Start with a Markdown file
10+
Markdown is plain text with some symbols for formatting
11+
12+
### 2. Read the file
13+
The script uses Pythons `open()` in-built function to read the Markdown file:
14+
```py
15+
with open(markdown_path, "r", encoding="utf-8") as md_file:
16+
```
17+
### 3. Update References
18+
When reading the markdown file, the source functions for images are not pathed properly,
19+
so we must update them:
20+
21+
### 4. Convert Markdown → HTML
22+
We then use the [`markdown`](https://pypi.org/project/Markdown/) library to turn Markdown into HTML:
23+
```py
24+
html_content = markdown.markdown(markdown_content)
25+
```
26+
27+
### 5. Wrap HTML document in a complete page
28+
We wrap the entire converted markdown file in HTML tags listed below:
29+
- `<!DOCTYPE html>` and `<html>` / `<head>` tags
30+
- A `<link>` to **GitHub's** CSS Markdown Stylesheet
31+
- Small custom CSS for width, margin and padding
32+
33+
### 6. Write to `convertedmarkdown.html`
34+
We save the wrapped HTML page:
35+
```py
36+
with open("./convertedmarkdown.html", "w") as f:
37+
```
38+
We can then see the HTML file in the same folder as `markdownparser.py`.
39+
40+
## 🚀 How to Use
41+
42+
### 1. Install `markdown`:
43+
```bash
44+
pip install Markdown
45+
```
46+
### 2. Navigate To Folder
47+
Starting from the root directory, navigate to
48+
`lesson_01/tyranricejr`. This is where the script is located in.
49+
50+
### 3. Run the script:
51+
```bash
52+
python markdownparser.py
53+
```
54+
55+
### 4. Input your `markdown` file path:
56+
The script will ask you to input your `markdown` file path. This path should be the direct path starting either from the `root` directory or from `lesson_01/tyranricejr` directory.
57+
58+
### 5. Success!
59+
After putting your correct file path, the script
60+
will give you the `HTML` converted version in the output file!
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import markdown
2+
3+
'''
4+
5+
Title: Markdown Parser
6+
7+
Description: This program turns your Markdown files into HTML files
8+
9+
Created By: Tyran Rice Jr.
10+
11+
'''
12+
13+
'''
14+
15+
Function Title: read_markdown_file
16+
17+
Description:
18+
This function reads the user's markdown file from the
19+
given path input.
20+
21+
Arguments:
22+
- markdown_path: The path to the Markdown file given by the user
23+
24+
Returns:
25+
- markdown_content: The Markdown file that was read from the given path
26+
27+
'''
28+
29+
30+
def read_markdown_file(markdown_path):
31+
with open(markdown_path, "r", encoding="utf-8") as md_file:
32+
markdown_content = md_file.readlines()
33+
34+
return markdown_content
35+
36+
37+
'''
38+
39+
Function Title: write_html_file
40+
41+
Description:
42+
This function takes the user's updated markdown file and converts it
43+
into a HTML file under the name 'convertedmarkdown.html'.
44+
45+
Arguments:
46+
- markdown_content: The updated Markdown file
47+
48+
Returns:
49+
- void: Simply writes a new HTML file
50+
51+
'''
52+
53+
54+
def write_html_file(markdown_content):
55+
# Convert Markdown file to HTML
56+
html_content = markdown.markdown(markdown_content)
57+
58+
with open("./output/convertedmarkdown.html", "w") as f:
59+
f.write("<!DOCTYPE html>\n")
60+
f.write("<html lang='en'>\n")
61+
f.write("""<head>
62+
<meta charset = "UTF-8" >
63+
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown-light.min.css" >
64+
<style >
65+
body {
66+
max-width: 800px;
67+
margin: auto;
68+
padding: 2rem;
69+
}
70+
</style >
71+
</head >
72+
<body class = "markdown-body" >""")
73+
f.write(html_content + "\n")
74+
f.write("</html>")
75+
76+
77+
'''
78+
79+
Function Title: change_url_path
80+
81+
Description:
82+
This function changes the URL path for src references to
83+
make sure they are correctly pathed to the right directory.
84+
This is done by taking the input of the user's path to their
85+
existing mark down file and adding it to the src path.
86+
87+
Arguments:
88+
- markdown_content: The Markdown file given by the user
89+
- markdown_path: The path to the Markdown file given by the user
90+
91+
Returns:
92+
- markdown_content: The new Markdown file with updated src paths
93+
94+
'''
95+
96+
97+
def change_url_path(markdown_content, markdown_path):
98+
# Removes 'README.md' from path to ensure the path is correctly referenced in src
99+
markdown_path = markdown_path.removesuffix("README.md")
100+
for i in range(len(markdown_content)):
101+
# If "src=" is located in a line, it will be correctly referenced
102+
if (markdown_content[i].find("src=") != -1):
103+
index = markdown_content[i].find("src=")
104+
# Change src to have the correct path location
105+
markdown_content[i] = markdown_content[i][:index + 4] + \
106+
"\"" + markdown_path + markdown_content[i][index + 5:]
107+
108+
return markdown_content
109+
110+
111+
def main():
112+
try:
113+
print("Welcome to Tyran's Markdown-To-HTML Converter")
114+
markdown_path = input("Please enter the path of the mark down file: ")
115+
116+
# Read the Markdown file and convert it into a list of strings
117+
markdown_content = read_markdown_file(markdown_path)
118+
119+
# Update references inside Markdown file
120+
markdown_content = change_url_path(markdown_content, markdown_path)
121+
122+
# Join the list of strings from the Markdown file into one entire string
123+
markdown_content = ''.join(markdown_content)
124+
125+
# Turn the Markdown file into a HTML file
126+
write_html_file(markdown_content)
127+
128+
print("Converted Markdown To HTML content")
129+
130+
except FileNotFoundError:
131+
print("Error: The specified Markdown file was not found.")
132+
except Exception as e:
133+
print(f"An error occurred!\nError: {e}")
134+
135+
136+
if __name__ == "__main__":
137+
main()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html>
2+
<html lang='en'>
3+
<head>
4+
<meta charset = "UTF-8" >
5+
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown-light.min.css" >
6+
<style >
7+
body {
8+
max-width: 800px;
9+
margin: auto;
10+
padding: 2rem;
11+
}
12+
</style >
13+
</head >
14+
<body class = "markdown-body" ><h1>📝 Markdown To HTML Script</h1>
15+
<p>This program turns any Markdown file into a complete HTML document.</p>
16+
<h4><em>Created By: Tyran Rice Jr.</em></h4>
17+
<h2>📖 How It Works</h2>
18+
<h3>1. Start with a Markdown file</h3>
19+
<p>Markdown is plain text with some symbols for formatting</p>
20+
<h3>2. Read the file</h3>
21+
<p>The script uses Pythons <code>open()</code> in-built function to read the Markdown file:
22+
<code>py
23+
with open(markdown_path, "r", encoding="utf-8") as md_file:</code></p>
24+
<h3>3. Update References</h3>
25+
<p>When reading the markdown file, the source functions for images are not pathed properly,
26+
so we must update them:</p>
27+
<h3>4. Convert Markdown → HTML</h3>
28+
<p>We then use the <a href="https://pypi.org/project/Markdown/"><code>markdown</code></a> library to turn Markdown into HTML:
29+
<code>py
30+
html_content = markdown.markdown(markdown_content)</code></p>
31+
<h3>5. Wrap HTML document in a complete page</h3>
32+
<p>We wrap the entire converted markdown file in HTML tags listed below:
33+
- <code>&lt;!DOCTYPE html&gt;</code> and <code>&lt;html&gt;</code> / <code>&lt;head&gt;</code> tags
34+
- A <code>&lt;link&gt;</code> to <strong>GitHub's</strong> CSS Markdown Stylesheet
35+
- Small custom CSS for width, margin and padding</p>
36+
<h3>6. Write to <code>convertedmarkdown.html</code></h3>
37+
<p>We save the wrapped HTML page:
38+
<code>py
39+
with open("./convertedmarkdown.html", "w") as f:</code>
40+
We can then see the HTML file in the same folder as <code>markdownparser.py</code>.</p>
41+
<h2>🚀 How to Use</h2>
42+
<h3>1. Install <code>markdown</code>:</h3>
43+
<p><code>bash
44+
pip install Markdown</code></p>
45+
<h3>2. Navigate To Folder</h3>
46+
<p>Starting from the root directory, navigate to
47+
<code>lesson_01/tyranricejr</code>. This is where the script is located in.</p>
48+
<h3>3. Run the script:</h3>
49+
<p><code>bash
50+
python markdownparser.py</code></p>
51+
<h3>4. Input your <code>markdown</code> file path:</h3>
52+
<p>The script will ask you to input your <code>markdown</code> file path. This path should be the direct path starting either from the <code>root</code> directory or from <code>lesson_01/tyranricejr</code> directory.</p>
53+
<h3>5. Success!</h3>
54+
<p>After putting your correct file path, the script
55+
will give you the <code>HTML</code> converted version in the output file!</p>
56+
</html>

lesson_02/quiz_java/app/build.gradle.kts

Lines changed: 0 additions & 41 deletions
This file was deleted.

lesson_02/quiz_java/app/src/main/java/quiz_java/App.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)