Add section link snippet

master
Hektor Misplon 2024-01-09 12:45:49 +01:00
parent 4e625a45fa
commit e11085ca91
Signed by: hektor
GPG Key ID: 5151AF79E723F21C
1 changed files with 9 additions and 0 deletions

View File

@ -57,6 +57,9 @@ def code_inline():
def code(): def code():
return code_inline() or code_block() return code_inline() or code_block()
def slugify(text):
return re.sub('\s+', '-', text.lower())
def linkify(text, link): def linkify(text, link):
return f"[{text}]({link})" return f"[{text}]({link})"
@ -741,6 +744,12 @@ for i in range(int(match.group(1)), int(match.group(2)) + 1):
` `
endsnippet 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 snippet cp(\d+) "Comment current page (and date)" r
`!p snip.rv = "<!--" + datetime.now().strftime("%Y-%m-%d") + " p. " + match.group(1) + "-->"` `!p snip.rv = "<!--" + datetime.now().strftime("%Y-%m-%d") + " p. " + match.group(1) + "-->"`
endsnippet endsnippet