Difference between revisions of "Help:HTML"

MyWikiBiz, Author Your Legacy — Saturday November 16, 2024
Jump to navigationJump to search
(HTML help page)
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
  
 
==Permitted HTML==
 
==Permitted HTML==
The following [[w:HTML element|HTML element]]s are currently permitted:
+
The following [[HTML element|HTML element]]s are currently permitted:
 
          
 
          
 
{| border="0" cellpadding="5"
 
{| border="0" cellpadding="5"
 
| valign="top"|
 
| valign="top"|
* [[w:HTML_element#Official|<b>]]
+
* [[HTML_element#Official|<b>]]
* [[w:HTML_element#Official|<big>]]
+
* [[HTML_element#Official|<big>]]
* [[w:HTML_element#General_block_elements|<blockquote>]]
+
* [[HTML_element#General_block_elements|<blockquote>]]
* [[w:HTML_element#Images_and_objects|<br>]]
+
* [[HTML_element#Images_and_objects|<br>]]
* [[w:HTML_element#Tables|<caption>]]
+
* [[HTML_element#Tables|<caption>]]
* [[w:HTML_element#Official|<center>]]
+
* [[HTML_element#Official|<center>]]
* [[w:HTML_element#General_phrase_elements|<cite>]]
+
* [[HTML_element#General_phrase_elements|<cite>]]
* [[w:HTML_element#Computer_code_phrase_elements|<code>]]
+
* [[HTML_element#Computer_code_phrase_elements|<code>]]
* [[w:HTML_element#Lists|<dd>]]
+
* [[HTML_element#Lists|<dd>]]
* [[w:HTML_element#Other_containers|<div>]]
+
* [[HTML_element#Other_containers|<div>]]
* [[w:HTML_element#Lists|<dl>]]
+
* [[HTML_element#Lists|<dl>]]
* [[w:HTML_element#Lists|<dt>]]
+
* [[HTML_element#Lists|<dt>]]
* [[w:HTML_element#General_phrase_elements|<em>]]
+
* [[HTML_element#General_phrase_elements|<em>]]
* [[w:HTML_element#Official|<font>]]
+
* [[HTML_element#Official|<font>]]
* [[w:HTML_element#Headings|<h1>]]
+
* [[HTML_element#Headings|<h1>]]
 
| valign="top"|
 
| valign="top"|
* [[w:HTML_element#Headings|<h2>]]
+
* [[HTML_element#Headings|<h2>]]
* [[w:HTML_element#Headings|<h3>]]
+
* [[HTML_element#Headings|<h3>]]
* [[w:HTML_element#Headings|<h4>]]
+
* [[HTML_element#Headings|<h4>]]
* [[w:HTML_element#Headings|<h5>]]
+
* [[HTML_element#Headings|<h5>]]
* [[w:HTML_element#Headings|<h6>]]
+
* [[HTML_element#Headings|<h6>]]
* [[w:HTML_element#General_block_elements|<hr>]]
+
* [[HTML_element#General_block_elements|<hr>]]
* [[w:HTML_element#Official|<i>]]
+
* [[HTML_element#Official|<i>]]
* [[w:HTML_element#Lists|<li>]]
+
* [[HTML_element#Lists|<li>]]
* [[w:Ordered list|<ol>]]
+
* [[Ordered list|<ol>]]
* [[w:HTML_element#General_block_elements|<p>]]
+
* [[HTML_element#General_block_elements|<p>]]
* [[w:HTML_element#Other_containers|<pre>]]
+
* [[HTML_element#Other_containers|<pre>]]
 
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <rb>]
 
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <rb>]
 
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <rp>]
 
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <rp>]
Line 40: Line 40:
 
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <ruby>]
 
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <ruby>]
 
| valign="top"|
 
| valign="top"|
* [[w:HTML_element#Official|<s>]]
+
* [[HTML_element#Official|<s>]]
* [[w:HTML_element#Official|<small>]]
+
* [[HTML_element#Official|<small>]]
* [[w:HTML_element#Official|<strike>]]
+
* [[HTML_element#Official|<strike>]]
* [[w:HTML_element#General_phrase_elements|<strong>]]
+
* [[HTML_element#General_phrase_elements|<strong>]]
* [[w:HTML_element#Special_inline_elements|<sub>]]
+
* [[HTML_element#Special_inline_elements|<sub>]]
* [[w:HTML_element#Special_inline_elements|<sup>]]
+
* [[HTML_element#Special_inline_elements|<sup>]]
* [[w:HTML_element#Tables|<table>]]
+
* [[HTML_element#Tables|<table>]]
* [[w:HTML_element#Tables|<td>]]
+
* [[HTML_element#Tables|<td>]]
* [[w:HTML_element#Tables|<th>]]
+
* [[HTML_element#Tables|<th>]]
* [[w:HTML_element#Tables|<tr>]]
+
* [[HTML_element#Tables|<tr>]]
* [[w:HTML_element#Presentational_markup|<tt>]]
+
* [[HTML_element#Presentational_markup|<tt>]]
* [[w:HTML_element#Presentational_markup|<u>]]
+
* [[HTML_element#Presentational_markup|<u>]]
* [[w:Ordered list|<ul>]]
+
* [[Ordered list|<ul>]]
* [[w:HTML_element#Computer_code_phrase_elements|<var>]]
+
* [[HTML_element#Computer_code_phrase_elements|<var>]]
* [[w:HTML_element#HTML_Comment|<!-- ... -->]]
+
* [[HTML_element#HTML_Comment|<!-- ... -->]]
 
|}
 
|}
 
 
The following excerpt from [http://svn.wikimedia.org/viewvc/mediawiki/tags/REL1_6_6/phase3/includes/Sanitizer.php Sanitizer.php] additionally shows which attributes are allowed.
 
 
:'''Update:''' In 1.4rc1, the removeHTMLtags function is located in Parser.php.
 
 
:'''Update:''' In 1.5, the removeHTMLtags function is now located in Sanitizer.php.
 
  
 
For many HTML elements, more convenient wikitext code is available, see [[Help:Editing]]. On the other hand, HTML tags allow an id that can be referenced in one's [[Help:User style|user style]] css, and allows the tag to be used as link target.
 
For many HTML elements, more convenient wikitext code is available, see [[Help:Editing]]. On the other hand, HTML tags allow an id that can be referenced in one's [[Help:User style|user style]] css, and allows the tag to be used as link target.
Line 160: Line 153:
 
==Font==
 
==Font==
  
''Note: This element is [[w:Deprecation|deprecate]]d (should not be used) in favor of [[#Span|<nowiki><span></nowiki>]].''
+
''Note: This element is [[Deprecation|deprecate]]d (should not be used) in favor of [[#Span|<nowiki><span></nowiki>]].''
  
 
For some attributes, like color, one can also use
 
For some attributes, like color, one can also use

Latest revision as of 16:21, 19 February 2007

Help:Contents

This page gives you information about using permitted HTML code within MediaWiki.

Permitted HTML

The following HTML elements are currently permitted:

For many HTML elements, more convenient wikitext code is available, see Help:Editing. On the other hand, HTML tags allow an id that can be referenced in one's user style css, and allows the tag to be used as link target.

	/* private */ function removeHTMLtags( $text )
	{
		wfProfileIn( "OutputPage::removeHTMLtags" );
		$htmlpairs = array( # Tags that must be closed
			"b", "i", "u", "font", "big", "small", "sub", "sup", "h1",
			"h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s", "span",
			"strike", "strong", "tt", "var", "div", "center",
			"blockquote", "ol", "ul", "dl", "table", "caption", "pre",
			"ruby", "rt" , "rb" , "rp"
		);
		$htmlsingle = array(
			"br", "p", "hr", "li", "dt", "dd"
		);
		$htmlnest = array( # Tags that can be nested--??
			"table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
			"dl", "font", "big", "small", "sub", "sup"
		);
		$tabletags = array( # Can only appear inside table
			"td", "th", "tr"
		);

		$htmlsingle = array_merge( $tabletags, $htmlsingle );
		$htmlelements = array_merge( $htmlsingle, $htmlpairs );

		$htmlattrs = array( # Allowed attributes--no scripting, etc.
			"title", "align", "lang", "dir", "width", "height",
			"bgcolor", "clear", /* BR */ "noshade", /* HR */
			"cite", /* BLOCKQUOTE, Q */ "size", "face", "color",
			/* FONT */ "type", "start", "value", "compact",
			/* For various lists, mostly deprecated but safe */
			"summary", "width", "border", "frame", "rules",
			"cellspacing", "cellpadding", "valign", "char",
			"charoff", "colgroup", "col", "span", "abbr", "axis",
			"headers", "scope", "rowspan", "colspan", /* Tables */
			"id", "class", "name", "style" /* For CSS */
		);

For example, the anchor element "a" is not allowed, so the wikitext

<a href="http://meta.wikimedia.org/wiki/Main_Page">Main Page</a>

is treated like the wikitext

&lt;a href="http://meta.wikimedia.org/wiki/Main_Page"&gt;Main Page&lt;/a&gt;

and is therefore displayed as

<a href="http://meta.wikimedia.org/wiki/Main_Page">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 recommended (enclosed in square brackets with the URL separated from the contents by a single space):

[http://meta.wikimedia.org/wiki/Main_Page Main Page]

displays as:

Main Page

Span

<span>, a generic inline text container, is now allowed on default MediaWiki installations (as of version 1.5). Span can be ID'd, classed, or styled:

This is <span style="color:red">red</span> text.

This is <span id="randomfooid">identified</span> text.

This is <span class="importantmessage">classed</span> text.

produces:

This is red text.

This is identified text.

This is classed text.

IDs and classes are used in conjunction with stylesheets to give a piece of text a descriptive class (or unique identifier) and to refer to that in a stylesheet.

Note that in most cases, one can use a more descriptive tag, for instance, <strong> (which can be classed, identified, and styled, as well) to indicate an important piece of text, or <em> (subject to the same things as strong) to indicate an emphasized piece of text. For instance, the above might be better reformulated as

This is <em style="color:red;font-style:normal">red</em> text.

This is red 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 emphasized text.

Using Template:Timc, "a height of {{h:title|6.1 km|20000 ft}} above sea level" gives "a height of Template:H:title above sea level" (note the hover box over "20000 ft").

Font

Note: This element is deprecated (should not be used) in favor of <span>.

For some attributes, like color, one can also use

a <font color="red">red</font> word.

giving

a red word

It's pointless to combine the legacy tag <font> with inline CSS; legacy browsers would ignore the CSS, while modern browsers support <span> (see above).

Div

E.g. to assign the class "red" to a text one can put

<div class="red">example text</div>

which gives

example text

which is in red if the css line

.red {color:red}

is applicable.

This is suitable if the color is specifically intended to be red; if it is just for emphasis a more general term for the class would be more appropriate, because css allows the user to choose another method of emphasis (another color, bold, enlarged, etc.).

Note that many readers will not have their own css with such lines as ".red {color:red}", so one cannot refer to "the red text above", etc.

MediaWiki namespace

In some pages in the MediaWiki namespace HTML does not work, and e.g. <span id=abc> produces the HTML &lt;span id=abc&gt; rendered by the browser as <span id=abc>.

Style pages

CSS and JS pages (see Help:User style) are not interpreted as wikitext, and therefore can have arbitrary HTML.