]*>(\s*)<\/span>/', '\1', $highlighter->highlight($codeblock));
return "highlightCssClass}\">".$output."
";
}
else
return "".CHtml::encode($codeblock)."
";
}
/**
* Returns the user-entered highlighting options.
* @param string $codeblock code block with highlighting options.
* @return string the user-entered highlighting options. Null if no option is entered.
*/
protected function getHighlightTag($codeblock)
{
$str = trim(current(preg_split("/\r|\n/", $codeblock,2)));
if(strlen($str) > 2 && $str[0] === '[' && $str[strlen($str)-1] === ']')
return $str;
}
/**
* Creates a highlighter instance.
* @param string $options the user-entered options
* @return Text_Highlighter the highlighter instance
*/
protected function createHighLighter($options)
{
if(!class_exists('Text_Highlighter', false))
{
require_once(Yii::getPathOfAlias('system.vendors.TextHighlighter.Text.Highlighter').'.php');
require_once(Yii::getPathOfAlias('system.vendors.TextHighlighter.Text.Highlighter.Renderer.Html').'.php');
}
$lang = current(preg_split('/\s+/', substr(substr($options,1), 0,-1),2));
$highlighter = Text_Highlighter::factory($lang);
if($highlighter)
$highlighter->setRenderer(new Text_Highlighter_Renderer_Html($this->getHighlightConfig($options)));
return $highlighter;
}
/**
* Generates the config for the highlighter.
* @param string $options user-entered options
* @return array the highlighter config
*/
public function getHighlightConfig($options)
{
$config = array('use_language'=>true);
if( $this->getInlineOption('showLineNumbers', $options, false) )
$config['numbers'] = HL_NUMBERS_LI;
$config['tabsize'] = $this->getInlineOption('tabSize', $options, 4);
return $config;
}
/**
* Generates the config for the highlighter.
*
* NOTE: This method is deprecated due to a mistake in the method name.
* Use {@link getHighlightConfig} instead of this.
*
* @param string $options user-entered options
* @return array the highlighter config
*/
public function getHiglightConfig($options)
{
return $this->getHighlightConfig($options);
}
/**
* Retrieves the specified configuration.
* @param string $name the configuration name
* @param string $str the user-entered options
* @param mixed $defaultValue default value if the configuration is not present
* @return mixed the configuration value
*/
protected function getInlineOption($name, $str, $defaultValue)
{
if(preg_match('/'.$name.'(\s*=\s*(\d+))?/i', $str, $v) && count($v) > 2)
return $v[2];
else
return $defaultValue;
}
}