Skip to content

Instantly share code, notes, and snippets.

@leotop
Last active January 28, 2018 18:17
Show Gist options
  • Save leotop/1837342ab09b36aeb3dd05947d5f8583 to your computer and use it in GitHub Desktop.
Save leotop/1837342ab09b36aeb3dd05947d5f8583 to your computer and use it in GitHub Desktop.
MODX плагин, на событие OnLoadWebDocument. Преобразует теги MODX и экранирует html символы внутри конструкции <pre><code> </code></pre>
<?php
function replace_modxtags($matches){
$code_entities_match = array('[', ']','{', '}', '!', '`', '*', '~');
$code_entities_replace = array('&#91;','&#93;','&#123;','&#125;', '&#033;', '&#96;', '&#42;', '&#126;');
$code = str_replace(
$code_entities_match,
$code_entities_replace,
htmlentities($matches[1], ENT_QUOTES)
);
return '<pre><code>'.$code.'</code></pre>';
}
$content = preg_replace_callback("#<pre><code>(.*?)</code></pre>#s", "replace_modxtags", $modx->resource->get('content'));
$modx->resource->set('content', $content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment