Template talk:Pre
Add topicMaking all pres autoflow
[edit]Just add this to your user CSS:
/* Make preformatted sections overflow with a scrollbar instead of uglies */
pre {
overflow: auto;
width: auto;
}
Maybe usurp the name Template:Pre?
[edit]I wonder whether it would be particularly bad if the name Template:Pre was usurped by the current Template:Pre2?
{{Pre2}} generates <pre>s, but with wrapped text, or a scrollbox, depending on the settings/parameters. It's quite new, but it would be easier to remember if it only had the name {{Pre}}. The reason I like it is that I use the modern skin, and so {{Pre}}, as it is at the moment, shows <pre> differently to normal. It's still a very useful template though, well done on making it! I'm wondering if it could be moved to a different name?
All comments very much appreciated; thanks, Drum guy (talk) 23:16, 13 June 2008 (UTC)
- I've imported Pre2 in my wiki (http://neurov.is/on), since it seemed cleaner at first glance than Pre. Thanks for creating it! I prefer Pre2 and I think it would be worthwhile to consider replacing Pre with it, but I don't know enough about the two to really recommend doing so. Would there be any backwards compatibility issues? JonathanWilliford (talk) 14:05, 13 August 2009 (UTC)
Double border
[edit]A recent change to the styling of the <code>...</code> element means that this template no longer does what it claims to do:
This Pre-format can look like this.
is not at all similar to
This Pre-format can look like this.
See related post at MediaWiki talk:Common.css#Double border. --Redrose64 (talk) 09:16, 1 August 2014 (UTC)
- Why is this template using
<code>in the first place? That is an inline tag.-- [[User:Edokter]] {{talk}}10:15, 1 August 2014 (UTC)- Then why change it to
<kbd>...</kbd>? That's also an inline element. --Redrose64 (talk) 13:51, 1 August 2014 (UTC)- There are several elements in HTML5 that we might expect a browser to render as mono-spaced, but which have different semantic meanings. The relevant document is http://www.w3.org/TR/html5/text-level-semantics.html and it defines:
<code>as "a fragment of computer code";<kbd>as "user input"; and<samp>as "(sample) output from a program". Semantically, you can't determine the correct tag here as it would depend on the content supplied to the template. I'd have thought that a container with its font-family set to monospace would be the general solution here. --RexxS (talk) 14:42, 1 August 2014 (UTC) - I tried
<pre>, but that disables all template code inside. Any way around that?-- [[User:Edokter]] {{talk}}15:12, 1 August 2014 (UTC)- It looks like the
<kbd>...</kbd>is only being used to supply the monospaced font. In the current sandbox, I've removed the<kdb>...</kdb>and appliedfont-family: monospace; font-size:1.3em;to the container. Looking at Template:Pre/testcases, it seems to do the job. See what you think? --RexxS (talk) 15:54, 1 August 2014 (UTC)- I want to use
<pre>so all the inline styling can be removed.-- [[User:Edokter]] {{talk}}16:15, 1 August 2014 (UTC) - I stole a trick from {{pre2}}, now it looks much better.
-- [[User:Edokter]] {{talk}}16:29, 1 August 2014 (UTC)- Yesss... what does the empty
<noinclude></noinclude>do? --Redrose64 (talk) 16:47, 1 August 2014 (UTC)- Apparently, it prevents the pre tag from kicking in (and disabling all the template code) before being transcluded.
-- [[User:Edokter]] {{talk}}18:10, 1 August 2014 (UTC)
- Apparently, it prevents the pre tag from kicking in (and disabling all the template code) before being transcluded.
- Yesss... what does the empty
- I want to use
- It looks like the
- There are several elements in HTML5 that we might expect a browser to render as mono-spaced, but which have different semantic meanings. The relevant document is http://www.w3.org/TR/html5/text-level-semantics.html and it defines:
- Then why change it to
Deprecating hack with params 2 through 20
[edit]In my recent documentation update, I boldly deprecated the evil hack with parameters 2 through 20, added in 2006, which ostensibly allows for up to 19 unescaped pipe characters (but of course cannot allow for an unescaped first equals sign). This hack is both wrong and bad. It's wrong because it causes incorrect spacing behaviour, defeating the purpose of preformatting. It's bad because it obfuscates the workings of the parameter mechanism (which encourages bad habits) and makes the template unnecessarily inefficient.
I would like to add a tracking category to the template that tracks the use of parameter 2. This should allow us to go in and fix all the broken invocations that fail to escape their pipe characters correctly. When all of them are fixed, this horrible hack can be removed.
Comments, opinions? – McDutchie (talk) 04:34, 30 December 2025 (UTC)
- "Evil" parameters? They're barely even mentioned in the documentation to start off with. Additionally, there has been no discussion to deprecate them, so I reverted your change. I don't fault you for being bold, but that was a little too bold. Primefac (talk) 10:44, 30 December 2025 (UTC)
- Having barely documented incorrect behaviour is actually worse than having prominently documented incorrect behaviour. So the fact that they're "barely mentioned" in the documentation only strengthens the argument for deprecating and then removing this nonsense. I'll add a clearer illustration of the wrongness below.
- Incorrect invocation
{{Pre | one | two || three ||| four}}- Actual output
one| two| three| four
- Expected output
one | two || three ||| four
- Correct invocations (produce the expected output)
{{Pre | one {{!}} two {{!}}{{!}} three {{!}}{{!}}{{!}} four}}{{Pre | <nowiki>one | two || three ||| four</nowiki>}}
- – McDutchie (talk) 15:14, 30 December 2025 (UTC)
- I'll be honest, I'm waiting for more input from other folk, but in the meantime just wanted to mention that the code from from {{Onlyinclude}} looks and behaves exactly as typed and intended. Also, the cat is still populating but there is only one article using a second param (and only 0 pages total). Primefac (talk) 23:26, 30 December 2025 (UTC) updated post-change to template Primefac (talk) 02:13, 11 January 2026 (UTC)
- I am struggling to see any relation between the present template and {{Onlyinclude}}. It does not include any hack or problem of the sort we're discussing. Please explain the relevance of your comment.
- As for the tracking category, I'm surprised you added it without awaiting the outcome of this discussion, after telling me off for merely editing the documentation. In any case, the current method does not catch an empty second parameter when a third, etc. is provided. The only way to be sure to catch all uses of the hack is to check them all. The method currently in the sandbox does that. – McDutchie (talk) 00:58, 31 December 2025 (UTC)
- My example above uses {{pre}} in the documentation, but because it doesn't have any extra spaces there is no "missing space" issue. As far as tracking categories goes, yes absolutely I added it because you come across as very confident that this is a widely-spread problem, and the first step towards determining if there is a problem is to see how many times it appears. Primefac (talk) 01:15, 31 December 2025 (UTC)
- I did not intentionally make any statement about how widespread the incorrect output is in practice. Any impression to the contrary is the result of a misunderstanding, and I apologise if I wasn't clear. My comments were intended to be purely on the (lack of) merits of the hack itself. My proposal to add a tracking category was precisely to find out how widespread the problem of incorrect output is in practice. However, if it turns out not to be widespread, then that just makes it even easier to get rid of this incorrect hack. – McDutchie (talk) 01:55, 31 December 2025 (UTC)
- My example above uses {{pre}} in the documentation, but because it doesn't have any extra spaces there is no "missing space" issue. As far as tracking categories goes, yes absolutely I added it because you come across as very confident that this is a widely-spread problem, and the first step towards determining if there is a problem is to see how many times it appears. Primefac (talk) 01:15, 31 December 2025 (UTC)
- I'll be honest, I'm waiting for more input from other folk, but in the meantime just wanted to mention that the code from from {{Onlyinclude}} looks and behaves exactly as typed and intended. Also, the cat is still populating but there is only one article using a second param (and only 0 pages total). Primefac (talk) 23:26, 30 December 2025 (UTC) updated post-change to template Primefac (talk) 02:13, 11 January 2026 (UTC)
- Having barely documented incorrect behaviour is actually worse than having prominently documented incorrect behaviour. So the fact that they're "barely mentioned" in the documentation only strengthens the argument for deprecating and then removing this nonsense. I'll add a clearer illustration of the wrongness below.
Right, so there are 20-ish cases (plus a few duplicate mentions due to templates transcluding /doc) in the tracking category. Since only the second parameter is checked for non-emptiness, it will miss cases like {{Pre||foo}}, but it will surely have caught the vast majority. Problems found:
- Venpa, User talk:EvKnight13, User:John J. Bulten/Friends, Template:Onlyinclude/doc, User talk:Opabinia regalis/Archive 10, User talk:Piotrus/Archive 64, Talk:The Horus Heresy/Archive 1
- Incorrect use of {{Pre}} or {{Pre2}} with failure to escape
|. Fix: escape the text passed with<nowiki>...</nowiki>, or fix bugs in such escaping. So, the problem that the hack was ostensibly meant to cope with is actually quite rare. - Template_talk:AfC_submission/Archive_1, User:BrandonXLF/scripts/doc/doc, User:Britmax, Talk:Headquarters and service company, User:Jeremy Butler/Things to Remember When Wikiing, Template talk:Now commons dated, User:Paul foord/Template links, Template talk:Rquote
- These pages use the obsolete {{Pre2}} with a first parameter of
scroll. Since that template now redirects to {{Pre}} in an incompatible way, that argument isn't handled correctly. Fix: change to correct {{Pre}} invocations. - Help talk:How to fix your signature/Archive 1
- These pages use the obsolete {{Pre2}} with a first parameter of
nowiki. Fix: replace with {{Pre}} and wrap argument in<nowiki>...</nowiki>. - User:JohnnyMyself, Template talk:Pre2, User:Wdchk/Sandbox
- Obsolete {{Pre2}} invocations as a code examples; will just have to stay broken.
It won't be very much work to fix all of these invocations, which is a great reason to fix them and then get rid of all that dead weight in the template. – McDutchie (talk) 18:23, 3 January 2026 (UTC)
- All the invocations that needed to be fixed are now fixed, and their pages are gone from the tracking category. Only the template itself and its doc and test cases are left to do now. Since there is now nothing else left that uses the "raw pipes" hack, I am going to assume it is okay to go ahead. – McDutchie (talk) 03:10, 6 January 2026 (UTC)
- This is now done, reducing the size of the template by about two thirds. – McDutchie (talk) 12:13, 8 January 2026 (UTC)
Compatibility with Parsoid
[edit]This template has another problem that is going to bite soon, when Wikipedia transitions to the new wikitext parser Parsoid. The hack that is currently used for disabling MediaWiki's recognition of the <pre>...</pre> tag, which is what allows the use of wikitext in preformatted blocks, will not work with Parsoid, so this template will break when Wikipedia eventually transitions to Parsoid. It took a little experimenting but I've figured out what the new canonical way is: we have to use the {{#tag}} parser function to generate a pre tag with the attribute format="wikitext", which was recently added for the explicit purpose of superseding that hack. The current Sandbox version does that, and works well in my testing, with and without Parsoid (note: add ?useparsoid=1 or &useparsoid=1 to any page's URL to test it with Parsoid). Please subject it to further testing. – McDutchie (talk) 14:16, 8 January 2026 (UTC)
- In fact, since Parsoid can be activated in user preferences now, I think the change is urgent, because the template is completely broken in Parsoid at the moment. The change is straightforward: it uses the well-documented {{#tag}} parser function in combination with the new format="wikitext" attribute for
<pre>...</pre>which was designed precisely to replace the includeonly/noinclude hack currently in the template. It works in my testing and I don't see any conceivable mode of failure, so I'm just going to go ahead and apply it. If anything does break or if anyone disagrees, it's easy enough to revert (but remember that reverting will re-break the template for Parsoid). – McDutchie (talk) 22:01, 8 January 2026 (UTC)- That edit caused Linter errors at Template:AUSintcore/doc and pages that transclude it. I have added a testcase using the code that is in use there. – Jonesey95 (talk) 00:53, 10 January 2026 (UTC)
- The sandbox breaks other functionality as well. See the testcases page. – Jonesey95 (talk) 00:58, 10 January 2026 (UTC)
- It looks like restoring one of the two edits has cleared the Linter errors. I have synced the sandbox with the live template. Please check the /testcases page after any further sandbox testing. – Jonesey95 (talk) 16:11, 10 January 2026 (UTC)
- @Jonesey95 I deployed a fix for the issue with Template:AUSintcore/doc in gerrit:1295505 and updated Template:Pre/sandbox with the proposed change to the template.
- Parsoid and the legacy parser now render all the test cases the same with Template:Pre/sandbox. However, the legacy parser renders one case different between Template:Pre and Template:Pre/sandbox, so it's not an exact equivalent.
- The escape mechanism used in that differing test case,
{{((}}Supranational Oceanian Bodies, was introduced in Special:Diff/713771191 but doesn't seem to be needed. It can be rewritten equivalently as in Special:PermanentLink/1357836683 with a<nowiki>. - I would like to attempt to update the template again and fix any instances that produce lint errors to use a different escape mechanism. Although, some instances are going to produce rendering differences without producing lint errors. It might be possible to set up a hidden lint to try and detect that.
- Do you have any thoughts? ABreault (WMF) (talk) 00:16, 5 June 2026 (UTC)
- The template was updated in Special:Diff/1361694400 ABreault (WMF) (talk) 14:47, 29 June 2026 (UTC)
- Nice work. It all looks good now. – Jonesey95 (talk) 15:48, 29 June 2026 (UTC)
- The template was updated in Special:Diff/1361694400 ABreault (WMF) (talk) 14:47, 29 June 2026 (UTC)
- It looks like restoring one of the two edits has cleared the Linter errors. I have synced the sandbox with the live template. Please check the /testcases page after any further sandbox testing. – Jonesey95 (talk) 16:11, 10 January 2026 (UTC)
- The sandbox breaks other functionality as well. See the testcases page. – Jonesey95 (talk) 00:58, 10 January 2026 (UTC)
- That edit caused Linter errors at Template:AUSintcore/doc and pages that transclude it. I have added a testcase using the code that is in use there. – Jonesey95 (talk) 00:53, 10 January 2026 (UTC)