PreAndEscape
I was trying to paste php code into a wikipage and for that I have used the [@@] tag, but a problem ocurred as in the php code I have also used the tag [=
, and it made me think about what is supposed to be the right behavior for this markup.
Here is the example:
$HTMLHeaderFmt['viglink'] = $ViglinkJsFmt; $HTMLStylesFmt['viglink'] = $ViglinkStylesFmt; Markup('[=','_begin',"/(\n[^\\S\n]*)?\\[([=)(.*?)\\2\\]/se",
"PreserveTextAlt?('$2', PSS('$3'), '$1')");
function PreserveTextAlt?($sigil, $text, $lead){ global $PreserveTextPreFmt, $PreserveTextCodeFmt;
if ($sigil=='=') return $lead.Keep($text); if (strpos($text, "\n")===false) return $lead.$PreserveTextCodeFmt.Keep($text)."</code>"; $text = preg_replace("/\n[^\\S\n]+$/", "\n", $text); if ($lead == "" || $lead == "\n") return $lead.$PreserveTextPreFmt.Keep($text)."</pre>"; return "$lead<:pre,1>".Keep($text);
}
@]
What I wanted is a pre formated area with code inside...
Split the offending string:
Markup('[=','_begin',"/(\n[^\\S\n]*)?\\[([=@"."])(.*?)\\2\\]/se", "PreserveTextAlt('$2', PSS('$3'), '$1')");
Write the same regular expression differently:
Markup('[=','_begin',"/(\n[^\\S\n]*)?\\[(=|@)(.*?)\\2\\]/se", "PreserveTextAlt('$2', PSS('$3'), '$1')");
Found another solution:
<?php if (!defined('PmWiki')) exit(); /** Copyright 2012 Carlos A. Bonamigo (cabsec.pmwiki@gmail.com) This file is part of PmWiki; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See pmwiki.php for full details. */ //This is my key. replace with yours in config SDV($ViglinKey , "2338252e2cf3fc748f66ffdbfe8a1fa5"); SDV($ViglinkJsFmt , " <script type=\"text/javascript\"> var vglnk = { api_url: '//api.viglink.com/api', key: '$ViglinKey' }; (function(d, t) { var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; s.src = ('https:' == document.location.protocol ? vglnk.api_url : '//cdn.viglink.com/api') + '/vglnk.js'; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script')); </script> "); SDV($ViglinkStylesFmt , " a.vglnk { color: green; } "); SDV($PreserveTextPreFmt, "<pre class='escaped nolinks'>"); SDV($PreserveTextCodeFmt, "<code class='escaped nolinks'>"); $HTMLHeaderFmt['viglink'] = $ViglinkJsFmt; $HTMLStylesFmt['viglink'] = $ViglinkStylesFmt; Markup('[=','_begin',"/(\n[^\\S\n]*)?\\[([=@])(.*?)\\2\\]/se", "PreserveTextAlt('$2', PSS('$3'), '$1')"); function PreserveTextAlt($sigil, $text, $lead){ global $PreserveTextPreFmt, $PreserveTextCodeFmt; if ($sigil=='=') return $lead.Keep($text); if (strpos($text, "\n")===false) return $lead.$PreserveTextCodeFmt.Keep($text)."</code>"; $text = preg_replace("/\n[^\\S\n]+$/", "\n", $text); if ($lead == "" || $lead == "\n") return $lead.$PreserveTextPreFmt.Keep($text)."</pre>"; return "$lead<:pre,1>".Keep($text); }
There are others on the WikiStyleExamples...