protected function compileTools($instanceId, $content)
{
return preg_replace_callback('!<(?:(div)|img)([^>]*)' . $this->selectorName . '=([^>]*)>(?(1)(.*?)</div>)!is', function ($match) use($instanceId) {
$script = " {$match[2]} {$this->selectorName}={$match[3]}";
$script = preg_replace('/([\\w:-]+)\\s*=(?:\\s*(["\']))?((?(2).*?|[^ ]+))\\2/i', '\\1="\\3"', $script);
preg_match_all('/([a-z0-9_-]+)="([^"]+)"/is', $script, $m);
$attributes = [];
for ($i = 0, $c = count($m[0]); $i < $c; $i++) {
$attributes[$m[1][$i]] = $m[2][$i];
}
if (!isset($attributes[$this->selectorName])) {
return $match[0];
}
/** @var AbstractTool $tool */
if ($tool = $this->getTool($attributes[$this->selectorName], $instanceId)) {
return $tool->compile($match[0]);
}
// 대상 editor tool 이 존재하지 않는 경우 해당 내용 삭제
return '';
}, $content);
}