- Filters are a "find and replace" feature (think SED)
- Filters do not follow the "last found, one used" schema, they're
cumulative. You can define as many filters as needed, with no limit.
They will be applied on the same order as defined.
- Different from other settings, both the target specific filters and
the generic ones (all targets) are used. On the following example, both
filters are used on the HTML target:
%!postproc : this that
%!postproc(html): that other
- The filters must receive exactly TWO arguments
- Special escapes as
\n
(line break) and \t
(tabulation) are interpreted
- To delete some text, change it by an empty string
%!postproc: "undesired string" ""
- To avoid problems, always use the explicit target form when using
PostProc to change tags:
%!postproc(target): <this> <that>
- PREproc is applied right after the line is read, and POSTproc is
applied after all the parsing was made. This is similar to (UUOC
ahead):
$ cat file.t2t | preproc.sh | txt2tags | postproc.sh
- The first part of a filter (the "search for" part) is not read as a
regular string, but as a Regular Expression pattern. If you don't know
what these expressions do, don't worry, you may never have to. Just
keep in mind that you will need to "escape" some characters to use
them. To escape is to prefix the character with a backslash "\". Here
is the list:
\* \+ \. \^ \$ \? \( \) \{ \[ \| \\
- Python Regular Expressions are available! They're similar to Perl
Regexes (PCRE). Example: Change all opening and closing "B" tags to
"STRONG" on HTML:
%!postproc(html): '(</?)B>' '\1STRONG>'
- The filter arguments can be passed on 3 ways:
- A single unquoted word such as FOO (no spaces)
- A string double quoted such as "FOO"
- A string single quoted such as 'FOO'
- If your pattern has double quotes, protect it with single quotes and
vice-versa. Some valid samples:
%!postproc: PATT REPLACEMENT
%!postproc: "PATT" "REPLACEMENT"
%!postproc: 'PATT' 'REPLACEMENT'
%!postproc: PATT "REPLACEMENT"
%!postproc: "PATT" 'REPLACEMENT'