Board Thread:Support Requests - Getting Technical/@comment-26231129-20160320122853/@comment-11733175-20160320211325

In the context of MediaWiki, comments such as these are more used as a workaround than for a specific purpose. I've never really understood the use of comments in true HTML, I think they belong elsewhere, but for the purposes of MediaWiki and templates they have some use, even if it is diminishing with the rise of visual editors which don't implement them.

Before understanding how comments work in the context of templates, you first need to understand the difference between displaying an element inline and block - inline takes up the minimum width it can, block takes up as much space as it can:

Inline Block

Inline elements are typically span tags on MediaWiki, but also include b, strong, and a few others. Block elements are normally div tags, but there's a few others you might see around in very unusual circumstances (I've used them once in 3-4 years).

Hello
 * 1) example 1


 * 1) example 2

Hello

Using the above as a simple example, when your wikitext is converted to HTML, first of all it looks at comments and strips them away, replacing them with nothing.

Hello
 * 1) example 1


 * 1) example 2

Hello

Next, it decides whether the element is inline or block (there are others but it gets more complicated beyond there). As we know, block elements take up as much space as they want, so the parser allows them to span multiple lines. Inline elements are the opposite however, so they're only allowed to take up one line. Along side this, any unclosed tags are closed to prevent the content we write causing any issues outside the content area such as causing the skin to behave in new and interesting ways. Any tags that don't close anything are then stripped away.

After all that is done, you end up with something like: Hello
 * 1) example 1

Hello
 * 1) example 2

This is where the whitespace is introduced.

Next, the parser comes along and wraps every new line in p tags, representing paragraphs, unless it's a block element.

Hello
 * 1) example 1

Hello
 * 1) example 2

Finally, to go back to how this causes issues in templates, every time a new line is added content can end up being added into a p tag. P tags will take up a newline and add the whitespace we see, and cause so many headaches all over Wikia. To avoid these headaches, we use comments :)