Recent Changes - Search:

PmWiki

pmwiki.org

MarkupExpressions-Talk

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)}
  • "MarkupExpressions-Talk"
  1. Expressions
  2. -Talk
  3. MarkupExpressions-Talk
  4. MarkupExpressions
  5. -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')}
 9 {(ftime "%F %H:%M" 'Pacific/Auckland
now')}
 10 {(ftime "%F %H:%M" 'now NZST')}
 11 {(ftime "%F %H:%M NZST" 'now')}

NowTime: 2014-10-25 04:27

 1 October 24, 2014, at 10:27 PM
 2 October 24, 2014, at 10:27 PM
 3 October 31, 2004, at 12:00 AM
 4 (ftime when='Pacific/Auckland {2014-10-25 04:27')} 
#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 October 24, 2014, at 10:27 PM
 6 October 26, 2014, at 11:27 PM
 7 October 31, 2004, at 08:20 AM
 8 2014-10-25 04:27 Pacific/Auckland
 9 2014-10-24 10:27
 10 2014-10-24 11:27
 11 2014-10-25 04:27 NZST

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


This is working fine in MarkupExpressions-Sandbox but not here. Is there anything wrong with this? -- Luigi 2 Sept 2014

MyDate:2007-04-12


              {(ftime '%A %B %e, %Y' {$:MyDate})}
              {(ftime '%A %B %e, %Y' '{$:MyDate} -2days')}

              Thursday April 12, 2007
              Tuesday April 10, 2007

Update! Thanks to Petko for enhancing the system: date subtraction now works!
Please see the thread about Adding/subtracting days to ftime Page Text Variable -- Luigi 5 Sept 2014



This is a talk page for improving PmWiki.MarkupExpressions.

Edit - History - Print - Recent Changes - Search
Page last modified on September 05, 2014, at 02:53 PM