WordPress.org

Ready to get started?Download WordPress

Forums

Crayon Syntax Highlighter
Request: Add a filter for the code before it gets parsed (1 post)

  1. umchal
    Member
    Posted 12 months ago #

    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/

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.