Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a21e479d5ec0c69c

Jump to content

Template talk:Trim quotes

Page contents not supported in other languages.
Add topic
From Wikipedia, the free encyclopedia
(Redirected from Module talk:Trim quotes)
Latest comment: 2 months ago by Jonesey95 in topic Ampersand handling issue

Wikimarkup interference

[edit]

This needs to be able (always or at least optionally) to distinguish "foo" and 'bar' (to be trimmed) from ''baz'', '''quux''', ''baz'' '''quux''', and '''quux''' ''baz'' (not to be trimmed). Ideally it would also detect '''quux''' 'yadda yadda!' (to output '''quux''' yadda yadda!) and "doodle doodle dee" ''baz'' (to output doodle doodle dee ''baz''). Right now, this is breaking various uses of {{Quote}} unless measures are taken on a case-by-case basis (which most editors will neither notice nor understand) to escape this behavior when the quoted material start and ends with bold or italic wikimarkup. There's really not a reason for this template to touch '' or ''' at all, unless specially told to do so by some parameter, since neither multi-apostrophe string is used for quotation, so we don't need to strip it. I can't Lua my way out of a paper bag, so someone who knows the language and its string-matching antics better than I do should tackle this.  — SMcCandlish ¢ 😼  21:31, 30 January 2020 (UTC)Reply

How would you handle "kevin's" or "'til" or "'til he went to kevin's"? Gonnym (talk) 22:04, 30 January 2020 (UTC)Reply
As double-quotes aren't used in wiki-markup, the only changes needed are to scan for multi-quote scenarios ("Bah" he said, "Humbug") and to provide an "opt out" for when a person WANTS the quotation marks to appear, such as quoting computer code where the quotations are important, like
Here is the string that needs to be changed: {{quote|"Hello WOrld"|notrim=1}}
The bigger issue would be the Britsh quotation style, where "'til we meet at the Jones'" (meaning "Until we meet at the Jones' house") becomes ''til we meet at the Jones''. Note the double-single-quote for a quotation mark and apostrophe at the beginning, and the reverse at the end. Of course, there could be a book titled 'Til we meet at the Jones' as well. Or a British book which is a quotation: ''Til we meet at the Jones'' You can see that the issue of single quotes this is probably intractable without some sort of context-awareness. An opt-out parameter to suppress stripping quotes solves this issue as well.
As an additional general solution, better advertising of the quotation mark templates listed here in the documentation of quotation-related templates may be the best we can do when it comes to single-quotation-mark issues. davidwr/(talk)/(contribs) 23:23, 30 January 2020 (UTC)Reply
Sorry if this wasn't clear. The double qutoes was to show here what text I'm referring to and not what text is sent to the template. --Gonnym (talk) 10:56, 31 January 2020 (UTC)Reply
May I make a recommendation: Add an |suppresstrim=1 parameter that makes {{trim quotes}} just return |s= or |1=, so that existing templates that call it are easier to modify. It's a lot easier to pass a |suppresstrim= parameter to you than it is to rewrite existing templates as a large if-then block of "if suppresstrim not present then do normal stuff else do normal stuff except don't call {{trim quotes}}". Rewriting such templates can result in block-copied code which becomes hard to maintain - I know, I seriously considered this option with today's changes to Template:quote. I went with the much simpler option of just throwing in <nowiki /> if a newly-added parameter |notrim= was present. Also, consider making the change at Module:Trim quotes. davidwr/(talk)/(contribs) 23:31, 30 January 2020 (UTC)Reply
This version avoids trimming consecutive single quotes, but doesn't handle internal trimming like '''quux''' 'yadda yadda!''''quux''' yadda yadda!.
function trim_quotes(str)
	str = mw.text.trim(str)
	local prev
	while true do
		local first = str:sub(1, 1)
		if first == str:sub(-1, -1)
		and (first == '"' or (first == "'" and not (str:sub(2, 2) == "'" or str:sub(-2, -2) == "'"))) then
			str = str:sub(2, -2)
		else
			break
		end
		prev = first
	end
	return str
end
Eru·tuon 04:13, 31 January 2020 (UTC)Reply
This fails with 'quux' 'yadda yadda!'. --Gonnym (talk) 11:02, 31 January 2020 (UTC)Reply
Right, that's not very different from '''quux''' 'yadda yadda!': there's a quotation and something else. The code relies on the assumption that the parameter contains a single quotation if any. It's a crappy draft, not good enough to be deployed in the template. — Eru·tuon 21:26, 31 January 2020 (UTC)Reply
How about something like
function trim_quotes(str)
	str = mw.ustring.gsub(str, '"', '')
	str = mw.ustring.gsub(str, "%f['%w]'%f[%w](.-)%f[^%w.!?]'%f[^'%w]", "%1")
	return str
end
That matches 'quote' where the first apostrophe is not preceded by a letter or another apostrophe but is followed by a letter, and the second apostrophe is preceded by a letter (or punctuation commonly found at the end of a quotation) but is not followed by a letter or another apostrophe.
It handles text like 'This won't break' but not 'St. James' Park'. The latter, I think, is impossible to parse in general. Certes (talk) 20:34, 31 January 2020 (UTC)Reply

Ampersand handling issue

[edit]

Please see this test case, in which an ampersanded soft hyphen is converted to a literal ampersand and the character name instead of being rendered. – Jonesey95 (talk) 06:23, 26 May 2026 (UTC)Reply