Skip to content

Commit cc0a9b3

Browse files
committed
fixed issue with buttons/links after changing from .txt to .sswg.
1 parent b9eda58 commit cc0a9b3

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ ENV/
100100
# mypy
101101
.mypy_cache/
102102

103-
.pypirc
103+
.pypirc
104+
uv.lock

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
[build-system]
2-
requires = ["setuptools"]
3-
build-backend = "setuptools.build_meta"
4-
51
[project]
62
name = "sswg"
7-
version = "3.0.0"
3+
trsion = "3.0.0"
84
description = "A Simple Static Website Generator that converts a markdown inspired markup language into web pages."
95
authors = [
106
{name = "Petter Amland", email = "pokepetter@gmail.com"}
@@ -13,6 +9,10 @@ license = {text = "MIT"}
139
keywords = ["website", "generator"]
1410
readme = "README.md"
1511
requires-python = ">=3.6"
12+
dependencies = []
1613

1714
[project.urls]
18-
Homepage = "https://github.com/pokepetter/sswg"
15+
Homepage = "https://github.com/pokepetter/sswg"
16+
17+
[tool.setuptools]
18+
py-modules = ["sswg"]

sswg.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
from pathlib import Path
55
from textwrap import dedent
6+
import shutil
67

78

89
def get_html_tags(string, start_tag='>', end_tag='>'):
@@ -53,7 +54,13 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
5354

5455
# find files to parse
5556
files = []
56-
for suffix in file_types.split(','):
57+
if ',' in file_types:
58+
file_types = file_types.split(',')
59+
else:
60+
file_types = (file_types, )
61+
# print('file_types:', file_types)
62+
63+
for suffix in file_types:
5764
files.extend(list(path.glob('*' + suffix)))
5865

5966
files_to_ignore = []
@@ -72,7 +79,7 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
7279
output_folder_path.mkdir()
7380

7481
# create css file
75-
with open('sswg.css', 'w', encoding='utf-8') as css_file:
82+
with (output_folder_path/'sswg.css').open('w', encoding='utf-8') as css_file:
7683
css_file.write(dedent('''
7784
html {max-width: 100%; margin: auto; color: #333333;}
7885
h2 {font-size: 50px; margin-block-end:0px; margin-block-start:0px;}
@@ -160,7 +167,7 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
160167
current_font_style = 'normal'
161168
is_code_block = False
162169
is_in_style_tag = False
163-
inline_images = list()
170+
inline_images = []
164171
code_block_id = 0
165172

166173
lines = text.split('\n')
@@ -186,7 +193,10 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
186193
with open(target_document, 'r', encoding='utf-8') as file:
187194
headlines = [l.split('## ')[1].strip() for l in file.readlines() if l.strip().startswith('## ')] # get name after ##
188195
for e in headlines:
189-
link = target_document.replace('.txt', '.html') + f'#{e}'
196+
link = target_document
197+
for suffix in file_types:
198+
link = link.replace(suffix, '.html')
199+
link = f'{link}#{e}'
190200
new_lines.append(current_indent + f'• <a href="{link}">{e}</a>')
191201

192202
elif l.startswith('```'):
@@ -410,3 +420,11 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
410420
with open(output_folder_path / f'{target_file.stem}.html', 'w', encoding='utf-8') as text_file:
411421
text_file.write(new_text)
412422
print('finished building:', target_file.stem + '.html')
423+
424+
425+
# # if using output_folder, copy images over
426+
# if output_folder_path != '.':
427+
# for img_name in inline_images:
428+
# print('--------- copy over image:', img_name)
429+
# # copy file to folder
430+
# shutil.copy(path/img_name, output_folder_path/img_name)

0 commit comments

Comments
 (0)