Content deleted Content added
Richardguk (talk | contribs) |
|||
Line 1:
{{shortcut|H:HTML}}
==Permitted HTML==
The following [[HTML element]]s are currently permitted:
{{Colbegin|3}}
* [[HTML element#General|<abbr>]]
* [[HTML element#Presentation|<b>]]
* [[HTML element#Presentation|<big>]]
* [[HTML element#Other Block Elements|<blockquote>]]
* [[HTML element#Other Inline Elements|<br>]]
* [[HTML element#Tables|<caption>]]
* [[HTML element#Other Block Elements|<center>]]
* [[HTML element#Other Inline Elements|<cite>]]
* [[HTML element#Computer Phrase Elements|<code>]]
* [[HTML element#Lists|<dd>]]
* [[HTML element#Other Block Elements|<del>]]
* [[HTML element#Other Block Elements|<div>]]
* [[HTML element#Lists|<dl>]]
* [[HTML element#Lists|<dt>]]
* [[HTML element#General|<em>]]
* [[HTML element#Presentation|<font>]]
* [[HTML element#Basic Text|<h1>]]
* [[HTML element#Basic Text|<h2>]]
* [[HTML element#Basic Text|<h3>]]
* [[HTML element#Basic Text|<h4>]]
* [[HTML element#Basic Text|<h5>]]
* [[HTML element#Basic Text|<h6>]]
* [[HTML element#Other Block Elements|<hr>]]
* [[HTML element#Presentation|<i>]]
* [[HTML element#Other Block Elements|<ins>]]
* [[HTML element#Lists|<li>]]
* [[HTML element#Lists|<ol>]]
* [[HTML element#Basic Text|<p>]]
* [[HTML element#Other Block Elements|<pre>]]
* [[Ruby character#Ruby markup|<rb>]]
* [[Ruby character#Ruby markup|<rp>]]
* [[Ruby character#Ruby markup|<rt>]]
* [[Ruby character#Ruby markup|<ruby>]]
* [[HTML element#Presentation|<s>]]
* [[HTML element#Presentation|<small>]]
* [[HTML element#Span|<span>]]
* [[HTML element#Presentation|<strike>]]
* [[HTML element#General|<strong>]]
* [[HTML element#Other Inline Elements|<sub>]]
* [[HTML element#Other Inline Elements|<sup>]]
* [[HTML element#Tables|<table>]]
* [[HTML element#Tables|<td>]]
* [[HTML element#Tables|<th>]]
* [[HTML element#Tables|<tr>]]
* [[HTML element#Presentation|<tt>]]
* [[HTML element#Presentation|<u>]]
* [[HTML element#Lists|<ul>]]
* [[HTML element#Computer Phrase Elements|<var>]]
* [[HTML element#HTML Comment|<!-- ... -->]]
{{Colend}}
For many HTML elements, more convenient wikitext code is available, see [[Help:Wiki markup]]. On the other hand, HTML tags allow an <code>id</code> attribute that can be referenced in one's [[Help:User style|user style]] CSS, and allows the element to be used as link target.
However, the anchor element <code>a</code> is not allowed, so the wikitext
<code><nowiki><a href="http://meta.wikimedia.org/">Main Page</a></nowiki></code>
is treated like the wikitext
<code><nowiki>&lt;a href="http://meta.wikimedia.org/"&gt;Main Page&lt;/a&gt;</nowiki></code>
and is therefore displayed as
{{Quote|1=<a href="http://meta.wikimedia.org/">Main Page</a>}}
which is unlikely to be what the editor intended. Instead of using the anchor element (<a>) the wiki markup for external reference is required (enclosed in square brackets with the URL separated from the contents by a single space):
<code><nowiki>[http://meta.wikimedia.org/ Main Page]</nowiki></code>
displays as:
{{Quote|[http://meta.wikimedia.org/ Main Page]}}
The following excerpt from [http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Sanitizer.php?view=markup Sanitizer.php] additionally shows which attributes are allowed.
<source lang="php">
$htmlpairsStatic = array( # Tags that must be closed
'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1',
'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's',
'strike', 'strong', 'tt', 'var', 'div', 'center',
'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre',
'ruby', 'rt' , 'rb' , 'rp', 'p', 'span', 'u', 'abbr'
);
$htmlsingle = array(
'br', 'hr', 'li', 'dt', 'dd'
);
$htmlsingleonly = array( # Elements that cannot have close tags
'br', 'hr'
);
$htmlnest = array( # Tags that can be nested--??
'table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul',
'dl', 'font', 'big', 'small', 'sub', 'sup', 'span'
);
$tabletags = array( # Can only appear inside table, we will close them
'td', 'th', 'tr',
);
$htmllist = array( # Tags used by list
'ul','ol',
);
$listtags = array( # Tags that can appear in a list
'li',
);
</source>
== Tags ==
{{mlw|HTML element|Span|<code>'''<span>'''</code>}} is a generic inline text container.
<code>'''<font>'''</code> is a similar tag which is [[deprecation|deprecate]]d (should not be used) in favor of <nowiki><span></nowiki>.''
For example
<source lang=html4strict>
a <font color="red">red</font> word.
</source>
produces the same result as
<source lang=html4strict>
a <span style="color:red">red</span> word.
</source>
See also {{tim|font size demo}} and [[m:Help:Text color]].
It's pointless to combine the legacy tag <tt><font></tt>
with inline CSS; legacy browsers would ignore the CSS, while
modern browsers support <tt><span></tt> (see above).
Note that in most cases, one can use a more descriptive tag, for instance, <strong><nowiki><strong></nowiki></strong> to indicate an important piece of text, or <em><nowiki><em></nowiki></em> (subject to the same things as strong) to indicate an emphasized piece of text.
This not only draws the user's attention to the text, but can also alert those who are using nonvisual browsers or have sight impairments, etc. to the fact that that is <em>emphasized text</em>.
===Using <nowiki><span></nowiki> as a link target===
The standard way of providing a named anchor as an invisible target (i.e. <code><a name="Foo"></code>) doesn't work (since all <code><a></code> tags are converted), and [http://www.w3.org/TR/html401/struct/links.html an alternative suggested by the W3C], <code><nowiki><hN id="Foo"></hN></nowiki></code>, produces an "[Edit]" link.
However, <code><nowiki><span id="Foo"></nowiki></code> does produce a target than can be the destination of a link. Note that it doesn't work everywhere; for instance, in a table, it has to be inside a cell before some browsers will jump to it properly.
===<nowiki><div></nowiki>===
<code>'''<div>'''</code> is a generic block container. Rules:
* <nowiki><div></nowiki> should be followed by a newline
* <nowiki></div></nowiki> should be preceded by a newline
*<nowiki></div></nowiki> followed by text on the same line, two newlines and text before <nowiki><div></nowiki> on the same line should be avoided (because the two newlines only produce a space)
===HTML comment===
Using {{tim|t}}:
*{{xpd|t}}
*"<code><nowiki>{{subst:xpd|t}}</nowiki>"</code> gives "<!--t-->start-pqr-end", producing HTML code without the comment.
The "Remove comments" option of [[mw:Extension:ExpandTemplates|ExpandTemplates]] selects whether comments are removed, not just in the final result but throughout the expansion process. This affects the result of parser functions: a comment in the expression of #expr or in the condition of #ifexpr gives an error message unless "Remove comments" is on, and comments affect #if and #ifeq.
Example:
Wikitext:
----
<pre>
{{#expr:<!--p-->3}}
{{#ifeq:<!--p-->3|3|1|0}}
{{#if:<!--p-->|1|0}}
</pre>
----
Result of normal expansion, and of ExpandTemplates with "Remove comments" on:
----
{{#expr:<!--p-->3}}
{{#ifeq:<!--p-->3|3|1|0}}
{{#if:<!--p-->|1|0}}
----
Result of full substitution, and of ExpandTemplates with "Remove comments" off:
----
<strong class="error">Expression error: Unrecognised punctuation character ""</strong>
0
1
----
Therefore it is typically better to avoid comments in these places, and to put the comment before or after the parser function.
In the case of nested parser functions, to avoid having to put the comments outside the whole, an alternative is <nowiki>{{void|</nowiki>''comment''}}. In the case of substitution of the parser function, "void" has to be substituted too, e.g. in a template allowing multi-level substitution we can put <nowiki>{{{{{subst1|}}}#expr:3*{{{1}}} {{{{{subst1|}}}void|</nowiki> multiply by 3 }}}}.
Another alternative is making the comment the name of a parameter (in the likely case that it is unused), with the empty string as default, e.g. <nowiki>{{{ multiply by 3 |}}} or, to recognize the intention, use pseudo comment tags: {{{<!- multiply by 3 ->|}}}, or real ones, if the empty string is not used as parameter: {{{<!-- multiply by 3 -->|}}}</nowiki>.
See also {{tim|t comment}}.
== Attributes ==
|