• Hi,

    Nice plugin.

    I’m wondering if you can add a filter for the code string right before it is gets parsed.

    Case in point, I would suggest something like this.

    On line 221,

    function code($code = NULL) {
    		if ($code === NULL) {
    			return $this->code;
    		} else {
    
    			// Trim whitespace
    			if ($this->setting_val(CrayonSettings::TRIM_WHITESPACE)) {
    				$code = preg_replace("#(?:^\\s*\\r?\\n)|(?:\\r?\\n\\s*$)#", '', $code);
    			}

    Change it to

    function code($code = NULL) {
    		if ($code === NULL) {
    			return $this->code;
    		} else {
    
    			$code = apply_filters( 'crayon_highlighter_pre_code_format', $code );
    
    			// Trim whitespace
    			if ($this->setting_val(CrayonSettings::TRIM_WHITESPACE)) {
    				$code = preg_replace("#(?:^\\s*\\r?\\n)|(?:\\r?\\n\\s*$)#", '', $code);
    			}

    The filter name can be whatever suitable.

    This way, I can customize the behaviour of the plugin without editing the plugin code. I need to strip and replace some parts of the text before it gets parsed which are inserted automatically by my blog writer(text editor).

    Thanks for your consideration.

    http://wordpress.org/plugins/crayon-syntax-highlighter/

  • The topic ‘Request: Add a filter for the code before it gets parsed’ is closed to new replies.