This is a talk page for improving MarkupExpressions.
Requests for further markup expressions
- ftime add ordinal suffix for date format - st, nd, rd, th.
- allow markup expressions to be nested (already possible - see below)
- rtrim - remove trailing spaces (default) or character if optional parameter supplied (useful for page text variables);
{(rtrim string optionalchar)}
- ltrim - remove leading spaces (default) or character if optional parameter supplied (useful for page text variables);
{(ltrim string optionalchar)}
- trim - remove leading and trailing spaces (default) or character if optional parameter supplied (useful for page text variables);
{(trim string optionalchar)}
- nomarkup - remove markup such as separators (! headings, ----), lists (*, #, : :), emphasis ('', ''', [++], [--], etc), paragraphs ([[<<]], -<, ->), and optionally groups ([[x|y]] becomes y)
{(nomarkup string nolinks)}
- word - return specified word(s) (alfanum+"_"+"-"). If second number is greater than no of word, return all words til the end (KAL)
{(word string 1)} = return first word
{(word string 2 4)} = return second, third and fourth word
- token - return parsed string, list of valid separators is specified as 1. argument, no of token as 2. argument (KAL)
{(token string 'list-of-sep-chars' 3)}
- return string before a target string (KAL)
- e.g.: {(stringbefore "sample string to be parsed" "ng")} will return "sample stri"
- PHP-code to add to markupexpressions.php:
# return substring of string before targetstring:
## expressions like {(stringbefore string targetstring)}
$MarkupExpr['stringbefore'] = 'stringbefore($args[0],$args[1])';
function stringbefore($text,$target)
{
list($text2,$null) = explode($target,$text);
return $text2;
}
how do I achieve the following
- obtain the last n characters of a string
Use {(substr "string" -n)}
- truncate the last n characters of a string
Use {(substr "string" 0 -n)}
Working examples
* "{$Name}"
# {(substr "{$Name}" 6 -5)}
# {(substr "{$Name}" -5)}
# {(substr "{$Name}" 0)}
# {(substr "{$Name}" 0 -5)}
# {(substr "{$Name}" -5 4)}
# {(substr "{$Name}" -5 -6)}
| - Expressions
- -Talk
- MarkupExpressions-Talk
- MarkupExpressions
- -Tal
-
|
Is it possible to nest markup expressions?
looks like the answer is no
{(substr "{$FullName}" 0 -5)}
{(asspaced '{$FullName}')}
{(asspaced '{(substr "{$FullName}" 0 -5)}')}
|
PmWiki.MarkupExpressions
Pm Wiki.Markup Expressions-Talk
(asspaced '{PmWiki.MarkupExpressions')}
|
Ah, but with a different syntax and being careful of quoting...
{(asspaced (substr "{$FullName}" 0 -5))}
|
Pm Wiki.Markup Expressions
|
Points to note:
- Nested MXes work with just parens on the inner MX, not curly+paren
- If you put it in quotes then it will be processed as a literal rather than as an expression, as expected
Moved from main page (doesn't work)
- is it possible to display the time in another time zone, eg
NowTime: {(ftime fmt="%F %H:%M")}
1 {(ftime when='Europe/London')}
2 {(ftime when='Europe/London 0
days')}
3 {(ftime when="Europe/London
2004-10-31 08:00")}
4 {(ftime when='Pacific/Auckland
{$:NowTime}')}
->@@#4 doesn't work because of the
order of rules with a markup expression
both setting NowTime (above) and also
using it (in #4)@@
5 {(ftime when='Europe/London')}
6 {(ftime when='Europe/London +2
days')}
7 {(ftime when="Europe/London
20041031T0820")}
8 {(ftime "%F %H:%M" 'Pacific/Auckland
now')}
| NowTime: 2013-06-19 07:59
1 June 19, 2013, at 01:59 AM
2 June 19, 2013, at 01:59 AM
3 October 31, 2004, at 12:00 AM
4 (ftime when='Pacific/Auckland {2013-06-19 07:59')}
#4 doesn't work because of the order of rules with a markup expression both setting NowTime (above) and also using it (in #4)
5 June 19, 2013, at 01:59 AM
6 June 21, 2013, at 01:59 AM
7 October 31, 2004, at 08:20 AM
8 2013-06-18 14:59
|
How is it possible to use page variables as follows
(:Month:{(substr 2013May 4)}:)
(:MonthNum:{(ftime fmt="%m" when="{$:Month}")}:)
{$:Month} ''as a number is'' {$:MonthNum}
|
May as a number is (ftime fmt=%m when="{May")}
|
Just note that when you have in a page a {$:PageTextVariable} the wikitext it contains is pasted in its place in the page without any change (except for relative links), and without evaluation. The evaluation will be done at a later point. That means, your {$:MonthNum} variable will actually contain {(ftime fmt="%m" when="{(substr 2013May 4)}")} after {$:Month} has been changed to its text content. When at a later point the markup expressions are evaluated, this is an incorrect syntax - in order to embed markup expressions, only the outer one needs curly brackets. So PmWiki does exactly what it is designed to do, but probably not what you expect. --Petko May 03, 2013, at 03:32 PM