Add section link snippet

This commit is contained in:
2024-01-09 12:45:49 +01:00
parent 4e625a45fa
commit e11085ca91

View File

@@ -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 = "<!--" + datetime.now().strftime("%Y-%m-%d") + " p. " + match.group(1) + "-->"`
endsnippet