diff --git a/markdown_include/include.py b/markdown_include/include.py index 00f2131..f3b8a1c 100644 --- a/markdown_include/include.py +++ b/markdown_include/include.py @@ -148,7 +148,7 @@ def run(self, lines): ) wanted_lines.extend( - original_text[current_start - 1 : current_end] + original_text[current_start - 1: current_end] ) else: wanted_line = int(block.strip()) @@ -174,19 +174,18 @@ def run(self, lines): link = LINK_SYNTAX.search(text[i]) if link: raw_path = link.group(2) - if not raw_path.startswith( - "http" - ) and not raw_path.startswith("/"): + if not raw_path.startswith("http") and not raw_path.startswith( + "/") and not raw_path.startswith("#"): path_ = f"{os.path.dirname(relative_filename)}{os.path.sep}{raw_path}" text[i] = ( - text[i][: link.start(2)] - + path_ - + text[i][link.end(2) :] + text[i][: link.start(2)] + + path_ + + text[i][link.end(2):] ) text[i] = text[i].rstrip("\r\n") text_to_insert = "\r\n".join(text) - line = line[: m.start()] + text_to_insert.strip() + line[m.end() :] + line = line[: m.start()] + text_to_insert.strip() + line[m.end():] del lines[loc] lines[loc:loc] = line.splitlines() m = INC_SYNTAX.search(line) diff --git a/tests/resources/docs/template/template_frag_link.md b/tests/resources/docs/template/template_frag_link.md new file mode 100644 index 0000000..fba0929 --- /dev/null +++ b/tests/resources/docs/template/template_frag_link.md @@ -0,0 +1 @@ +[some link](#template) \ No newline at end of file diff --git a/tests/test_include.py b/tests/test_include.py index 0f740f3..a628b7e 100644 --- a/tests/test_include.py +++ b/tests/test_include.py @@ -48,6 +48,14 @@ def test_abs_url_link(markdown_include): assert html == "

some link

" + +def test_frag_url_link(markdown_include): + source = "{!docs/template/template_frag_link.md!}" + html = markdown.markdown(source, extensions=[markdown_include]) + + assert html == "

some link

" + + def test_relative_path_img_url_link(markdown_include): source = "{!with_img_link.md!}" html = markdown.markdown(source, extensions=[markdown_include])