From 14d64ea27246095e62ef6b88e33415e782848c1e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 6 Dec 2022 14:33:17 +0000 Subject: [PATCH 1/4] Include bookmarks within html titles --- markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown.py b/markdown.py index b43e53ce2..e7a976084 100644 --- a/markdown.py +++ b/markdown.py @@ -386,7 +386,7 @@ def markdown_to_html(markdown: str) -> str: for hsh, hashes in titles.items(): if line.startswith(hashes): line = line.replace(hashes, '').strip() - line = '<' + hsh + '>' + line + '\n' + line = '<' + hsh + ' id="' + line + '">' + line + '\n' ctr = -1 break html_str += line From 3d7418a4b6567fabce1b2cf54ea07abec26e5003 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 6 Dec 2022 14:37:18 +0000 Subject: [PATCH 2/4] Bookmark formatting --- markdown.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/markdown.py b/markdown.py index e7a976084..9f9e1c787 100644 --- a/markdown.py +++ b/markdown.py @@ -385,8 +385,10 @@ def markdown_to_html(markdown: str) -> str: for hsh, hashes in titles.items(): if line.startswith(hashes): + bookmark_str = line.lower().replace(' ', '-') line = line.replace(hashes, '').strip() - line = '<' + hsh + ' id="' + line + '">' + line + '\n' + line = '<' + hsh + ' id="' + bookmark_str + '">' + \ + line + '\n' ctr = -1 break html_str += line From 98366a17de8fe1acb7a6a0034f2ee9d9475d1dc0 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 6 Dec 2022 14:43:03 +0000 Subject: [PATCH 3/4] html bookmark --- markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown.py b/markdown.py index 9f9e1c787..355e79025 100644 --- a/markdown.py +++ b/markdown.py @@ -385,7 +385,7 @@ def markdown_to_html(markdown: str) -> str: for hsh, hashes in titles.items(): if line.startswith(hashes): - bookmark_str = line.lower().replace(' ', '-') + bookmark_str = line.split(' ', 1)[1].lower().replace(' ', '-') line = line.replace(hashes, '').strip() line = '<' + hsh + ' id="' + bookmark_str + '">' + \ line + '\n' From 0d9c5d888bfe3b19c8812f96805b459b0e4b0108 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 6 Dec 2022 14:48:57 +0000 Subject: [PATCH 4/4] Bookmark links --- markdown.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/markdown.py b/markdown.py index 355e79025..b83074705 100644 --- a/markdown.py +++ b/markdown.py @@ -198,10 +198,16 @@ def _markdown_replace_links(markdown: str) -> str: section_text = \ section_text.replace('!' + replace_str, html_link) if replace_str in section_text: - html_link = \ - '' + \ - link_text + '' + if not link_url.startswith('#'): + # external link + html_link = \ + '' + \ + link_text + '' + else: + # bookmark + html_link = \ + '' + link_text + '' section_text = \ section_text.replace(replace_str, html_link) ctr += 1