|
Cookbook /
EnableHTML<< BuildForms | Forms-related | Forms >> Summary: How to include HTML markup in wiki pages
Version:
Prerequisites:
Status:
Maintainer:
Discussion: EnableHTML-Talk
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 Same code as presented, but this one works with linebreaks enabled in config.php (e.g. $HTMLPNewline = '<br />'; ) and allows all html tags:
<?php if (!defined('PmWiki')) exit();
$HTMLPNewline = '<br />';
Markup(
"html-allow",
'>{$var}',
'/<(\/?([\w]+)(?![a-z!])(([\'"]).*?\4|.*?)*?)>/ie',
"'<:block>'.Keep(PSS('<$1>'))"
);
Not secure!!! I only use it for my personal wiki. MikeStopContinues 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:]";
}
}
Sorry, but this doesn't work! cg 2008-08-28 It works for me, but I use the following:
Markup('html', 'fulltext', '/\\(:html:\\)(.*?)\\(:htmlend:\\)/esi',
"'<:block>'.Keep(str_replace(array('>','<','&'), array('>','<','&'), PSS('$1')))");
if (!CondAuth($pagename,"admin"))
{ $ROSPatterns["/\\(:html:\\)/i"] = "[:html:]";
$ROSPatterns["/\\(:htmlend:\\)/i"] = "[:htmlend:]";
}
Which version you use depends on where you put the condition in your local/config.php or local/farmconfig.php file. See this mailing list discussion for more details. This is a consolidation of some tips on the EnableHTML-Talk page. It enables raw HTML between (:html:) and (:htmlend:) tags only if the page is saved by somebody with admin privileges. Cut and paste the below code into your
# enable (:html:) & (:htmlend:) for admins
# From http://www.pmwiki.org/wiki/Cookbook/EnableHTML-Talk
Markup(
'html',
'fulltext',
'/\\(:html:\\)(.*?)\\(:htmlend:\\)/esi',
"'<:block>'.Keep(str_replace(array('>', '<', '&'),
array('>', '<', '&'), PSS('$1')))");
array_unshift($EditFunctions, 'MaybeDisableEmbedhtml');
function MaybeDisableEmbedhtml($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
Contributors
CommentsSee discussion at EnableHTML-Talk |