tags var $block_elements = 'p|div|blockquote|pre|code|h\d|script|ol|ul'; // Elements that should not have
and and /' => '$1', // )+#' => ' )+/' => ' ',
// Clean up stray paragraph tags that appear before block level elements
'# \n* tags or ", $str);
$str = preg_replace("/([^\n])(\n)([^\n])/", "\\1 '.$str.'
tags within them.
var $skip_elements = 'p|pre|ol|ul';
// Tags we want the parser to completely ignore when splitting the string.
var $ignore_elements = 'a|b|i|em|strong|span|img|li';
// Whether to allow Javascript event handlers to be sumitted inside tags
var $allow_js_event_handlers = FALSE;
// Whether to reduce more than two consecutive empty lines to a maximum of two
var $reduce_empty_lines = FALSE;
/**
* Nothing to do here...
*
*/
function CI_Typography()
{
}
/**
* Main Processing Function
*
*/
function convert($str)
{
if ($str == '')
{
return '';
}
// Standardize Newlines to make matching easier
if (strpos($str, "\r") !== FALSE)
{
$str = str_replace(array("\r\n", "\r"), "\n", $str);
}
// Reduce line breaks. If there are more than two consecutive linebreaks
// we'll compress them down to a maximum of two since there's no benefit to more.
if ($this->reduce_empty_lines == TRUE)
{
$str = preg_replace("/\n\n+/", "\n\n", $str);
}
// Do we allow JavaScript event handlers? If not, we strip them from within all tags
if ($this->allow_js_event_handlers == FALSE)
{
$str = preg_replace("#<([^><]+?)([^a-z_\-]on\w*|xmlns)(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str);
}
// Convert quotes within tags to temporary markers. We don't want quotes converted
// within tags so we'll temporarily convert them to {@DQ} and {@SQ}
if (preg_match_all("#\<.+?>#si", $str, $matches))
{
for ($i = 0; $i < count($matches['0']); $i++)
{
$str = str_replace($matches['0'][$i],
str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]),
$str);
}
}
// Convert "ignore" tags to temporary marker. The parser splits out the string at every tag
// it encounters. Certain inline tags, like image tags, links, span tags, etc. will be
// adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG}
$str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str);
// Split the string at every tag. This expression creates an array with this prototype:
//
// [array]
// {
// [0] = tags and a few other things.
if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match))
{
if (preg_match("#".$this->skip_elements."#", $match[2]))
{
$process = ($match[1] == '/') ? TRUE : FALSE;
}
$str .= $chunk;
continue;
}
if ($process == FALSE)
{
$str .= $chunk;
continue;
}
// Convert Newlines into
tags
$str .= $this->format_newlines($chunk);
}
// Convert quotes, elipsis, and em-dashes
$str = $this->format_characters($str);
// Final clean up
$table = array(
// If the user submitted their own paragraph tags within the text
// we will retain them instead of using our tags.
'/(
*
*/
function format_newlines($str)
{
if ($str == '')
{
return $str;
}
if (strpos($str, "\n") === FALSE)
{
return $str;
}
$str = str_replace("\n\n", "
\\2\\3", $str);
return '