AppleCrumble 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.5
2
+ Name: AppleCrumble
3
+ Version: 0.1.0
4
+ Summary: AppleCrumble is a simple SSG that converts your markdown into HTML for the browser.
5
+ Requires-Python: >=3.9
6
+ Requires-Dist: click>=8.5.1
7
+ Requires-Dist: pyyaml>=6.0.3
8
+ Description-Content-Type: text/markdown
9
+
10
+ # AppleCrumble
11
+
12
+ AppleCrumble is a stupid-simple SSG (static-site generator) that takes your markdown (.md) files and turns them into HTML files able to be read by the browser.
@@ -0,0 +1,3 @@
1
+ # AppleCrumble
2
+
3
+ AppleCrumble is a stupid-simple SSG (static-site generator) that takes your markdown (.md) files and turns them into HTML files able to be read by the browser.
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "AppleCrumble"
7
+ version = "0.1.0"
8
+ description = "AppleCrumble is a simple SSG that converts your markdown into HTML for the browser."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ 'click>=8.5.1',
13
+ 'PyYAML>=6.0.3',
14
+ ]
15
+
16
+ [project.scripts]
17
+ AppleCrumble-init = "AppleCrumble.main:init"
18
+ AppleCrumble-build = "AppleCrumble.main:build"
19
+ AppleCrumble-create_new_page = "AppleCrumble.main:make_page"
File without changes
@@ -0,0 +1,153 @@
1
+ import click
2
+ import yaml
3
+ import os
4
+
5
+ def init():
6
+ os.mkdir("_content")
7
+ os.makedirs("_site/static")
8
+ create_new_page("index")
9
+ open("_site/static/styles.css", "w")
10
+
11
+ def create_new_page(page_name:str):
12
+ if not (os.path.exists(f"_content/{page_name}")):
13
+ os.mkdir(f"_content/{page_name}")
14
+
15
+ with open(f"_content/{page_name}/{page_name}.md", "w") as md_file:
16
+ md_file.write("# ***This is my new page!***")
17
+
18
+ with open(f"_content/{page_name}/{page_name}.yaml", "w") as yaml_file:
19
+ yaml_file.write("title: \"My New Page!\" \n")
20
+ yaml_file.write("style: \"styles.css\" \n")
21
+
22
+
23
+ @click.command()
24
+ @click.option('--p', default=None, help='The name of the page that you want to make.')
25
+ def make_page(p : str):
26
+ if p == None:
27
+ click.echo("Page name not specified, please specify the name of the page that you want to make.")
28
+ return
29
+ else:
30
+ create_new_page(p)
31
+
32
+ @click.command()
33
+ @click.option('--m', default=None, help='The markdown file that you want to compile into HTML.')
34
+ def build(m : str):
35
+ if m == None:
36
+ click.echo("No folder specified, please specify a folder.")
37
+ return
38
+
39
+ with open(f"_content/{m}/{m}.yaml") as yaml_file:
40
+ readable_yaml = yaml.load(yaml_file, yaml.FullLoader)
41
+ style = readable_yaml['style']
42
+ title = readable_yaml['title']
43
+
44
+ open(f"_site/static/{style}", "w")
45
+
46
+ with open(f"_content/{m}/{m}.md") as md_file:
47
+ if not (os.path.exists(f"_site/{m}")):
48
+ os.mkdir(f"_site/{m}")
49
+
50
+ with open(f"_site/{m}/{m}.html", "w") as html_file:
51
+ html_file.write("<!DOCTYPE html>\n")
52
+ html_file.write("<html>\n")
53
+
54
+ html_file.write("\n<head>\n")
55
+ html_file.write("\n<meta charset=\"UTF-8\">\n")
56
+ html_file.write("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n")
57
+ html_file.write(f"<title> {title} </title>\n")
58
+ html_file.write(f"<link href=\"/_site/static/{style}\" rel=\"stylesheet\" type=\"text/css\" media=\"all\">\n")
59
+ html_file.write("\n</head>\n")
60
+
61
+ html_file.write("\n<body>\n")
62
+
63
+ for line in md_file:
64
+ if line.startswith("<") or line.strip("\n").endswith(">"):
65
+ html_file.write(line) # Skips the whole shebang if the line is already in html
66
+ else:
67
+ tag = parse_tag(line)
68
+ contents = parse_contents(line, tag)
69
+ html_contents = convert_contents_to_html(contents)
70
+ converted_line = convert_lines_to_html(html_contents, tag)
71
+ html_file.write(f"{converted_line} \n")
72
+
73
+ html_file.write("\n")
74
+ html_file.write("</body>\n")
75
+ html_file.write("\n")
76
+ html_file.write("</html>")
77
+
78
+ # Adding the functions from parser and converter here because i can't figure out how to add them as a dependency
79
+
80
+ def parse_tag(line : str):
81
+ if line == "\n":
82
+ return "br"
83
+ elif line.startswith("#"):
84
+ number_of_hashes = 0
85
+ increment = 0
86
+
87
+ while True:
88
+ if line[increment] == "#":
89
+ number_of_hashes += 1
90
+ increment += 1
91
+ else:
92
+ if number_of_hashes > 6: # Limits heading to H6 since thats the smallest a heading can go
93
+ number_of_hashes = 6
94
+ break
95
+
96
+ return ("h" + str(number_of_hashes))
97
+ else:
98
+ return "p"
99
+
100
+ def parse_contents(line : str, tag : str):
101
+ tags = { # There's most definitely a better way to do this but im lazy.
102
+ 'h1' : '# ', # The extra space is intentional so that the contents don't all begin with a space
103
+ 'h2' : '## ',
104
+ 'h3' : '### ',
105
+ 'h4' : '#### ',
106
+ 'h5' : '##### ',
107
+ 'h6' : '###### ',
108
+ 'p' : '' # The paragraph doesn't have a space because it doesn't have a prefix
109
+ }
110
+
111
+ if tag == 'br':
112
+ return '\n'
113
+ else:
114
+ return line.strip(tags[tag]).strip("\n")
115
+
116
+ ### Converts .md lines into html
117
+ def convert_lines_to_html(contents : str, tag : str):
118
+ if tag == "br":
119
+ return (f"<{tag}>")
120
+ else:
121
+ return (f"<{tag}> {contents} </{tag}>")
122
+
123
+ def convert_contents_to_html(contents : str):
124
+ words = contents.split()
125
+
126
+ for i in range(len(words)): # This is so fucked dude
127
+ words[i] = get_bold_and_italic(words[i])
128
+ words[i] = get_code_block(words[i])
129
+
130
+ contents = " ".join(words)
131
+ return contents
132
+
133
+ def find_and_replace(word:str, targets:list, html_replacement:str):
134
+ for target in targets:
135
+ if word.startswith(target):
136
+ word = f"<{html_replacement}>" + word.removeprefix(target)
137
+ elif word.endswith(target):
138
+ word = word.removesuffix(target) + f"</{html_replacement}>"
139
+ return word
140
+
141
+ def get_code_block(word : str):
142
+ return find_and_replace(word, ["`"], "code")
143
+
144
+ def get_bold_and_italic(word : str):
145
+ if word.startswith("***") or word.startswith("___"):
146
+ word = "<strong><em>" + word.removeprefix("***").removeprefix("___")
147
+ elif word.endswith("***") or word.endswith("___"):
148
+ word = word.removesuffix("***").removesuffix("___") + "</em></strong>"
149
+ else:
150
+ word = find_and_replace(word, ["**", "__"], "strong")
151
+ word = find_and_replace(word, ["*", "_"], "em")
152
+
153
+ return word