I have created a Quarto extension to remove all occurrences of ".html" from the links. The Lua script is as follows:
function Link(el)
local str = el.target
local result = str:gsub("(.-)%.html(.-)", "%1%2")
el.target = result
return el
end
It works perfectly in the test example created within the extension. However, when I include it in my Quarto book project, it doesn't work.
The extension is being called correctly because I replaced the code with another one to format tags with italics, and upon rendering, it worked. But when I put the above code back, it doesn't work. All links ( tags) still have ".html."
I also tried changing the order so that my filter runs after the Quarto’s built-in filters (as below), but it still didn't work.
filters:
- lightbox
- quarto
- strip-dot-html-off
Any ideas?
I don't see anything wrong with the string replacement code, as executing ("foo-bar.html-some-more"):gsub("(.-)%.html(.-)", "%1%2")
returns foo-bar-some-more
as expected. You haven't provided a single example as what kind of URLs you expect to modify, so maybe the issue is with something really simple (for example, using .htm
extension instead of .html
).
I'd check if the code works outside of your environment in a regular Lua interpreter and also check if you get the expected result if you set the result
value manually to whatever result you expect from gsub
(just to make sure that the rest of the processing happens as you envision it).