<div dir="ltr">I use <a href="https://www.pmwiki.org/wiki/Cookbook/Grep">https://www.pmwiki.org/wiki/Cookbook/Grep</a><div>I find it works very well, e.g. see <a href="https://ttc.org.nz/pmwiki/pmwiki.php/Site.TemplateFixtureCardInclude">https://ttc.org.nz/pmwiki/pmwiki.php/Site.TemplateFixtureCardInclude</a></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, 14 May 2025 at 00:57, ABClf <<a href="mailto:languefrancaise@gmail.com">languefrancaise@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:monospace">I was looking for something easy (I guess) which might be useful : get a markup for extracting a line in some Group.MyPage according to regex pattern.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">I have asked ChatGPT (free version) to do the job ; </div><div class="gmail_default" style="font-family:monospace">first attempt didn't work, but the scenario was credible (markup will be like :<span style="font-family:Arial,Helvetica,sans-serif"> </span><span style="font-family:Arial,Helvetica,sans-serif">(:ExtractLine Profil.JeanDoe "^Nom:" :))</span></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">First result given was :</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace"><?php if (!defined('PmWiki')) exit();<br><br>Markup('ExtractLine', 'directives',<br>  '/\\(:ExtractLine\\s+(\\S+)\\s+([\'"]).+?\\2\\s*:\\)/e',<br>  "ExtractLineFromPage('$1', PSS('$2'))");<br><br>function ExtractLineFromPage($pagename, $pattern) {<br>    $page = ReadPage($pagename, READPAGE_CURRENT);<br>    if (!$page) return "Page non trouvée";<br><br>    $text = $page['text'];<br>    $lines = explode("\n", $text);<br><br>    foreach ($lines as $line) {<br>        if (preg_match($pattern, $line)) {<br>            return Keep($line);  // Keep() évite l'interprétation wiki<br>        }<br>    }<br><br>Saved as a cookbook and called in config, I am given an error by PmWiki internal debugging code (message : code obsolete).</div><div class="gmail_default" style="font-family:monospace">Ok. I copy the error message to ChatGPT and suggest him a link to PmWiki/CustomMarkup.<br></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">One second later, I am given an updated code which works :</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace"><?php if (!defined('PmWiki')) exit();<br><br>Markup('ExtractLine', 'directives',<br>  '/\\(:ExtractLine\\s+(\\S+)\\s+([\'"])(.+?)\\2\\s*:\\)/',<br>  'ExtractLineMarkup');<br><br>function ExtractLineMarkup($m) {<br>    $targetPage = $m[1];<br>    $pattern = $m[3]; // C'est le motif entre guillemets<br><br>    return ExtractLineFromPage($targetPage, $pattern);<br>}<br><br>function ExtractLineFromPage($pagename, $pattern) {<br>    $page = ReadPage($pagename, READPAGE_CURRENT);<br>    if (!$page) return "Page non trouvée";<br><br>    $text = $page['text'];<br>    $lines = explode("\n", $text);<br><br>    foreach ($lines as $line) {<br>        if (@preg_match("/$pattern/", $line)) {<br>            return Keep($line);  // Empêche l'interprétation du markup<br>        }<br>    }<br><br>    return "Aucune ligne ne correspond au motif.";<br>}<br></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">This code gets only the first line meeting the pattern.</div><div class="gmail_default" style="font-family:monospace">Just ask if you need all the lines and wait one more second :<br><br><?php if (!defined('PmWiki')) exit();<br><br>Markup('ExtractLine', 'directives',<br>  '/\\(:ExtractLine\\s+(\\S+)\\s+([\'"])(.+?)\\2\\s*:\\)/',<br>  'ExtractLineMarkup');<br><br>function ExtractLineMarkup($m) {<br>    $targetPage = $m[1];<br>    $pattern = $m[3]; // Motif brut sans délimiteurs<br>    return ExtractAllMatchingLines($targetPage, $pattern);<br>}<br><br>function ExtractAllMatchingLines($pagename, $pattern) {<br>    $page = ReadPage($pagename, READPAGE_CURRENT);<br>    if (!$page) return "Page non trouvée";<br><br>    $text = $page['text'];<br>    $lines = explode("\n", $text);<br>    $matches = [];<br><br>    foreach ($lines as $line) {<br>        if (@preg_match("/$pattern/", $line)) {<br>            $matches[] = Keep($line);  // Empêche le parsing wiki<br>        }<br>    }<br><br>    if (count($matches) > 0) {<br>        return implode("<br />\n", $matches);<br>    } else {<br>        return "Aucune ligne ne correspond au motif.";<br>    }<br>}<br></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Might be easy for smart people, but I'm still so admirative. For the result I get so quickly, and for the easy way to get it, fluently, in 3, 4 "conversational" steps. That's not something I would have expected 1 year ago. One more second and I believe you get the extracted line cleaned up from PmWiki markup if you need it.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">My question is two open questions :</div><div class="gmail_default" style="font-family:monospace"><br>1. is the Ai generated code well done ? Ok, it works, but is it well written ? secure enough ? doesn't it forget something important ? efficient enough for speed ? (I believe it is, because here it is something very basic).</div><div class="gmail_default" style="font-family:monospace">2. do you play with AI tools like ChapGPT, Deepseek, Mistral for improving your PmWiki ? What do you do (can we do something else than markups and recipes ?) Does it work fine for you ? Which AI do you find is the best for this kind of work ?</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Gilles.</div></div>
_______________________________________________<br>
pmwiki-users mailing list<br>
<a href="mailto:pmwiki-users@pmichaud.com" target="_blank">pmwiki-users@pmichaud.com</a><br>
<a href="http://www.pmichaud.com/mailman/listinfo/pmwiki-users" rel="noreferrer" target="_blank">http://www.pmichaud.com/mailman/listinfo/pmwiki-users</a><br>
</blockquote></div>