Fabrice changed the content model of the page Module:Quote from "wikitext" to "Scribunto module" |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p. | -- Main function for processing quote text | ||
local | function p.process(frame) | ||
if | local raw = frame.args.text or frame.args[1] or "" | ||
if raw == "" then return "" end | |||
-- Step 1: Remove | -- Optional: restore pipes/equals if you replace them earlier in template | ||
local | -- raw = raw:gsub("__EQUALS__", "=") | ||
-- Step 2: Replace | |||
-- Step 1: Remove continuation hyphens ( - at end of line, possibly with spaces) | |||
-- Step 3: | -- Matches: optional spaces, then -, then optional spaces, then newline | ||
local text = raw:gsub("%s*%-+%s*\n", " ") | |||
-- Step 4: | |||
-- Step 2: Replace any remaining single newlines with space (join lines into paragraph) | |||
return | 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 → <br />, 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 <br /> for use inside <poem> or directly | |||
text = text:gsub("\r?\n", "<br />") | |||
return text | |||
end | end | ||
return p | return p | ||
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