AbcExt.php

<?php

namespace Tlf\Scrawl\Test\Ext;

/**
 * Test regex matching ... Not a great implementation
 */
class AbcExt extends \Tlf\Scrawl\ExtensionType\DefaultExt {

    
    ///////
    // define your regexes
    ///////
    public $regData = [
        'Abc' => 
            //For this regex: $1 is the key, $2 is the code, $3 is the @export_end line
            '/abc/',
    ];

    ///////
    // define a function to handle regex matches
    ///////
    /**
     *
     * @param $info a special info array generated by BetterRegex
     * @param $file a file object. @see onTemplateFileFound()
     */
    public function matchAbc($info, $file){
        //replace the match with '000' because ... examples
        $fixed = str_replace('abc', '000', $info['string']);
        $file->content = str_replace($info['string'], $fixed, $file->content);
    }
    //////
    // Use a hook to invoke regex matching
    // Probably onTemplateFileFound or onSourceFileFound
    //////
    public function onTemplateFileFound($file){
        // in case you only want to run on one file
        if (basename($file->path)!='RegexTest.src.md')return;
        $this->match('Abc',$file, $file);
        $out_file = substr($file->relPath,0,-7).'.md';
        $this->scrawl->setOutput('file', $out_file, $file);
    }

}