4 Commits

Author SHA1 Message Date
d66a471c76 Changelog for v2.0.5
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2025-09-18 16:45:36 -05:00
bbab9de1f6 regenerate requirements-dev.txt to get some safety stuff to shut up
weirdly, if I rebuild the whole requirements-dev.txt, test coverage
drops, so I'm sure that's a problem to worry about later

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2025-09-18 16:45:01 -05:00
d4f27c9ad8 add python3.13 to tox environments
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2025-09-18 16:36:14 -05:00
424ec3621d replace links that have .md suffixes with clean links
to aid viewing the raw markdown source in e.g. a gitlab source browser,
or to aid navigation in vim with "gf" style commands to jump between
files, allow the markdown source to specify foo.md or whatever/index.md
explicitly, yet generate the clean URLs for linking in the HTML output

this assumes that nginx is serving "foo" with foo.html, and "bar/" with
bar/index.html

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2025-09-18 14:19:48 -05:00
7 changed files with 65 additions and 8 deletions

View File

@@ -2,6 +2,19 @@
Included is a summary of changes to the project, by version. Details can be found in the commit history.
## v2.0.5
### Features
* The Markdown parser replaces links to e.g. `[Page](page.md)` with a href of `page`, rather than the Markdown source
specifying a link of `page` explicitly. This allows for some improved site navigation when browsing the Markdown
files, e.g. when going to files in Vim, or browsing a site in a Git web UI.
### Miscellaneous
* `tox.ini` also runs tests in a Python 3.13 environment now.
* Some trivial bumps to CI requirements.
## v2.0.4
### Bugfixes

View File

@@ -58,7 +58,18 @@ def parse_md(path: str, pages_root: str):
with open(absolute_path, 'r') as input_file:
mtime = datetime.datetime.fromtimestamp(os.path.getmtime(input_file.name), tz=datetime.timezone.utc)
entry = input_file.read()
logger.debug("path '%s' read", absolute_path)
# remove .md extensions used for navigating in vim and replace them with
# the pattern we use for HTML output here
# foo/index.md -> foo/, foo/index.md#anchor -> foo/#anchor
# ../index.md -> ../, ../index.md#anchor -> ../#anchor
entry = re.sub(r'\[([^]]+)\]\(([^)]+)index.md(#[^)]*)?\)', r'[\1](\2\3)', entry)
# index.md -> ., index.md#anchor -> .#anchor
entry = re.sub(r'\[([^]]+)\]\(index.md(#[^)]*)?\)', r'[\1](.\2)', entry)
# bar.md -> bar, foo/bar.md -> foo/bar, bar.md#anchor -> bar#anchor
entry = re.sub(r'\[([^]]+)\]\(([^)]+).md(#[^)]*)?\)', r'[\1](\2\3)', entry)
md = init_md()
content = Markup(md.convert(entry)) # nosec B704
except (OSError, FileNotFoundError):

View File

@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# This file is autogenerated by pip-compile with Python 3.13
# by the following command:
#
# pip-compile --extra=dev --output-file=requirements/requirements-dev.txt
@@ -22,7 +22,7 @@ build==1.2.2.post1
# via pip-tools
cachetools==5.5.2
# via tox
certifi==2025.1.31
certifi==2025.8.3
# via requests
cffi==1.17.1
# via cryptography
@@ -217,9 +217,9 @@ pyyaml==6.0.2
# via bandit
readme-renderer==44.0
# via twine
regex==2024.11.6
regex==2025.9.1
# via nltk
requests==2.32.3
requests==2.32.5
# via
# id
# requests-toolbelt
@@ -240,8 +240,6 @@ ruamel-yaml==0.18.10
# via
# safety
# safety-schemas
ruamel-yaml-clib==0.2.12
# via ruamel-yaml
safety==3.3.1
# via incorporeal-cms (pyproject.toml)
safety-schemas==0.0.11
@@ -278,7 +276,7 @@ typing-extensions==4.12.2
# safety
# safety-schemas
# typer
urllib3==2.3.0
urllib3==2.5.0
# via
# requests
# twine

View File

@@ -0,0 +1,6 @@
[Cool](cool/index.md)
[Anchored Cool](cool/index.md#anchor)
[This Index](index.md)
[Anchored This Index](index.md#anchor)
[Parent](../index.md)
[Anchored Parent](../index.md#anchor)

View File

@@ -0,0 +1,4 @@
[Foo](foo.md)
[Anchored Foo](foo.md#anchor)
[Sub Foo](sub/foo.md)
[Anchored Sub Foo](sub/foo.md#anchor)

View File

@@ -163,3 +163,23 @@ def test_parse_md_bad_file():
"""Test the direct results of parsing a markdown file."""
with pytest.raises(ValueError):
content, md, page_name, page_title, mtime = parse_md(os.path.join(PAGES_DIR, 'actually-a-png.md'), PAGES_DIR)
def test_md_extension_in_source_link_is_stripped():
"""Test that if a foo.md file link is specified in the Markdown, it is foo in the HTML."""
content, _, _, _, _ = parse_md(os.path.join(PAGES_DIR, 'file-with-md-link.md'), PAGES_DIR)
assert '<a href="foo">Foo</a>' in content
assert '<a href="foo#anchor">Anchored Foo</a>' in content
assert '<a href="sub/foo">Sub Foo</a>' in content
assert '<a href="sub/foo#anchor">Anchored Sub Foo</a>' in content
def test_index_in_source_link_is_stripped():
"""Test that if a index.md file link is specified in the Markdown, it is just the dir in the HTML."""
content, _, _, _, _ = parse_md(os.path.join(PAGES_DIR, 'file-with-index.md-link.md'), PAGES_DIR)
assert '<a href="cool/">Cool</a>' in content
assert '<a href="cool/#anchor">Anchored Cool</a>' in content
assert '<a href=".">This Index</a>' in content
assert '<a href=".#anchor">Anchored This Index</a>' in content
assert '<a href="../">Parent</a>' in content
assert '<a href="../#anchor">Anchored Parent</a>' in content

View File

@@ -5,7 +5,7 @@
[tox]
isolated_build = true
envlist = begin,py39,py310,py311,py312,coverage,security,lint,reuse
envlist = begin,py39,py310,py311,py312,py313,coverage,security,lint,reuse
[testenv]
allow_externals = pytest, coverage
@@ -41,6 +41,11 @@ commands =
commands =
pytest --cov-append --cov={envsitepackagesdir}/incorporealcms/ --cov-branch
[testenv:py313]
# run pytest with coverage
commands =
pytest --cov-append --cov={envsitepackagesdir}/incorporealcms/ --cov-branch
[testenv:coverage]
# report on coverage runs from above
skip_install = true