|
Cookbook /
EnableHTML<< BuildForms | Forms-related | Forms >> Summary: How to include HTML markup in wiki pages
Version:
Prerequisites:
Status:
Maintainer:
QuestionIs it possible to include HTML markup in wiki pages? AnswerBy 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. There's also a security issue involved with that. If visitors can add elements such as However, there are a number of administrative pages where only selected people have edit passwords. It's entirely reasonable to unlock as much power as can be trusted to them, and as much complexity as they are willing to handle. So for those cases where this is warranted, here is how to do it: Install enablehtml.phpΔ into your Edit your include_once("$FarmD/cookbook/enablehtml.php");
This will give you a new function
EnableHtml('img');
EnableHtml('b|i|u|sup|sub|a|iframe|small');
You can also allow HTML comment tags via
EnableHtml('!');
Here's the code for it if for any reason the download-link does not work. (Just put it in your
<?php if (!defined('PmWiki')) exit();
function EnableHtml($tag) {
Markup(
"html-$tag",
'>{$var}',
'/<(\/?('.$tag.')(?![a-z!])(([\'"]).*?\4|.*?)*?)>/ie',
'Keep(PSS(\'<$1>\'))');
}
HTH - it's the best I can do -- TeganDowling As an option, here's some text combining info from two other pages. I like it because you can enable it sitewide, and anyone who is not an admin will have their html disabled when they save. Easy to use! Caveman
Markup('html', 'fulltext', '/\\(:html:\\)(.*?)\\(:htmlend:\\)/esi',
"'<:block>'.Keep(str_replace(array('>','<','&'), array('>','<','&'), PSS('$1')))");
array_unshift($EditFunctions, 'MaybeDisableHtml');
function MaybeDisableHtml($pagename,&$page,&$new)
{ if (!CondAuth($pagename,"admin"))
{ $ROSPatterns["/\\(:html:\\)/i"] = "[:html:]";
$ROSPatterns["/\\(:htmlend:\\)/i"] = "[:htmlend:]";
}
}
DetailsThis does not validate element attributes. The It also doesn't validate whether opening and closing tags are properly nested. If the pages contains invalid HTML markup, it will simply be passed through unchanged. (In case I haven't said this already, this means: Don't allow this on pages that aren't password-protected!) The parameter of
If EnableHtml('b|/b');
(in fact that would not work because
<form action="http://domain.tld/path/to/cgi?query=value" method="POST">
<input title="Tell me more about the < b > tag in HTML"> and not replace that If will not make PmWiki emit something like
To be precise,
See Also
Bugs and CommentsBe VERY careful when trying to use this with pages that already have hanging indents -- like PmWiki / BasicEditing. Hanging indents use -< as their indicator. If the next token looks like an html tag you want (eg. the phrase "A reverse arrow" will look like an anchor tag (<a>) ), then you may find pmwiki.php going into an infinite loop. --oPEO It doesn't seem to work. I am not the first one to notice. Here is another unanswered question: (Jan 3, 2007) I placed the enablehtml.php file into my cookbook directory in the hopes of allowing me to make new pages using HTML. Then I put include_once(" Like this user, I followed the directions to the letter. I tried many variations, nothing worked. Maybe it worked with previous versions, but not anymore? I'd like to point out a bug: using block elements may result in invalid XHTML. In HTML it's illegal to have <div> foo bar </div> it will come out poorly when PMWiki auto adds in p-tags. :/ --Carl To create a HTML-only site, you'd have to disable PmWiki's own markup. This isn't advisable for the pages that come with the installation of PmWiki, but it's perfectly possible for the other pages. Here's a sketch how to do that (warning: PHP ahead): In Disabling the markup can be done in several ways, none of them fully satisfactory:
Joachim Durchholz April 20, 2005, at 11:42 AM I'd like to have not just tags but also attributes filtered. That way, EnableHTML could be used to allow harmless HTML like It would be even better to filter attributes and CSS settings, so that harmless CSS styles could be done but dangerous ones (such as This all is technically a bit difficult. Any serious effort at this should also consider the Joachim Durchholz April 20, 2005, at 11:42 AM I'd like to add the code for a webring to my page; it has to be in HTML. How do I do that? Use CustomMarkup. There's a specific example on that page. -- Susan I'm having trouble using CustomMarkup. I want to be able to include a Statcounter.com javascript in my pages but when I try to use the Markup() code in stdmarkup.php (or config.php), it returns errors when I go to my wiki(approve links) (even using the example script) -Craig You can enable some html tags without any attributes. Put the following into local/config.php
$AllowedHtmlTags = 'b|i';
Markup("html-tags",
'>{$var}',
'/<('.$AllowedHtmlTags.')>(.*?)<\/('.$AllowedHtmlTags.')>/',
'<$1>$2</$3>');
If you place this in your configuration file
Markup(
'html',
'fulltext',
'/\\(:html:\\)(.*?)\\(:htmlend:\\)/esi',
"'<:block>'.Keep(str_replace(array('>', '<', '&'),
array('>', '<', '&'), PSS('$1')))");
you'll be able to use (:html:) and (:htmlend:) directives to insert HTML markup in your wiki pages. If you don't want your HTML source to be inside a <p>paragraph</p> then the (:html:) directive should be at the beginning of a line, immediately preceding your raw HTML source. The (:htmlend:) directive belongs at the end of the last line of your HTML source. For example, this wiki source Line above. (:html:)<h2>Hi!</h2> Some text.(:htmlend:) Line below. results in this output <p>Line above. </p><h2>Hi!</h2> Some text. <p>Line below. </p> You can also insert HTML code inline within a paragraph. For example, this wiki source Text...(:html:)<span class='foo'>Hi!</span>(:htmlend:)...text. results in this output <p>Text...<span class='foo'>Hi!</span>...text. </p> Authors will be able to place any conceivable malicious code between (:html:) and (:htmlend:), so be sure to take appropriate precaution... --Hagan ... and here's a good precaution to take: In your configuration file, put
array_unshift($EditFunctions, 'MaybeDisableEmbedhtml');
function MaybeDisableEmbedhtml($pagename,&$page,&$new)
{ if (!CondAuth($pagename,"admin"))
{ $ROSPatterns["/\\(:html:\\)/i"] = "[:html:]";
$ROSPatterns["/\\(:htmlend:\\)/i"] = "[:htmlend:]";
}
}
How this works: if someone is editing a page who doesn't have admin privileges, then it will strip all (:html:) and (:htmlend:) tags from their text, replacing them with square-bracket versions that do nothing. --Lucian Wischik, 23 November 2006, based on suggestions by PM (The above solution also answers the following question:) "I'd like to restrict HTML tags to write-protected pages. How can I do?"
The idea is: My Web site is public. I do not want to allow people adding HTML tags in normal pages. But, if the page is protected by a password (write-protect), I am nearly sure that the page will not be modified by a hacker. And if I want to include something in a lot of pages, I can use the site/group/page header or footer.
Jean-Dom, 27 September 2005. I'm confused. How do you rig it so that only admins, or certain users, or certain groups, may have permission to insert HTML?
<<<<<<< Whoa! Trying to use EnableHtml made everything go blank... Using SimpleTab skin, maybe that can have something to do with it... -Tryggve --- Contributors
SandboxUse the space below to experiment with embedded HTML tags.
<SCRIPT LANGUAGE="JavaScript"> user = 'name'; site = 'domain.com'; document.write('<a href=\"mailto:' + user + '@' + site + '\">'); document.write(user + '@' + site + '</a>'); </SCRIPT> |