From d95ebca78e200cb325dcf934492c83090cf2b462 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 1 Oct 2008 23:57:38 +0000 Subject: added $protect_braced_quotes to Typography class, to prevent curly-quoting single and double quoted string within {curly "braces"} --- system/libraries/Typography.php | 18 +++++++++++++++++- user_guide/libraries/typography.html | 10 ++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 59a96dfdb..2393e164e 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -35,6 +35,9 @@ class CI_Typography { // Tags we want the parser to completely ignore when splitting the string. var $inline_elements = 'a|abbr|acronym|b|bdo|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|samp|select|span|strong|sub|sup|textarea|var'; + // whether or not to protect quotes within { curly braces } + var $protect_braced_quotes = FALSE; + /** * Nothing to do here... * @@ -97,7 +100,20 @@ class CI_Typography { $str); } } - + + if ($this->protect_braced_quotes === TRUE) + { + 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} diff --git a/user_guide/libraries/typography.html b/user_guide/libraries/typography.html index 359c590ce..29219059c 100644 --- a/user_guide/libraries/typography.html +++ b/user_guide/libraries/typography.html @@ -135,6 +135,16 @@ This function is identical to the native PHP nl2br() function, except $string = $this->typography->nl2br_except_pre($string); +

protect_braced_quotes

+ +

When using the Typography library in conjunction with the Template Parser library it can often be desirable to protect single + and double quotes within curly braces. To enable this, set the protect_braced_quotes class property to TRUE. + +

Usage example:

+ +$this->load->library('typography');
+$this->typography->protect_braced_quotes = TRUE; +
-- cgit v1.2.3-24-g4f1b