Module:Module introspection: Difference between revisions

Ganaram inukshuk (talk | contribs)
bugfix offset line numbers
Ganaram inukshuk (talk | contribs)
No edit summary
Line 11: Line 11:
if not content then return "" end
if not content then return "" end


-- Preserve line breaks inside comments
-- Step 1: blank multi-line comments including --[[ ... ]] and --[=[ ... ]=]
 
content = content:gsub("%-%-%[(=*)%[(.-)%]%1%]", function(eq, body)
-- Handle multi-line comments with optional equals (e.g. --[[ ... ]] or --[=[ ... ]=])
-- Replace everything except newlines with spaces
content = content:gsub("%-%-%[(=*)%[.-%]%1%]", function(s)
local blank = body:gsub("[^\n]", " ")
-- Replace all non-newline characters with spaces to preserve line numbers
return "--[[" .. blank .. "]]"
return (s:gsub("[^\n]", " "))
end)
end)


-- Handle single-line comments
-- Step 2: blank single-line comments
content = content:gsub("%-%-[^\n]*", function(s)
content = content:gsub("%-%-[^\n]*", function(s)
return string.rep(" ", #s)
return s:gsub("[^\n]", " ")
end)
end)