EnableHTML
<< Index Template | Cookbook-V1 | Foot Notes >>
Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.
Question
Is it possible to include HTML markup in wiki pages?
Answer
By default (and by design), PmWiki does not support the use of HTML elements in the editable markup for wiki pages. There are a number of reasons for this described in the PmWikiPhilosophy and PmWiki.Audiences. Basically, Pm feels that enabling HTML markup within wiki pages in a collaborative environment has the effect of excluding some potential authors from being able to edit pages, as well as posing a number of display and security issues. Indeed, for complex markup sequences it's often better to design a CustomMarkup to provide the desired functionality, as this allows things to be easily customized and changed in the future without having to re-edit a lot of pages.
That said, as of PmWiki 0.6.9 it's possible to add a local customization to enable selected HTML elements in the page markup. The code looks something like:
$AllowedHTML="b|i|u|sup|sub|div|a|img"; $BrowseDirectives["/(<\\/?($AllowedHTML)\\b[^>]*>)/e"] = "Keep(str_replace('\\\"','\"','$1'));";
The first line identifies the set of HTML elements the WikiAdministrator is willing to allow in the markup. The second line preserves the open and closing form of those elements, along with any attributes/text that occur inside the angle brackets.
Note that this does not provide any validation of proper attributes for each element, nor does it provide any assurance that tags will be properly nested--i.e., an author placing these tags within a page needs to know something of what he or she is doing. Still, for sites where it's okay to expect some level of HTML sophistication from page authors, this is a useful workaround.
Also note that enabling authors to arbitrarily add elements such as <table>
, <script>
, and <meta>
may have unwanted side-effects and even pose threats to browser and user security. See http://www.cert.org/advisories/CA-2000-02.html for additional information on the types of risks this may pose.
See Also
- PmWiki.PmWikiPhilosophy
- PmWiki.Audiences
- http://www.cert.org/advisories/CA-2000-02.html
Contributors
- Pm, 15-Mar-2004, original code
Sandbox
Use the space below to experiment with embedded HTML tags.
<b>bold</b>
produces <b>bold</b>.
<center> <iframe src="http://www.societyofcontrol.com/x404/ludwigstein/index.htm" width="100%"
height="1000" frameborder="0" allowtransparency="1"></iframe></center>
<a href="http://www.google.com">google</a>
<EMBED SRC="test.mp3" AUTOSTART=false WIDTH=144 HEIGHT=60 LOOP=1>
<pre>
- include <math.h>
- include <stdio.h>
int main(int argc, char **argv) {
sleep(years2seconds(1500000); printf("%d\n", 42);
} </pre>
could work to show
#include <math.h> #include <stdio.h> int main(int argc, char **argv) { sleep(years2seconds(1500000); printf("%d\n", 42); }
I had to change this to get it to work in a file included in a template (as with a sidebar). My code is:
$AllowedHTML="ul|li"; $InlineReplacements["/<(\/?($AllowedHTML)\b[^>]*)>/"] = "<$1>";
pmwiki-2.3.38 -- Last modified by {{}}?