Skip to content

Commit

Permalink
Format the code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonZhang2024 committed May 23, 2024
1 parent a033f55 commit b449740
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 45 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-lenth = 88
extend-ignore = E203

31 changes: 15 additions & 16 deletions src/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def convert_str(markdown: list, preview=False, file_path='./') -> str:
</script>
'''

html = '''\
html = (
'''\
<html>
<title>
Preview
Expand All @@ -78,16 +79,17 @@ def convert_str(markdown: list, preview=False, file_path='./') -> str:
font-family: 'Sans Mono';
}
</style>
'''\
+ script\
'''
+ script
+ '''\
<body onload = "JavaScript:AutoRefresh(5000);">
'''\
+ html\
'''
+ html
+ '''\
</body>
</html>
'''
)

# Convert quoted code
html = convert_code(html)
Expand All @@ -102,21 +104,21 @@ def convert_gfm(line: str) -> str:
'[!TIP]': 'TIP',
'[!IMPORTANT]': 'IMPORTANT',
'[!WARNING]': 'WARNING',
'[!CAUTION]': 'CAUTION'
'[!CAUTION]': 'CAUTION',
}

for origin, html in gfm_alerts.items():
line = line.replace(origin, html)

line = line.replace('[ ]', '<input type="checkbox">')\
.replace('[x]', '<input type="checkbox" checked>')
line = line.replace('[ ]', '<input type="checkbox">').replace(
'[x]', '<input type="checkbox" checked>'
)

return line


def replace_script_tag(line: str) -> str:
line = line.replace('<script>', '')\
.replace('</script>', '')
line = line.replace('<script>', '').replace('</script>', '')

return line

Expand Down Expand Up @@ -215,12 +217,9 @@ def convert_single_line(line: str) -> str:
else:
description = ''

src = img.replace(description, '')\
.replace('(', '')\
.replace(')', '')

description = description.replace('![', '')\
.replace(']', '')
src = img.replace(description, '').replace('(', '').replace(')', '')

description = description.replace('![', '').replace(']', '')
image = f'<img src={src} alt={description}/>'
line = line.replace(img, image)
need_br_tag = False
Expand Down
26 changes: 11 additions & 15 deletions src/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@
"""

# Availible filetypes for the file selection window
filetypes = [
('Markdown', '*.md'),
("All Files", "*.*")
]
filetypes = [('Markdown', '*.md'), ("All Files", "*.*")]


def show_project_info():
get_help.show_project_info()


def load_preview():
# Load the preview
markdown_text_for_preview = text.get('1.0', 'end') # Get the text
Expand All @@ -56,8 +54,9 @@ def load_preview():
preview_file = f'{home}/.tkmarker/{file_uuid}'

# Convert the Markdown document to HTML and write to the preview file
html = convert(markdown_text_for_preview, preview=True,
file_path=os.path.split(filename))
html = convert(
markdown_text_for_preview, preview=True, file_path=os.path.split(filename)
)
with open(preview_file, 'w+', encoding='utf-8') as p:
p.write(html)

Expand All @@ -69,8 +68,9 @@ def refresh_preview(arg):
# Refresh the preview
markdown_text_for_preview = text.get('1.0', 'end')
preview_file = f'{home}/.tkmarker/{file_uuid}'
html = convert(markdown_text_for_preview, preview=True,
file_path=os.path.split(filename))
html = convert(
markdown_text_for_preview, preview=True, file_path=os.path.split(filename)
)

with open(preview_file, 'w', encoding='utf-8') as p:
p.write(html)
Expand Down Expand Up @@ -108,10 +108,7 @@ def cut():
def open_file():
# Open a file
global filename
filename = filedialog.askopenfilename(
initialdir='~/Documents',
filetypes=filetypes
)
filename = filedialog.askopenfilename(initialdir='~/Documents', filetypes=filetypes)

with open(filename, encoding='utf-8') as f:
t = f.read()
Expand All @@ -127,8 +124,7 @@ def save():
global filename
if filename == 'New File':
filename = filedialog.asksaveasfilename(
initialdir='~/Documents',
filetypes=filetypes
initialdir='~/Documents', filetypes=filetypes
)

# Set the filename as the title of the window
Expand All @@ -149,7 +145,7 @@ def new_file():
editor.wm_title('tkMarker')

# Set full screen
#editor.geometry('1000x1000')
# editor.geometry('1000x1000')
menubar = ttk.Menu(editor)

# Add the 'File' menubar
Expand Down
18 changes: 4 additions & 14 deletions src/get_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,17 @@ def show_project_info():
description.pack()

github_repos = ttk.Button(
info_page,
text='GitHub',
command=open_github_repos,
bootstyle=PRIMARY
info_page, text='GitHub', command=open_github_repos, bootstyle=PRIMARY
)
github_repos.pack()

website = ttk.Button(
info_page,
text='Website',
command=open_website,
bootstyle=(INFO, OUTLINE)
info_page, text='Website', command=open_website, bootstyle=(INFO, OUTLINE)
)
website.pack()

issue_tracker = ttk.Button(
info_page,
text='Report an issue',
command=open_issue_url,
bootstyle=SECONDARY
info_page, text='Report an issue', command=open_issue_url, bootstyle=SECONDARY
)
issue_tracker.pack()

Expand Down Expand Up @@ -104,4 +95,3 @@ def open_issue_url():

def open_website():
webbrowser.open(WEBSITE_URL)

0 comments on commit b449740

Please sign in to comment.