Skip to content

Commit b67facf

Browse files
authored
Merge branch 'main' into feat/lesson-03/Creating-new-quiz-questions
2 parents 5114aae + 8618b2c commit b67facf

File tree

197 files changed

+31259
-6
lines changed

Some content is hidden

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

197 files changed

+31259
-6
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Check Lesson 05 Quiz Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_05/quiz/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Use Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20.x'
23+
24+
- name: Build Shared Lib with Node.js
25+
working-directory: ./lib/javascript/codedifferently-instructional
26+
run: npm ci
27+
28+
- name: Build Lesson 05 Quiz with Node.js
29+
working-directory: ./lesson_05/quiz
30+
run: |
31+
npm ci
32+
npm run check

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/.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

lesson_02/quiz_java/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
This file was generated by the Gradle 'init' task.
3+
*/
4+
5+
6+
plugins {
7+
java
8+
id("org.springframework.boot") version "3.1.0"
9+
id("io.spring.dependency-management") version "1.1.0"
10+
application
11+
}
12+
13+
14+
java {
15+
toolchain {
16+
languageVersion.set(JavaLanguageVersion.of(21))
17+
}
18+
}
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
implementation("org.apache.commons:commons-text:1.10.0")
26+
implementation(project(":codedifferently-instructional:instructional-lib")) // <-- the link to the specific module
27+
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
28+
implementation("org.springframework.boot:spring-boot-starter")
29+
testImplementation("org.springframework.boot:spring-boot-starter-test")
30+
31+
}
32+
33+
34+
35+
application {
36+
// Define the main class for the application.
37+
application { mainClass.set("quiz_java.App") }
38+
tasks.test { useJUnitPlatform() }
39+
40+
}
41+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
/*
3+
* This source file was generated by the Gradle 'init' task
4+
*/
5+
package quiz_java;
6+
7+
/**
8+
* Java port of the assignment app using codedifferently-instructional library
9+
*/
10+
public class App {
11+
public static void main(String[] args) {
12+
System.out.println("Starting Quiz Java Application...");
13+
14+
try {
15+
// Initialize and run the lesson
16+
Lesson2 lesson = new Lesson2();
17+
lesson.run();
18+
19+
} catch (Exception e) {
20+
System.err.println("Error running quiz: " + e.getMessage());
21+
e.printStackTrace();
22+
}
23+
}
24+
}
25+
26+

0 commit comments

Comments
 (0)