Review: typo and neater regex
This commit is contained in:
parent
75654740b3
commit
3c667f3f9b
1 changed files with 5 additions and 5 deletions
|
@ -24,19 +24,19 @@ end
|
||||||
-- [text]({{ site.baseurl }}/chapter/#more-stuff) -> [text](#chapter-more-stuff)
|
-- [text]({{ site.baseurl }}/chapter/#more-stuff) -> [text](#chapter-more-stuff)
|
||||||
--
|
--
|
||||||
-- Case 2:
|
-- Case 2:
|
||||||
-- [text]({{ site.baseurl }}/chapter/) -> [text](#stuff)
|
-- [text]({{ site.baseurl }}/chapter/) -> [text](#chapter)
|
||||||
--
|
--
|
||||||
-- All other Links are ignored.
|
-- All other Links are ignored.
|
||||||
function Link (el)
|
function Link (el)
|
||||||
local n
|
local n
|
||||||
-- When parsing a markdown link such as "[stuff]({{ site.baseurl }}/Naturals",
|
-- When parsing a markdown link such as "[stuff]({{ site.baseurl }}/Naturals",
|
||||||
-- pandoc encodes the link's URL with percent-encoding, resulting in the
|
-- pandoc encodes the link's URL with percent-encoding, resulting in the
|
||||||
-- link "[stuff](%7B%7B+site.baseurl+%7D%7D%2FNaturals)". This is why the
|
-- link "[stuff](%7B%7B%20site.baseurl%20%7D%7D/Naturals)".
|
||||||
-- pattern begins with ".*site%.baseurl.*" and not "{{ site%.baseurl }}".
|
local baseurl = "%%7B%%7B%%20site%.baseurl%%20%%7D%%7D"
|
||||||
el.target, n = el.target:gsub("^.*site%.baseurl.*/(%w+)/#([%w-]+)$", -- case 1
|
el.target, n = el.target:gsub("^" .. baseurl .. "/(%w+)/#([%w-]+)$", -- case 1
|
||||||
"#%1-%2")
|
"#%1-%2")
|
||||||
if n == 0 then
|
if n == 0 then
|
||||||
el.target = el.target:gsub("^.*site%.baseurl.*/(%w+)/$", -- case 2
|
el.target = el.target:gsub("^" .. baseurl .. "/(%w+)/$", -- case 2
|
||||||
"#%1")
|
"#%1")
|
||||||
end
|
end
|
||||||
return el
|
return el
|
||||||
|
|
Loading…
Reference in a new issue