Skip to content

Instantly share code, notes, and snippets.

@jenswittmann
Last active November 18, 2015 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenswittmann/13448acf1930639beca1 to your computer and use it in GitHub Desktop.
Save jenswittmann/13448acf1930639beca1 to your computer and use it in GitHub Desktop.
MODX Redactor replace inline CSS and add SrcSet: http://jens-wittmann.de/codeschnipsel/redactor-editor.html
<?php
$o = $input;
// replace inline css
$o = preg_replace('/(<[^>]+) style=".*"/iU', '$1', $o);
// remove paragraph around img and iframe
$o = preg_replace('/<p>\s*(<img.*>)\s*<\/p>/iU', '$1', $o);
$o = preg_replace('/<p>\s*(<iframe.*>\s*<\/iframe>)\s*<\/p>/iU', '$1', $o);
// add srcset
$o = preg_replace('/<img src="(.*)".*>/iU', '<img src="[[pthumb? &input=`$1` &options=`w=1000`]]" srcset="[[pthumb? &input=`$1` &options=`w=500`]] 500w, [[pthumb? &input=`$1` &options=`w=1500`]] 1500w" $2>', $o);
return $o;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment