user5268559
user5268559

Reputation:

MediaWiki: How do you put a period after the heading number?

I've been unable to find an answer to the following online.

I've enabled auto-numbered headings in MediaWiki by adding the following to LocalSettings.php:

$wgDefaultUserOptions['numberheadings'] = 1;

However, I'd like there to be a period after the heading number, to distinguish it from the heading.

That is, I'd like:

2. This is a heading

instead of:

2 This is a heading

However, I'd prefer the number not to have a period after it in the case of sub-headings.

That is, I'd like:

2.1 This is a heading

not:

2.1. This is a heading

Does anyone know how to do this?

Thanks in advance for any help

Upvotes: 2

Views: 607

Answers (2)

Seb35
Seb35

Reputation: 493

A simple way to achieve this is by editing the wiki page "MediaWiki:Common.css" (connected as admin) and adding the following CSS code:

.mw-headline-number::after {
    content: ".";
}

If you want only some header levels, you can use the following: (here for level 2 headers (HTML <h2>), which is traditionnally the first level in wikitext since the title is a level 1 header (HTML <h1>))

h2 .mw-headline-number::after {
    content: ".";
}

This will appear only for users who activated their preference "Auto-number headings" but you have activated it by default, so it will work for anybody who keep the preference activated.

Once the change is done, you will have to refresh your browser with F5 or Ctrl-R.

Upvotes: 2

leo
leo

Reputation: 8542

The space is hardcoded, see Parser.php, so you will have to modify it after it is created. Your best shot is probably to use theParserSectionCreate hook, or possible ParserBeforeTidy

If you want to do it frontend: Loop through all headings with the class mw-headline-number, and apply your logic there.

Also note that these changes will only affect users that have enabled the numberheadings features in their settings, or registered after you changed the default setting.

Edit: You might want to check what language your user is viewing your wiki in first, as a trailing dot might not be used with all languages and numeral systems. See this list for some variants (note how the CJK systems use an east asian comma, 壹、, and how the ge'ez (Ethiopic) example uses a space, )

Upvotes: 0

Related Questions