From e11085ca91d1d0f4506fc7dd95225f975acc892e Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Tue, 9 Jan 2024 12:45:49 +0100 Subject: [PATCH] Add section link snippet --- .vim/snips/pandoc.snippets | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.vim/snips/pandoc.snippets b/.vim/snips/pandoc.snippets index 6d3c119..f32d6ff 100644 --- a/.vim/snips/pandoc.snippets +++ b/.vim/snips/pandoc.snippets @@ -57,6 +57,9 @@ def code_inline(): def code(): return code_inline() or code_block() +def slugify(text): + return re.sub('\s+', '-', text.lower()) + def linkify(text, link): return f"[{text}]({link})" @@ -741,6 +744,12 @@ for i in range(int(match.group(1)), int(match.group(2)) + 1): ` endsnippet +snippet "sec([\sA-z]+)" "Link section titled ..." r +`!p +snip.rv = "* " + linkify(match.group(1), f"{snip.basename}_{slugify(match.group(1))}") +` +endsnippet + snippet cp(\d+) "Comment current page (and date)" r `!p snip.rv = ""` endsnippet