Module:Quote: Difference between revisions
Fabrice P. Laussy's Web
No edit summary
Fabrice (talk | contribs)
m 1 revision imported
(No difference)

Revision as of 10:45, 31 December 2025

local p = {}

-- Main function for processing quote text function p.process(frame)

   local raw = frame.args.text or frame.args[1] or ""
   if raw == "" then return "" end
   -- Optional: restore pipes/equals if you replace them earlier in template
   -- raw = raw:gsub("__EQUALS__", "=")
   -- Step 1: Remove continuation hyphens ( - at end of line, possibly with spaces)
   -- Matches: optional spaces, then -, then optional spaces, then newline
   local text = raw:gsub("%s*%-+%s*\n", " ")
   -- Step 2: Replace any remaining single newlines with space (join lines into paragraph)
   text = text:gsub("\n", " ")
   -- Step 3: Collapse multiple spaces into one
   text = text:gsub("%s+", " ")
   -- Step 4: Trim leading/trailing space
   text = text:match("^%s*(.-)%s*$")
   return text

end

-- Alternative function if you want to PRESERVE deliberate line breaks (e.g. for poetry) -- Use this if you want newlines →
, but still remove continuation hyphens function p.processWithBreaks(frame)

   local raw = frame.args.text or frame.args[1] or ""
   if raw == "" then return "" end
   -- Remove continuation hyphens, join those lines seamlessly
   local text = raw:gsub("%s*%-+%s*\r?\n", "")
   -- Convert remaining newlines to 
for use inside <poem> or directly text = text:gsub("\r?\n", "
")
   return text

end

return p