[pmwiki-users] Re: Re: Re: Re: Cookbook recipes updated for beta 19 compatibility
chr at home.se
chr at home.se
Fri Jan 28 02:38:23 CST 2005
On 28 Jan 2005, John Rankin wrote:
> On Friday, 28 January 2005 11:23 AM, chr at home.se wrote:
> >On 27 Jan 2005, John Rankin wrote:
> >
> >> A function something like the following, perhaps:
> >>
> >> function PreventMarkup($markups) {
> >> global $MarkupTable;
> >> foreach ($markups as $m)
> >> if isset($MarkupTable[$m]) unset($MarkupTable[$m])
> >> else Markup($m,'');
> >> }
> >
> >I'd prefer the function being able to take a variable number of arguments
> >(where each one can be a an array).
>
> Er, lead me by the hand please. Can you give me an example?
Yes, I thought it'd be nice we would allow all of these invocations:
PreventMarkup('dropcaps', '^!', 'Q:');
PreventMarkup(array('dropcaps',' '^!', 'Q:'));
PreventMarkup('Q:', array('dropcaps',' '^!'));
> how do I do that? Remember I'm only an amateur programmer.
I googled and came up with this example (I don't know PhP well either)
function foo() {
$numargs = func_num_args();
echo "Number of arguments: $numargs<br />\n";
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "<br />\n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
}
}
foo(1, 2, 3);
So how about something like this:
function PreventMarkup() {
global $MarkupTable;
$args = func_get_args(); // Place arguments in an array
foreach ($args as $arg) {
if(is_array($arg)) {
foreach ($args as $m) {
if isset($MarkupTable[$m]) unset($MarkupTable[$m])
else Markup($m,'');
}
else {
if isset($MarkupTable[$arg]) unset($MarkupTable[$arg])
else Markup($arg,'');
}
}
}
It's not so elegant. If I knew how to explode an array and send the
elements as separate arguments I'd make the function above recursive.
Something like
function PreventMarkup() {
global $MarkupTable;
$args = func_get_args(); // Place arguments in an array
foreach ($args as $arg)
if(is_array($arg))
PreventMarkup(explode_array($arg));
else
if isset($MarkupTable[$arg])
unset($MarkupTable[$arg])
else
Markup($arg,'');
}
Not sure if some extra {...} are needed or not...
> >> Assuming the above works, I suggest we add it to the extended markup
> >> recipe.
> >
> >Why not add the function to pmwiki.php? Instructions on how to use
> >function should of course go into extended markup.
>
> It could be, but I suspect Pm has higher calls on his time, so it may be
> better if a mere mortal does it.
Oh, I don't think Pm will have any problems adding this function to
pmwiki.php if we write and test it. Assuming he doesn't have something
else against this functionality. Patrick?
> >> >Hmm... when I think about it... what about being able to disable markup
> >> >through markup? What if by adding the following to a wiki page
> >> >
> >> > (:prevent-markup ^!:)
> >> >
> >> >would disable that markup for that page? (This might be a can of worms of
> >Is this something good or something naughty?
>
> Let's say the effects may cause surprise. Sometimes surprises are good.
> This may not be one of those times...
It may well have some risks... but I think I'd like this possibility,
yesterday I came across a situation when I thought it would have been
super to be able to do just that.
/C
--
Christian Ridderström, +46-8-768 39 44 http://www.md.kth.se/~chr
More information about the pmwiki-users
mailing list