lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


target:gsub("%.md%f[%z#]", ".html")


From: Peter Matulis <pmatulis@gmail.com>
Sent: Friday, 22 January 2021 3:37 AM
To: lua-l@lists.lua.org <lua-l@lists.lua.org>
Subject: Combining two tiny scripts
 
Hi, I am very new to Lua but I do have two tiny Pandoc Lua filters that work. They are extremely similar and I would like to combine them. I'm just not sure how to introduce the conditional aspect.

1. This script simply exchanges the '.md' file extension for the '.html' extension:


function Link (link)
  link.target = link.target:gsub('(.+)%.md', '%1.html')
  return link
end



2. This script does the same except it handles the case where the link contains an anchor:


function Link (link)
  link.target = link.target:gsub('(.+)%.md%#(.+)', '%1.html#%2')
  return link
end



/pm