Help:HTML in wikitext: Difference between revisions

Content deleted Content added
No edit summary
Cplot (talk | contribs)
restored version to WikiMedia version
Line 1:
{{H:h|editor toc}}
 
==Permitted HTML==
gt;]]
The following [[w:HTML element|HTML element]]s are currently permitted:
* [[w:HTML_element#Presentational_markup|<font>]]
{| border="0" cellpadding="5"
| valign="top"|
* [[w:HTML_element#OthersOfficial|<brb>]]
* [[w:HTML_element#ListsOfficial|<ddbig>]]
* [[w:HTML_element#Block-levelGeneral_block_elements|<blockquote>]]
* [[w:HTML_element#ListsImages_and_objects|<dlbr>]]
* [[w:HTML_element#Tables|<caption>]]
* [[w:HTML_element#InlineOfficial|<codecenter>]]
* [[w:HTML_element#General_phrase_elements|<cite>]]
* [[w:HTML_element#Computer_code_phrase_elements|<code>]]
* [[w:HTML_element#Lists|<dtdd>]]
* [[w:HTML_element#Other_containers|<div>]]
* [[w:HTML_element#InlineLists|<emdl>]]
* [[w:HTML_element#Presentational_markupLists|<bdt>]]
* [[w:HTML_element#Presentational_markupGeneral_phrase_elements|<bigem>]]
* [[w:HTML_element#Presentational_markupOfficial|<font>]]
* [[w:HTML_element#Headings|<h1>]]
| valign="top"|
Line 10 ⟶ 27:
* [[w:HTML_element#Headings|<h5>]]
* [[w:HTML_element#Headings|<h6>]]
* [[w:HTML_element#Block-levelGeneral_block_elements|<hr>]]
* [[w:HTML_element#Presentational_markupOfficial|<i>]]
* [[w:HTML_element#Lists|<li>]]
* [[w:HTML_element#ListsOrdered list|<ol>]]
* [[w:HTML_element#Block-levelGeneral_block_elements|<p>]]
* [[w:HTML_element#Block-levelOther_containers|<pre>]]
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <rb>]
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <rp>]
Line 21 ⟶ 38:
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ <ruby>]
| valign="top"|
* [[w:HTML_element#Presentational_markupOfficial|<s>]]
* [[w:HTML_element#Presentational_markupOfficial|<small>]]
* [[w:HTML_element#Presentational_markupOfficial|<strike>]]
* [[w:HTML_element#InlineGeneral_phrase_elements|<strong>]]
* [[w:HTML_element#InlineSpecial_inline_elements|<sub>]]
* [[w:HTML_element#InlineSpecial_inline_elements|<sup>]]
* [[w:HTML_element#Tables|<table>]]
* [[w:HTML_element#Tables|<td>]]
Line 33 ⟶ 50:
* [[w:HTML_element#Presentational_markup|<tt>]]
* [[w:HTML_element#Presentational_markup|<u>]]
* [[w:HTML_element#ListsOrdered list|<ul>]]
* [[w:HTML_element#InlineComputer_code_phrase_elements|<var>]]
* [[w:HTML_element#OthersHTML_Comment|<!-- ... -->]]
|}
 
==Permitted HTML==
 
The following [[w:HTML element|HTML element]]s are currently permitted:
The following excerpt from [http://cvssvn.sourceforgewikimedia.netorg/viewcvs.pyviewvc/mediawiki/tags/wikipediaREL1_6_6/phpwikiphase3/newcodebaseincludes/OutputPageSanitizer.php OutputPageSanitizer.php] additionally shows which attributes are allowed.
{| border="0" cellpadding="5"
| valign="top"|
* [[w:HTML_element#Presentational_markup|<b>]]
* [[w:HTML_element#Presentational_markup|<big>]]
* [[w:HTML_element#Block-level|<blockquote>]]
* [[w:HTML_element#Others|<br>]]
* [[w:HTML_element#Tables|<caption>]]
* <center>
* <cite>
* [[w:HTML_element#Inline|<code>]]
* [[w:HTML_element#Lists|<dd>]]
* [[w:HTML_element#Other_containers|<div>]]
* [[w:HTML_element#Lists|<dl>]]
* [[w:HTML_element#Lists|<dt>]]
* [[w:HTML_element#Inline|<em&
The following excerpt from [http://cvs.sourceforge.net/viewcvs.py/wikipedia/phpwiki/newcodebase/OutputPage.php OutputPage.php] additionally shows which attributes are allowed.
 
:'''Update:''' In 1.4rc1, the removeHTMLtags function is located in Parser.php.
Line 62 ⟶ 63:
 
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.
<br clear="all"><!-- stop floating navbox before pre -->
 
<pre>
/* 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 */
);
);
</pre>
 
E.g.For example, the anchor element "a" is not allowed, andso the wikitext
 
: <code><nowiki><a href="<nowiki>http://meta.wikimedia.org/wiki/Main_Page</nowiki>">Main Page</a></nowiki></code>
 
is treated like the wikitext
produces the HTML code
 
: <code><nowiki>&amp;lt;a href="<nowiki>http://meta.wikimedia.org/wiki/Main_Page</nowiki>"&amp;gt;Main Page&amp;lt;/a&amp;gt;</nowiki></code>
 
and is therefore displayed as
which renders as the wikitext, not working as a link.
 
: <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 (&lt;a&gt;) the wiki markup for external reference is recommended (enclosed in square brackets with the URL separated from the contents by a single space):
 
: <code><nowiki>[http://meta.wikimedia.org/wiki/Main_Page Main Page]</nowiki></code>
 
displays as:
 
: [http://meta.wikimedia.org/wiki/Main_Page Main Page]
 
==Span==
Line 152 ⟶ 163:
 
<pre>
a <font stylecolor="color: red">red</font> word.
</pre>
 
or
 
<pre>
a <font color=red>red</font> word.
</pre>
 
giving
 
a <font stylecolor="color: red">red</font> word
 
It's pointless to combine the legacy tag <tt>&lt;font&gt;</tt>
a <font color=red>red</font> word
with inline CSS; legacy browsers would ignore the CSS, while
modern browsers support <tt>&lt;span&gt;</tt> (see above).
 
==Div==
Line 182 ⟶ 189:
 
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. &lt;span id=abc&gt; produces the HTML &amp;lt;span id=abc&amp;gt; rendered by the browser as &lt;span id=abc&gt;.
 
==Style pages==
CSS and JS pages (see [[Help:User style]]) are not interpreted as wikitext, and therefore can have arbitrary HTML.
 
==External links==