In MediaWiki:Common.css I gave these essential directives:

code {
    display: block;

then I created an article with this content:


After saving it looks like this:

enter image description here

Although I used only one <code> tag the DOM markup includes four different <code> blocks while the most inner part also gets a <pre> tag I never created.
This all seems to come not from HTML or CSS, but from MediaWiki itself.

How could I prevent MediaWiki from altering my code this way?


Leading whitespace creates a <pre> block in wikitext. Try using the SyntaxHighlight extension instead.

  • 1
    Indent the whole code block, that will result in a single <pre> block (as opposed to the several <pre> and <p> blocks you have now). – Tgr Jun 22 '19 at 20:37
  • You can indent with space. – Tgr Jun 22 '19 at 21:06
  • Indenting the whole code block with space is something I prefer not to do. Is there a way to indent in MediaWiki with an indentation character directly from keyboard (hitting TAB doesn't help as it would in VSCODE)? – JohnDoea Jun 23 '19 at 5:13
  • What the tab key does depends on your editor, not the markup language (CodeEditor can indent via tab key for example, it's not really meant for editing wikitext though). And a raw tab character wouldn't work anyway, preformatted text needs to be indented with spaces. – Tgr Jun 23 '19 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.