2016-08-16 05:14:59 +03:00
|
|
|
#  pWiki Macros
|
2016-08-15 21:11:49 +03:00
|
|
|
|
2016-08-13 03:20:23 +03:00
|
|
|
## Syntax
|
|
|
|
|
|
|
|
|
|
Any macro can be used in any of the two forms, either _inline_ or _HTML-like_.
|
|
|
|
|
|
|
|
|
|
Inline:
|
|
|
|
|
```
|
2016-08-15 23:39:23 +03:00
|
|
|
@macro-name(value)
|
2016-08-13 03:20:23 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
HTML-style:
|
|
|
|
|
```
|
|
|
|
|
<macro-name arg="value"/>
|
|
|
|
|
|
|
|
|
|
<macro-name arg="value">
|
|
|
|
|
...text...
|
|
|
|
|
</macro-name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The two forms are almost identical, with the only difference being that the
|
|
|
|
|
inline form does not support body text (note that some macros may provide
|
|
|
|
|
this functionality as an argument, namely `slot`).
|
|
|
|
|
|
|
|
|
|
The two forms exist to fill two distinct functions:
|
|
|
|
|
- inline: compatible with attribute values and short
|
|
|
|
|
- html-like: element-like, simpler when dealing with html
|
|
|
|
|
|
2016-08-17 02:25:15 +03:00
|
|
|
|
|
|
|
|
|
2016-08-15 18:13:08 +03:00
|
|
|
### Escaping macros
|
|
|
|
|
|
|
|
|
|
Macros can be escaped for inclusion in the page, the two types of macros
|
|
|
|
|
are escaped a bit differently:
|
|
|
|
|
|
|
|
|
|
- inline macros -- escaped by preceding with a `\`
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
\\@include(SomePage)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Displayed in page as:
|
|
|
|
|
|
2016-08-15 18:21:35 +03:00
|
|
|
\@include(SomePage)
|
2016-08-15 18:13:08 +03:00
|
|
|
|
2016-08-15 18:20:09 +03:00
|
|
|
_NOTE: if displayed on github, this will show an extra "\" in both
|
|
|
|
|
cases, this should be ignored as pWiki will consume the escaping "\"
|
|
|
|
|
in both the code example and the preview._
|
|
|
|
|
|
2016-08-15 18:13:08 +03:00
|
|
|
|
|
|
|
|
- html-like macros -- escaped _the HTML way_
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<include src="SomePage"\>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Displayed in page as:
|
|
|
|
|
|
2016-08-15 18:22:37 +03:00
|
|
|
<include src="SomePage"\\>
|
2016-08-15 18:13:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-20 00:56:37 +03:00
|
|
|
### Conditional comments
|
|
|
|
|
|
|
|
|
|
In addition to HTML and filter-specific comments pWiki provides two types
|
|
|
|
|
of conditional comments that serve two specific functions:
|
|
|
|
|
|
|
|
|
|
Show something in pWiki but hide it in HTML:
|
|
|
|
|
```
|
|
|
|
|
<!--\[pWiki[ ... ]]-->
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Show something in HTML but hide in pWiki:
|
|
|
|
|
<pre>
|
|
|
|
|
<pwiki-comment> ... </pwiki-comment>
|
|
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
|
|
\@pwiki-comment( ... )
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This will enable writing documents (mainly in _markdown_) that are usable
|
|
|
|
|
bot from within pWiki as well as outside.
|
|
|
|
|
|
2016-08-13 03:20:23 +03:00
|
|
|
|
|
|
|
|
## Macros
|
|
|
|
|
|
2016-08-15 21:18:56 +03:00
|
|
|
### now ()
|
|
|
|
|
|
|
|
|
|
Get current date in seconds since epoch, this is equivalet Javascript's
|
|
|
|
|
`Date.now()`.
|
|
|
|
|
|
|
|
|
|
This is mostly used for automatically creating paths (see: todo / outline)
|
|
|
|
|
|
2016-08-17 02:25:15 +03:00
|
|
|
This is different from `$NOW` in path (see: Doc/Path) in that this gets
|
|
|
|
|
the date once per page load, i.e. the date changes on page load, while
|
|
|
|
|
`$NOW` is set every time the path is used, i.e. on every click or script
|
|
|
|
|
use.
|
|
|
|
|
|
|
|
|
|
**Example:**
|
|
|
|
|
```
|
|
|
|
|
\@now()
|
|
|
|
|
```
|
2016-08-20 01:21:05 +03:00
|
|
|
|
|
|
|
|
<pwiki-comment>Will produce: `1471389217848` </pwiki-comment>
|
|
|
|
|
|
|
|
|
|
<!--[pWiki[ Will produce: `@now()` ]]-->
|
2016-08-17 02:25:15 +03:00
|
|
|
|
|
|
|
|
|
2016-08-15 21:18:56 +03:00
|
|
|
|
2016-08-13 03:20:23 +03:00
|
|
|
### filter (name)
|
|
|
|
|
|
|
|
|
|
Enable or disable a page filter.
|
|
|
|
|
|
|
|
|
|
A filter is a way to transform the page source.
|
|
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
- `name` -- filter name. If name is preceded with a '-' then it
|
|
|
|
|
will be forced off. This is useful for disabling _default_ filters, or
|
|
|
|
|
filters added previously in templates.
|
|
|
|
|
|
|
|
|
|
Filters:
|
|
|
|
|
- wikiword (default)
|
|
|
|
|
- markdown
|
|
|
|
|
|
2016-08-17 02:25:15 +03:00
|
|
|
**Example:**
|
|
|
|
|
- `[./_edit]` -- _see the macro at the end of the page._
|
|
|
|
|
|
2016-08-13 03:20:23 +03:00
|
|
|
|
|
|
|
|
|
2016-08-15 21:55:20 +03:00
|
|
|
### include (src isolated text)
|
2016-08-13 03:20:23 +03:00
|
|
|
|
|
|
|
|
Include a page. The included page is rendered independently from current
|
|
|
|
|
page and is inserted as-is in macro body.
|
|
|
|
|
|
|
|
|
|
Note that this will produce a `include` tag in the code that contains
|
|
|
|
|
the included page, this makes this tag not suitable for use anywhere
|
|
|
|
|
but an html element body.
|
|
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
- `src` -- path to source page.
|
2016-08-15 21:55:20 +03:00
|
|
|
- `isolated` -- prevent slots from included page from affecting the including page.
|
2016-08-13 03:20:23 +03:00
|
|
|
- `text` -- is used when recursive include is detected and ignored otherwise.
|
|
|
|
|
|
2016-08-17 02:25:15 +03:00
|
|
|
_For examples see `slot` macro exaples below._
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-13 03:20:23 +03:00
|
|
|
### source (src) / quote (src)
|
|
|
|
|
|
|
|
|
|
Insert a page without rendering. This is similar to include but will not
|
|
|
|
|
render the page.
|
|
|
|
|
|
|
|
|
|
The difference between `source` and `quote` is:
|
|
|
|
|
- _source_ includes the page as-is
|
|
|
|
|
- _quotes_ escapes the page (i.e. _quotes_ it's source) for its code to
|
|
|
|
|
display in the rendered HTML correctly.
|
|
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
- `src` -- path to source page.
|
|
|
|
|
|
2016-08-17 02:25:15 +03:00
|
|
|
**Example:**
|
|
|
|
|
|
2016-08-20 01:02:55 +03:00
|
|
|
<pwiki-comment>
|
|
|
|
|
- [bootstrap css](bootstrap/Templates/_css.html)
|
2016-08-20 01:14:11 +03:00
|
|
|
</pwiki-comment>
|
2016-08-20 01:16:30 +03:00
|
|
|
|
2016-08-20 01:14:11 +03:00
|
|
|
<!--[pWiki[
|
2016-08-17 02:25:15 +03:00
|
|
|
[Templates/\_css] / [bootstrap css](bootstrap/Templates/_css.html):
|
2016-08-20 01:02:55 +03:00
|
|
|
```
|
2016-08-17 02:25:15 +03:00
|
|
|
@source(Templates/_css)
|
|
|
|
|
```
|
2016-08-20 00:56:37 +03:00
|
|
|
]]-->
|
2016-08-13 03:20:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
### slot (name text)
|
|
|
|
|
|
|
|
|
|
Define or fill a slot.
|
|
|
|
|
|
|
|
|
|
First occurrence of a `name` will _define_ a slot and fill it with `text`.
|
|
|
|
|
Each new occurrence of a name will change slot content.
|
|
|
|
|
|
2016-08-17 02:25:15 +03:00
|
|
|
**Example:**
|
|
|
|
|
|
2016-08-20 01:02:55 +03:00
|
|
|
<pwiki-comment>
|
2016-08-20 01:14:11 +03:00
|
|
|
- [bootstrap view](bootstrap/Templates/_view.html)
|
|
|
|
|
- [bootstrap edit](bootstrap/Templates/_edit.html)
|
|
|
|
|
</pwiki-comment>
|
2016-08-20 01:15:35 +03:00
|
|
|
|
2016-08-20 01:14:11 +03:00
|
|
|
<!--[pWiki[
|
2016-08-17 02:25:15 +03:00
|
|
|
[Templates/\_view] / [bootstrap view](bootstrap/Templates/_view.html):
|
|
|
|
|
```
|
|
|
|
|
@source(Templates/_view)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
[Templates/\_edit] / [bootstrap edit](bootstrap/Templates/_edit.html):
|
|
|
|
|
```
|
|
|
|
|
@source(Templates/_edit)
|
|
|
|
|
```
|
2016-08-20 01:02:55 +03:00
|
|
|
]]-->
|
2016-08-17 02:25:15 +03:00
|
|
|
|
2016-08-13 03:20:23 +03:00
|
|
|
|
2016-08-19 04:19:38 +03:00
|
|
|
### macro (name src sort) / else ()
|
2016-08-13 03:20:23 +03:00
|
|
|
|
|
|
|
|
Apply macro to source page and include the result.
|
|
|
|
|
|
|
|
|
|
This is similar to include but does not require a separate page.
|
|
|
|
|
|
|
|
|
|
Both `name` and `src` are optional.
|
|
|
|
|
|
|
|
|
|
If `name` is given a _named macro_ is defined. This macro can be later
|
|
|
|
|
referenced (used) by name. A named macro can be redefined/overridden.
|
|
|
|
|
|
|
|
|
|
If `src` is given a macro is applied to a specific page or range of pages
|
|
|
|
|
(see: WikiPath).
|
|
|
|
|
|
|
|
|
|
For a macro to be useful it must have a body (`text`), either defined as
|
|
|
|
|
a named macro or in the current macro.
|
|
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
- `name` -- macro name (optional).
|
|
|
|
|
- `src` -- path to source page (optional).
|
2016-08-19 04:19:38 +03:00
|
|
|
- `sort` -- space separated list of methods to use for item sorting
|
2016-08-13 03:20:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
`else` macro is applicable inside `macro`. it is used when the `src` path
|
|
|
|
|
of `macro` matches no pages.
|
|
|
|
|
|
2016-08-17 02:25:15 +03:00
|
|
|
**Example:**
|
|
|
|
|
|
2016-08-20 01:02:55 +03:00
|
|
|
<pwiki-comment>
|
2016-08-20 01:15:35 +03:00
|
|
|
- [bootstrap pages](bootstrap/Templates/pages.html)
|
2016-08-20 01:14:11 +03:00
|
|
|
</pwiki-comment>
|
2016-08-20 01:15:35 +03:00
|
|
|
|
2016-08-20 01:16:30 +03:00
|
|
|
<!--[pWiki[
|
2016-08-17 02:25:15 +03:00
|
|
|
[Templates/pages] / [bootstrap pages](bootstrap/Templates/pages.html):
|
|
|
|
|
```
|
|
|
|
|
@source(Templates/pages)
|
|
|
|
|
```
|
2016-08-20 01:16:30 +03:00
|
|
|
]]-->
|
2016-08-17 02:25:15 +03:00
|
|
|
|
2016-08-13 03:20:23 +03:00
|
|
|
|
|
|
|
|
<!-- @filter(markdown) -->
|
|
|
|
|
<!-- vim:set ts=4 sw=4 ft=markdown : -->
|