-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlead_md.py
More file actions
70 lines (62 loc) · 2.14 KB
/
lead_md.py
File metadata and controls
70 lines (62 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#Lead, a markdown renderer
#Copyright Pittab 2025
#Producesyntaxed by EyeScary-Development
#imports
import producesyntaxed
from typing import List, Any
#Kinda self explanatory, makes bullet list strings and rerenders them for things like bold tags and strikethroughs
def bulletlist(item):
splititem=item.split()
splititem.pop(0)
print("- ", end="")
render([str(' '.join(splititem))], rerender=True)
#Processes bold text
def bold(line):
line=line.split("*")
bolds = [line[i] for i in range(len(line)) if i % 2 != 0]
for item in line:
if item not in bolds:
render([item], rerender=True)
else:
producesyntaxed.producesyntaxed(item, 'aqua', True, False)
#Processes strikethroughs
def strikethrough(line):
line=line.split("~~")
tostrike = [line[i] for i in range(len(line)) if i % 2 != 0]
for item in line:
if item not in tostrike:
render([item], rerender=True)
else:
producesyntaxed.producesyntaxed(item, 'grey', True, False)
#Processes headings TODO: maybe H6 and H5?
def heading(line):
print()
line=line.split()
if line[0] == "#":
line.pop(0)
producesyntaxed.producesyntaxed(' '.join(line), 'blue2', False, True)
if line[0] == "##":
line.pop(0)
producesyntaxed.producesyntaxed(' '.join(line), 'blue', False, True)
if line[0] == "###":
line.pop(0)
producesyntaxed.producesyntaxed(' '.join(line), 'aqua', False, True)
if line[0] == "####":
line.pop(0)
print(' '.join(line))
#Run this command to render le text
def render(input_list: List[Any], rerender=False):
for item in input_list:
match item:
case x if x.startswith("#"):
heading(item.strip("\n"))
case x if x.startswith("* ") or x.startswith("- "):
bulletlist(item.strip("\n"))
case x if "**" in x:
bold(item.strip("\n"))
case x if "~~" in x:
strikethrough(item.strip("\n"))
case _:
print(item.strip("\n"), end='')
if rerender != True:
print()