|
Cookbook /
Replace on saveSummary: How to use
$ROSPatterns (Replace On Save Patterns)?Version:
Prerequisites:
Status:
Maintainer:
Categories: Markup
QuestionHow do I use AnswerThe ROS (Replace On Save) array defines a pattern as key and a text which should replace it when saving an edited text. The In general The "text to search for" is searched and replaced using the PHP preg_replace function, thus the pattern has to use the preg_replace syntax. ExamplesYou can use a replace on save pattern to assist you when converting HTML to wiki. The following patterns work # replace both <i> and </i>, upper and lower case $ROSPatterns ["/<\\/?i>/i"] = "''"; # replace both <b> and </b>, upper and lower case $ROSPatterns ["/<\\/?b>/i"] = "'''"; # replace <em>, upper and lower case, markup must be enabled in config.php $ROSPatterns ["/<em>/i"] = "'~"; # replace </em>, upper and lower case, markup must be enabled in config.php $ROSPatterns ["/<\\/em>/i"] = "~'"; # replace <strong>, upper and lower case, markup must be enabled in config.php $ROSPatterns ["/<strong>/i"] = "'*"; # replace </strong>, upper and lower case, markup must be enabled in config.php $ROSPatterns ["/<\\/strong>/i"] = "*'"; # replace <sup>, upper and lower case $ROSPatterns ["/<sup>/i"] = "'^"; # replace </sup>, upper and lower case $ROSPatterns ["/<\\/sup>/i"] = "^'"; # replace <sub>, upper and lower case $ROSPatterns ["/<sub>/i"] = "'_"; # replace </sub>, upper and lower case $ROSPatterns ["/<\\/sub>/i"] = "_'"; # replace both <br> and <br />, upper and lower case $ROSPatterns ["/<br\\s*\\/?>/i"] = "[[<]]"; # replace both <p> and </p>, upper and lower case $ROSPatterns ["/<\\/?p>/i"] = "\n\n"; # replace html links with the [[link|text]] markup $ROSPatterns ['/<\\s*?a.+?href\\s*?=\\s*?["\'](.*?)["\'].*?>(.*?)<\/a>/sim'] = '[[$1|$2]]'; # extract the image link from the <img ...> tag $ROSPatterns ['/<\\s*?img.+?src\\s*?=\\s*?["\'](.*?)["\'].*?>/sim'] = '$1'; # replace <h1> and </h1>, upper and lower case $ROSPatterns["/<h1\\s*>/i"] = "\n!"; $ROSPatterns["/<\\/h1\\s*>/i"] = ""; NotesMore patterns will be added to cater for other simple HTML constructs.
ReleasesAdd these patterns to the bottom of your local/config.php CommentsThe following test cases were used <i>italic</i> <I>ITALIC</I> bre<br>ak br<br />eak BRE<BR>AK BR<BR />EAK BRE<BR />EAK <b>bolD</B> <B>Bold</b> <EM>em</em> <sup>sup</sup>erscript <sub>sub</sub>script <strong>strong</STRONG> This is a simple <p>paragraph</p> sort of. See AlsoCookbook.QuickReplace Quickly define replacement texts in wiki pages, and use them as markup or during page save.
Cookbook.ConvertHTML Convert an HTML page to PmWiki markup
ContributorsSimon
Anno
Incorrect Links
$ROSPatterns["/\\[{2}([^\/|\\[\\]]*?)(\/){0,1}([^\/|\\[\\]]*?)\\.
([^|\\]\\[]*?)\\]{2}/i"] =
"[[$1$2$3 $4|$3. $4]]";
The explanation of the pattern:
Match the character "[" literally «\[{2}»
Exactly 2 times «{2}»
Match the regular expression below and capture its match into
backreference number 1 «([^/|\[\]]*?)»
Match a single character NOT present in the list below «[^/|\[\]]*?»
Between zero and unlimited times, as few times as possible,
expanding as needed (lazy) «*?»
One of the characters "/|" «/|»
A [ character «\[»
A ] character «\]»
Match the regular expression below and capture its match into
backreference number 2 «(/){0,1}»
Between zero and one times, as many times as possible, giving back
as needed (greedy) «{0,1}»
Match the character "/" literally «/»
Match the regular expression below and capture its match into
backreference number 3 «([^/|\[\]]*?)»
Match a single character NOT present in the list below «[^/|\[\]]*?»
Between zero and unlimited times, as few times as possible,
expanding as needed (lazy) «*?»
One of the characters "/|" «/|»
A [ character «\[»
A ] character «\]»
Match the character "." literally «\.»
Match the character " " literally « »
Match the regular expression below and capture its match into
backreference number 4 «([^|\]\[]*?)»
Match a single character NOT present in the list below «[^|\]\[]*?»
Between zero and unlimited times, as few times as possible,
expanding as needed (lazy) «*?»
The character "|" «|»
A ] character «\]»
A [ character «\[»
Match the character "]" literally «\]{2}»
Exactly 2 times «{2}»
email from Anno
|