Template talk:Code
This is the talk page for discussing improvements to the Code template. |
|
Archives: 1Auto-archiving period: 6 months |
Template:Code is permanently protected from editing because it is a heavily used or highly visible template. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit template-protected}} to notify an administrator or template editor to make the requested edit. Usually, any contributor may edit the template's documentation to add usage notes or categories.
Any contributor may edit the template's sandbox. Functionality of the template can be checked using test cases. |
Text and/or other creative content from this version of Template:Code was copied or moved into incubator:Template:Wp/nod/code with this edit. The former page's history now serves to provide attribution for that content in the latter page, and it must not be deleted as long as the latter page exists. |
|
This page has archives. Sections older than 180 days may be automatically archived by Lowercase sigmabot III. |
Template-protected edit request on 4 March 2024
This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
Update template to match this edit I made to Template:Code/Sandbox. The specific change to line 1, and is as follows, compared to the current version of Template:Code (disregard the mangled noinclude in the left/old one, it's an issue with Template:TextDiff, new version is on the right anyway):
− | {{#tag: | + | {{#tag:{{#ifeq:{{{lang|{{{2|text}}}}}}|text|code|syntaxhighlight}}|{{{code|{{{1}}}}}}|lang={{{lang|{{{2|text}}}}}}|class={{{class|}}}|id={{{id|}}}|style={{{style|}}}|inline=1}}<noinclude> |
The change has been tested in Template:Code/testcases, and produces the expected output.
Purpose of change: makes this template use #tag:code instead of #tag:syntaxhighlight when lang/param 2 is either undefined or has been defined as 'text', but still uses #tag:syntaxhighlight in all other cases. #tag:syntaxhighlight is a WP:EXPENSIVE parser function, and current template behaviour always uses #tag:syntaxhighlight, even when unnecessary (as 'lang=text' has no syntax highlighting) - but, this change ensures that the non-expensive #tag:code will be used instead when syntax highlighting is not necessary. 🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talk・edits) 20:01, 4 March 2024 (UTC)
- It needs some additional work first. There are differences in markup behavior:
plain ''ABC'' <b>bold</b> {{mdash}} {{PAGENAME}} {{code}} plain
''ABC''
<b>bold</b>
—
Code
{{code/sandbox}} plain
''ABC''
<b>bold</b>
—
Code
<syntaxhighlight inline> plain
''ABC''
<b>bold</b>
{{mdash}}
{{PAGENAME}}
<code><nowiki> plain
''ABC''
<b>bold</b>
{{mdash}}
{{PAGENAME}}
<code> plain
ABC
bold
—
Code
- See this template's documentation about how syntaxhighlight works like code plus nowiki (except that with this template inner templates/magic words expand first). SilverLocust 💬 08:54, 5 March 2024 (UTC)
{{code}} plain
''ABC''
<b>bold</b>
—
Code
{{code/sandbox2}} plain
ABC
bold
—
Code
- @HotMess: I have made a new version in Template:Code/sandbox2 that may be correct — but it could use more checking. [Edit: Now that my changes have been moved to /sandbox, I have put HotMess's original version in /sandbox2.] SilverLocust 💬 10:16, 5 March 2024 (UTC)
- @SilverLocust I've incorporated those changes into Template:Code/sandbox, and updated Template:Code/testcases with those additional checks (and a couple extra checks) - and it appears to be functioning correctly now. 🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talk・edits) 13:13, 5 March 2024 (UTC)
- @HotMess: I have made a new version in Template:Code/sandbox2 that may be correct — but it could use more checking. [Edit: Now that my changes have been moved to /sandbox, I have put HotMess's original version in /sandbox2.] SilverLocust 💬 10:16, 5 March 2024 (UTC)
- @HotMess: There is also a difference for how they treat html codes.
– –
lang=something{{code}} –
–
{{code/sandbox}} –
–
{{code/sandbox2}}
(your original request)–
–
<syntaxhighlight inline> –
–
<code><nowiki> –
–
<code> –
–
- For context about the need for the change, is there a page/situation where you encountered an issue because of the current template? (It is, of course, possible to have an issue by just using the template 501 times, or on a page with 500 other expensive calls, but I want to know how much this has been an issue.) SilverLocust 💬 23:43, 5 March 2024 (UTC)
- Well, the context behind this change was seeing Comparison of programming languages (basic instructions) in Category:Pages with too many expensive parser function calls (as this template is used 663 times within that page). I noticed that the current behaviour of this template upon reaching the WP:EXPENSIVE limit is to just present the code within regular
<code>...</code>
blocks, so, y'know, figured that it would make sense to default to<code>...</code>
unless the expensive syntax-highlighting functionality is desired. Genuinely have no idea how to replicate the 'not needing to escape & within HTML character entities' functionality of mw:SyntaxHighlight though. 🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talk・edits) 12:35, 6 March 2024 (UTC)- I have substituted most all of those with {{subst:codenowiki}}. That should keep that page under 500 hopefully forever. (I also then removed extra nowiki tags, though there may be some nowiki over- or under-inclusion errors left on the page that I haven't caught.) SilverLocust 💬 14:04, 6 March 2024 (UTC)
- Well, the context behind this change was seeing Comparison of programming languages (basic instructions) in Category:Pages with too many expensive parser function calls (as this template is used 663 times within that page). I noticed that the current behaviour of this template upon reaching the WP:EXPENSIVE limit is to just present the code within regular
- For context about the need for the change, is there a page/situation where you encountered an issue because of the current template? (It is, of course, possible to have an issue by just using the template 501 times, or on a page with 500 other expensive calls, but I want to know how much this has been an issue.) SilverLocust 💬 23:43, 5 March 2024 (UTC)