Page MenuHomePhabricator

<code> tags should treat content inside them as <nowiki>
Closed, DeclinedPublicFeature

Description

Why

  • editors typing program code into wikicode pages often want to escape that code, since typing HTML code is common, and the wikipage parser renders a lot of HTML elements
  • the current way of escaping, typing <code><nowiki></nowiki></code> or <syntaxhighlight inline></syntaxhighlight>, is both common and laborious (lots of keystrokes)

What

  • change the parser to treat <code></code> tags as automatically nowiki on the inside

Notes

Event Timeline

This would break a lot of things. It is not uncommon to put a template documentation inside <code> tags.
Example on enwiki: more than 700 000 use of <code>{{....

Yeah this would have been a good idea fifteen years ago when <code> was introduced, but I don't think it's plausible today.

Something like T286569: Reserve ``` ``` syntax to indicate 'code' blocks in wikitext markup is more doable (once parser unification is done and introducing new wikitext syntax doesn't require trying to keep two parsers with completely different internal mechanics in sync).

You can assign backtick as a hotkey for <code> in VE, and VE will take responsibility for inserting the correct <nowiki> tags, which solves 99% of this issue for me.

See https://meta.wikimedia.org/wiki/User:DLynch_(WMF)/VisualEditorCodeBacktick.js which can be installed globally by putting

mw.loader.load( 'https://meta.wikimedia.org/w/index.php?title=User:DLynch_(WMF)/VisualEditorCodeBacktick.js&action=raw&ctype=text/javascript' );

in your User:xxxx/global.js on meta.wikimedia.org.

See also https://en.wikipedia.org/wiki/User:Cscott/Ideas/A_Dozen_Visions_for_Wikitext/Backticks and T217944: Support backticks (`) for code samples (as in Markdown).

(It’s not quite backtick-as-hotkey — we did that once in the past and discovered that it caused horrible issues with adding accents via IMEs in some languages (I want to say Catalan, but might be misremembering). Rather, it adds a Slack-style behavior where if you wrap text in backticks as you’re writing it’ll convert it into a code annotation once you write the second backtick. It’s also a script I threw out in about 20 minutes, so I don’t promise it’s perfect. 😅)