Template:Template:Terminate sentence
{{#vardefine:txt|}} {{#vardefine:mark|.}} {{#vardefine:ref|}} {{#vardefine:trim|yes}}
{{#vardefine:txt|
{{#var:txt}}
}}
{{#vardefine:lastIsTerm|
0
}}
{{#vardefine:needsMark|
1
}}
{{#var:txt}}{{#var:mark}} {{#var:ref}}
- Examples
Template documentation
[edit source]Template:Terminate sentence ensures a sentence ends with a specified terminator (default: a period). It avoids adding duplicate terminators and can optionally trim trailing spaces. It attempts to ignore trailing closing quotes or brackets when deciding whether a terminator is already present.
Usage
[edit source]Basic:
{{Terminate sentence|This is a sentence}}
→ This is a sentence.
Named parameters:
{{Terminate sentence
|text=He said "Hello"
|term=.
}}
→ He said "Hello".
Custom terminator:
{{Terminate sentence|text=Warning|term=!}}
→ Warning!
Avoid duplicate terminator:
{{Terminate sentence|text=Already done.|term=.}}
→ Already done.
Trim trailing spaces:
{{Terminate sentence|text=Ends with space |trim=yes}}
→ Ends with space.
Skip processing:
{{Terminate sentence|text=No changes here|skip=yes}}
→ No changes here
Append a note:
{{Terminate sentence|text=Complete|note=(source: 2025)}}
→ Complete. (source: 2025)
Parameters
[edit source]- 1 / text
- The input text to terminate.
- term
- The terminator to enforce at the end. Default is
.. Common choices:!,?. - trim
- If
yes/true/1, strips trailing spaces before checking. - skip
- If
yes/true/1, returnstextunchanged (still appendsnoteif provided). - allowdup
- If
yes/true/1, allows duplicate terminators (e.g., ellipses). Default disallows duplicates. - note
- Optional text appended after a space, unaffected by termination logic.
Behavior details
[edit source]- Terminator detection attempts to ignore trailing closing quotes/brackets (", ', ”, ), ], }).
- If the last visible character equals
term, no extra terminator is added unlessallowdup=yes. - If
trim=yes, trailing spaces are removed before detection. - If
noteis present, it is added with a leading space after the final text.
Examples
[edit source]- Quotes:
{{Terminate sentence|text=He whispered "hush"|term=.}}
→ He whispered "hush".
- Parentheses:
{{Terminate sentence|text=Complete (verified)|term=.}}
→ Complete (verified).
- Exclamation:
{{Terminate sentence|text=Alert|term=!}}
→ Alert!
- Ellipsis (allow duplicates):
{{Terminate sentence|text=Wait...|term=.|allowdup=yes}}
→ Wait....
Best practices
[edit source]- Prefer using
termthat matches the sentence intent (., !, ?). - For complex punctuation, consider the Lua-powered variant below.
- Document usage in your template’s /doc page where you incorporate this helper.
Lua-powered variant (optional)
[edit source]For more robust detection (including multilingual quotes and punctuation), create Module:TerminateUtil with:
-- Module:TerminateUtil
local M = {}
local closing = {
[")"] = true, ["]"] = true, ["}"] = true,
['"'] = true, ["'"] = true, ["”"] = true, ["’"] = true, ["»"] = true, ["›"] = true
}
local function trimRight(s)
return (s:gsub("%s+$",""))
end
function M.lastVisibleChar(args)
local s = args.s or ""
s = trimRight(s)
local i = #s
while i > 0 do
local c = s:sub(i,i)
if closing[c] then
i = i - 1
else
return c
end
end
return ""
end
return M
Then update the template to call:
{{#invoke:TerminateUtil|lastVisibleChar|s=text}}
This improves detection for closing quotes and brackets.
See also
[edit source]Template documentation
[edit source]Template:Terminate sentence ensures a sentence ends with a specified terminator (default: a period). It avoids adding duplicate terminators and can optionally trim trailing spaces. It attempts to ignore trailing closing quotes or brackets when deciding whether a terminator is already present.
Usage
[edit source]Basic:
{{Terminate sentence|This is a sentence}}
→ This is a sentence.
Named parameters:
{{Terminate sentence
|text=He said "Hello"
|term=.
}}
→ He said "Hello".
Custom terminator:
{{Terminate sentence|text=Warning|term=!}}
→ Warning!
Avoid duplicate terminator:
{{Terminate sentence|text=Already done.|term=.}}
→ Already done.
Trim trailing spaces:
{{Terminate sentence|text=Ends with space |trim=yes}}
→ Ends with space.
Skip processing:
{{Terminate sentence|text=No changes here|skip=yes}}
→ No changes here
Append a note:
{{Terminate sentence|text=Complete|note=(source: 2025)}}
→ Complete. (source: 2025)
Parameters
[edit source]- 1 / text
- The input text to terminate.
- term
- The terminator to enforce at the end. Default is
.. Common choices:!,?. - trim
- If
yes/true/1, strips trailing spaces before checking. - skip
- If
yes/true/1, returnstextunchanged (still appendsnoteif provided). - allowdup
- If
yes/true/1, allows duplicate terminators (e.g., ellipses). Default disallows duplicates. - note
- Optional text appended after a space, unaffected by termination logic.
Behavior details
[edit source]- Terminator detection attempts to ignore trailing closing quotes/brackets (", ', ”, ), ], }).
- If the last visible character equals
term, no extra terminator is added unlessallowdup=yes. - If
trim=yes, trailing spaces are removed before detection. - If
noteis present, it is added with a leading space after the final text.
Examples
[edit source]- Quotes:
{{Terminate sentence|text=He whispered "hush"|term=.}}
→ He whispered "hush".
- Parentheses:
{{Terminate sentence|text=Complete (verified)|term=.}}
→ Complete (verified).
- Exclamation:
{{Terminate sentence|text=Alert|term=!}}
→ Alert!
- Ellipsis (allow duplicates):
{{Terminate sentence|text=Wait...|term=.|allowdup=yes}}
→ Wait....
Best practices
[edit source]- Prefer using
termthat matches the sentence intent (., !, ?). - For complex punctuation, consider the Lua-powered variant below.
- Document usage in your template’s /doc page where you incorporate this helper.
Lua-powered variant (optional)
[edit source]For more robust detection (including multilingual quotes and punctuation), create Module:TerminateUtil with:
-- Module:TerminateUtil
local M = {}
local closing = {
[")"] = true, ["]"] = true, ["}"] = true,
['"'] = true, ["'"] = true, ["”"] = true, ["’"] = true, ["»"] = true, ["›"] = true
}
local function trimRight(s)
return (s:gsub("%s+$",""))
end
function M.lastVisibleChar(args)
local s = args.s or ""
s = trimRight(s)
local i = #s
while i > 0 do
local c = s:sub(i,i)
if closing[c] then
i = i - 1
else
return c
end
end
return ""
end
return M
Then update the template to call:
{{#invoke:TerminateUtil|lastVisibleChar|s=text}}
This improves detection for closing quotes and brackets.
See also
[edit source]Template documentation
[edit source]Template:Terminate sentence ensures a sentence ends with a specified terminator (default: a period). It avoids adding duplicate terminators and can optionally trim trailing spaces. It attempts to ignore trailing closing quotes or brackets when deciding whether a terminator is already present.
Usage
[edit source]Basic:
{{Terminate sentence|This is a sentence}}
→ This is a sentence.
Named parameters:
{{Terminate sentence
|text=He said "Hello"
|term=.
}}
→ He said "Hello".
Custom terminator:
{{Terminate sentence|text=Warning|term=!}}
→ Warning!
Avoid duplicate terminator:
{{Terminate sentence|text=Already done.|term=.}}
→ Already done.
Trim trailing spaces:
{{Terminate sentence|text=Ends with space |trim=yes}}
→ Ends with space.
Skip processing:
{{Terminate sentence|text=No changes here|skip=yes}}
→ No changes here
Append a note:
{{Terminate sentence|text=Complete|note=(source: 2025)}}
→ Complete. (source: 2025)
Parameters
[edit source]- 1 / text
- The input text to terminate.
- term
- The terminator to enforce at the end. Default is
.. Common choices:!,?. - trim
- If
yes/true/1, strips trailing spaces before checking. - skip
- If
yes/true/1, returnstextunchanged (still appendsnoteif provided). - allowdup
- If
yes/true/1, allows duplicate terminators (e.g., ellipses). Default disallows duplicates. - note
- Optional text appended after a space, unaffected by termination logic.
Behavior details
[edit source]- Terminator detection attempts to ignore trailing closing quotes/brackets (", ', ”, ), ], }).
- If the last visible character equals
term, no extra terminator is added unlessallowdup=yes. - If
trim=yes, trailing spaces are removed before detection. - If
noteis present, it is added with a leading space after the final text.
Examples
[edit source]- Quotes:
{{Terminate sentence|text=He whispered "hush"|term=.}}
→ He whispered "hush".
- Parentheses:
{{Terminate sentence|text=Complete (verified)|term=.}}
→ Complete (verified).
- Exclamation:
{{Terminate sentence|text=Alert|term=!}}
→ Alert!
- Ellipsis (allow duplicates):
{{Terminate sentence|text=Wait...|term=.|allowdup=yes}}
→ Wait....
Best practices
[edit source]- Prefer using
termthat matches the sentence intent (., !, ?). - For complex punctuation, consider the Lua-powered variant below.
- Document usage in your template’s /doc page where you incorporate this helper.
Lua-powered variant (optional)
[edit source]For more robust detection (including multilingual quotes and punctuation), create Module:TerminateUtil with:
-- Module:TerminateUtil
local M = {}
local closing = {
[")"] = true, ["]"] = true, ["}"] = true,
['"'] = true, ["'"] = true, ["”"] = true, ["’"] = true, ["»"] = true, ["›"] = true
}
local function trimRight(s)
return (s:gsub("%s+$",""))
end
function M.lastVisibleChar(args)
local s = args.s or ""
s = trimRight(s)
local i = #s
while i > 0 do
local c = s:sub(i,i)
if closing[c] then
i = i - 1
else
return c
end
end
return ""
end
return M
Then update the template to call:
{{#invoke:TerminateUtil|lastVisibleChar|s=text}}
This improves detection for closing quotes and brackets.
See also
[edit source]Template documentation
[edit source]Template:Terminate sentence ensures a sentence ends with a specified terminator (default: a period). It avoids adding duplicate terminators and can optionally trim trailing spaces. It attempts to ignore trailing closing quotes or brackets when deciding whether a terminator is already present.
Usage
[edit source]Basic:
{{Terminate sentence|This is a sentence}}
→ This is a sentence.
Named parameters:
{{Terminate sentence
|text=He said "Hello"
|term=.
}}
→ He said "Hello".
Custom terminator:
{{Terminate sentence|text=Warning|term=!}}
→ Warning!
Avoid duplicate terminator:
{{Terminate sentence|text=Already done.|term=.}}
→ Already done.
Trim trailing spaces:
{{Terminate sentence|text=Ends with space |trim=yes}}
→ Ends with space.
Skip processing:
{{Terminate sentence|text=No changes here|skip=yes}}
→ No changes here
Append a note:
{{Terminate sentence|text=Complete|note=(source: 2025)}}
→ Complete. (source: 2025)
Parameters
[edit source]- 1 / text
- The input text to terminate.
- term
- The terminator to enforce at the end. Default is
.. Common choices:!,?. - trim
- If
yes/true/1, strips trailing spaces before checking. - skip
- If
yes/true/1, returnstextunchanged (still appendsnoteif provided). - allowdup
- If
yes/true/1, allows duplicate terminators (e.g., ellipses). Default disallows duplicates. - note
- Optional text appended after a space, unaffected by termination logic.
Behavior details
[edit source]- Terminator detection attempts to ignore trailing closing quotes/brackets (", ', ”, ), ], }).
- If the last visible character equals
term, no extra terminator is added unlessallowdup=yes. - If
trim=yes, trailing spaces are removed before detection. - If
noteis present, it is added with a leading space after the final text.
Examples
[edit source]- Quotes:
{{Terminate sentence|text=He whispered "hush"|term=.}}
→ He whispered "hush".
- Parentheses:
{{Terminate sentence|text=Complete (verified)|term=.}}
→ Complete (verified).
- Exclamation:
{{Terminate sentence|text=Alert|term=!}}
→ Alert!
- Ellipsis (allow duplicates):
{{Terminate sentence|text=Wait...|term=.|allowdup=yes}}
→ Wait....
Best practices
[edit source]- Prefer using
termthat matches the sentence intent (., !, ?). - For complex punctuation, consider the Lua-powered variant below.
- Document usage in your template’s /doc page where you incorporate this helper.
Lua-powered variant (optional)
[edit source]For more robust detection (including multilingual quotes and punctuation), create Module:TerminateUtil with:
-- Module:TerminateUtil
local M = {}
local closing = {
[")"] = true, ["]"] = true, ["}"] = true,
['"'] = true, ["'"] = true, ["”"] = true, ["’"] = true, ["»"] = true, ["›"] = true
}
local function trimRight(s)
return (s:gsub("%s+$",""))
end
function M.lastVisibleChar(args)
local s = args.s or ""
s = trimRight(s)
local i = #s
while i > 0 do
local c = s:sub(i,i)
if closing[c] then
i = i - 1
else
return c
end
end
return ""
end
return M
Then update the template to call:
{{#invoke:TerminateUtil|lastVisibleChar|s=text}}
This improves detection for closing quotes and brackets.
See also
[edit source]Template documentation
[edit source]Template:Terminate sentence ensures a sentence ends with a specified terminator (default: a period). It avoids adding duplicate terminators and can optionally trim trailing spaces. It attempts to ignore trailing closing quotes or brackets when deciding whether a terminator is already present.
Usage
[edit source]Basic:
{{Terminate sentence|This is a sentence}}
→ This is a sentence.
Named parameters:
{{Terminate sentence
|text=He said "Hello"
|term=.
}}
→ He said "Hello".
Custom terminator:
{{Terminate sentence|text=Warning|term=!}}
→ Warning!
Avoid duplicate terminator:
{{Terminate sentence|text=Already done.|term=.}}
→ Already done.
Trim trailing spaces:
{{Terminate sentence|text=Ends with space |trim=yes}}
→ Ends with space.
Skip processing:
{{Terminate sentence|text=No changes here|skip=yes}}
→ No changes here
Append a note:
{{Terminate sentence|text=Complete|note=(source: 2025)}}
→ Complete. (source: 2025)
Parameters
[edit source]- 1 / text
- The input text to terminate.
- term
- The terminator to enforce at the end. Default is
.. Common choices:!,?. - trim
- If
yes/true/1, strips trailing spaces before checking. - skip
- If
yes/true/1, returnstextunchanged (still appendsnoteif provided). - allowdup
- If
yes/true/1, allows duplicate terminators (e.g., ellipses). Default disallows duplicates. - note
- Optional text appended after a space, unaffected by termination logic.
Behavior details
[edit source]- Terminator detection attempts to ignore trailing closing quotes/brackets (", ', ”, ), ], }).
- If the last visible character equals
term, no extra terminator is added unlessallowdup=yes. - If
trim=yes, trailing spaces are removed before detection. - If
noteis present, it is added with a leading space after the final text.
Examples
[edit source]- Quotes:
{{Terminate sentence|text=He whispered "hush"|term=.}}
→ He whispered "hush".
- Parentheses:
{{Terminate sentence|text=Complete (verified)|term=.}}
→ Complete (verified).
- Exclamation:
{{Terminate sentence|text=Alert|term=!}}
→ Alert!
- Ellipsis (allow duplicates):
{{Terminate sentence|text=Wait...|term=.|allowdup=yes}}
→ Wait....
Best practices
[edit source]- Prefer using
termthat matches the sentence intent (., !, ?). - For complex punctuation, consider the Lua-powered variant below.
- Document usage in your template’s /doc page where you incorporate this helper.
Lua-powered variant (optional)
[edit source]For more robust detection (including multilingual quotes and punctuation), create Module:TerminateUtil with:
-- Module:TerminateUtil
local M = {}
local closing = {
[")"] = true, ["]"] = true, ["}"] = true,
['"'] = true, ["'"] = true, ["”"] = true, ["’"] = true, ["»"] = true, ["›"] = true
}
local function trimRight(s)
return (s:gsub("%s+$",""))
end
function M.lastVisibleChar(args)
local s = args.s or ""
s = trimRight(s)
local i = #s
while i > 0 do
local c = s:sub(i,i)
if closing[c] then
i = i - 1
else
return c
end
end
return ""
end
return M
Then update the template to call:
{{#invoke:TerminateUtil|lastVisibleChar|s=text}}
This improves detection for closing quotes and brackets.
See also
[edit source]Template documentation
[edit source]Template:Terminate sentence ensures a sentence ends with a specified terminator (default: a period). It avoids adding duplicate terminators and can optionally trim trailing spaces. It attempts to ignore trailing closing quotes or brackets when deciding whether a terminator is already present.
Usage
[edit source]Basic:
{{Terminate sentence|This is a sentence}}
→ This is a sentence.
Named parameters:
{{Terminate sentence
|text=He said "Hello"
|term=.
}}
→ He said "Hello".
Custom terminator:
{{Terminate sentence|text=Warning|term=!}}
→ Warning!
Avoid duplicate terminator:
{{Terminate sentence|text=Already done.|term=.}}
→ Already done.
Trim trailing spaces:
{{Terminate sentence|text=Ends with space |trim=yes}}
→ Ends with space.
Skip processing:
{{Terminate sentence|text=No changes here|skip=yes}}
→ No changes here
Append a note:
{{Terminate sentence|text=Complete|note=(source: 2025)}}
→ Complete. (source: 2025)
Parameters
[edit source]- 1 / text
- The input text to terminate.
- term
- The terminator to enforce at the end. Default is
.. Common choices:!,?. - trim
- If
yes/true/1, strips trailing spaces before checking. - skip
- If
yes/true/1, returnstextunchanged (still appendsnoteif provided). - allowdup
- If
yes/true/1, allows duplicate terminators (e.g., ellipses). Default disallows duplicates. - note
- Optional text appended after a space, unaffected by termination logic.
Behavior details
[edit source]- Terminator detection attempts to ignore trailing closing quotes/brackets (", ', ”, ), ], }).
- If the last visible character equals
term, no extra terminator is added unlessallowdup=yes. - If
trim=yes, trailing spaces are removed before detection. - If
noteis present, it is added with a leading space after the final text.
Examples
[edit source]- Quotes:
{{Terminate sentence|text=He whispered "hush"|term=.}}
→ He whispered "hush".
- Parentheses:
{{Terminate sentence|text=Complete (verified)|term=.}}
→ Complete (verified).
- Exclamation:
{{Terminate sentence|text=Alert|term=!}}
→ Alert!
- Ellipsis (allow duplicates):
{{Terminate sentence|text=Wait...|term=.|allowdup=yes}}
→ Wait....
Best practices
[edit source]- Prefer using
termthat matches the sentence intent (., !, ?). - For complex punctuation, consider the Lua-powered variant below.
- Document usage in your template’s /doc page where you incorporate this helper.
Lua-powered variant (optional)
[edit source]For more robust detection (including multilingual quotes and punctuation), create Module:TerminateUtil with:
-- Module:TerminateUtil
local M = {}
local closing = {
[")"] = true, ["]"] = true, ["}"] = true,
['"'] = true, ["'"] = true, ["”"] = true, ["’"] = true, ["»"] = true, ["›"] = true
}
local function trimRight(s)
return (s:gsub("%s+$",""))
end
function M.lastVisibleChar(args)
local s = args.s or ""
s = trimRight(s)
local i = #s
while i > 0 do
local c = s:sub(i,i)
if closing[c] then
i = i - 1
else
return c
end
end
return ""
end
return M
Then update the template to call:
{{#invoke:TerminateUtil|lastVisibleChar|s=text}}
This improves detection for closing quotes and brackets.