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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user