system/libraries/Typography.php
.htaccess
AesEncryption.php
LICENSE
application
.htaccess
cache
index.html
config
autoload.php
config.php
constants.php
database.php
doctypes.php
foreign_chars.php
hooks.php
index.html
memcached.php
migration.php
mimes.php
profiler.php
routes.php
smileys.php
user_agents.php
controllers
Systemid.php
Welcome.php
index.html
core
index.html
helpers
index.html
hooks
index.html
index.html
language
english
index.html
system_lang.php
index.html
libraries
index.html
logs
index.html
models
System_model.php
index.html
third_party
index.html
views
about.php
category
addedit.php
addeditsub.php
components.php
delete.php
errors
cli
error_404.php
error_db.php
error_exception.php
error_general.php
error_php.php
index.html
html
error_404.php
error_db.php
error_exception.php
error_general.php
error_php.php
index.html
index.html
foot.php
generator.php
head.php
index.html
login.php
main.php
pass
addedit.php
show.php
welcome_message.php
captcha
sys.txt
favicon.ico
index.php
install.php
library
AesEncryption.php
bootstrap
css
.DS_Store
bootstrap-grid.css
bootstrap-grid.css.map
bootstrap-grid.min.css
bootstrap-grid.min.css.map
bootstrap-reboot.css
bootstrap-reboot.css.map
bootstrap-reboot.min.css
bootstrap-reboot.min.css.map
bootstrap.css
bootstrap.css.map
bootstrap.min.css
bootstrap.min.css.map
js
bootstrap.bundle.js
bootstrap.bundle.js.map
bootstrap.bundle.min.js
bootstrap.bundle.min.js.map
bootstrap.js
bootstrap.js.map
bootstrap.min.js
bootstrap.min.js.map
font-awesome
HELP-US-OUT.txt
css
font-awesome.css
font-awesome.min.css
fonts
FontAwesome.otf
fontawesome-webfont.eot
fontawesome-webfont.svg
fontawesome-webfont.ttf
fontawesome-webfont.woff
fontawesome-webfont.woff2
less
animated.less
bordered-pulled.less
core.less
fixed-width.less
font-awesome.less
icons.less
larger.less
list.less
mixins.less
path.less
rotated-flipped.less
screen-reader.less
stacked.less
variables.less
scss
_animated.scss
_bordered-pulled.scss
_core.scss
_fixed-width.scss
_icons.scss
_larger.scss
_list.scss
_mixins.scss
_path.scss
_rotated-flipped.scss
_screen-reader.scss
_stacked.scss
_variables.scss
font-awesome.scss
font-awesome.min.css
jquery-ui
AUTHORS.txt
LICENSE.txt
external
jquery
jquery.js
images
ui-icons_444444_256x240.png
ui-icons_555555_256x240.png
ui-icons_777620_256x240.png
ui-icons_777777_256x240.png
ui-icons_cc0000_256x240.png
ui-icons_ffffff_256x240.png
index.html
jquery-ui.css
jquery-ui.js
jquery-ui.min.css
jquery-ui.min.js
jquery-ui.structure.css
jquery-ui.structure.min.css
jquery-ui.theme.css
jquery-ui.theme.min.css
package.json
jquery.min.js
jquerysctipttop.css
logo.png
password_indicator_bs4
css
signin.css
index.html
js
jaktutorial.js
popper.min.js
right-click
css
contextMenu.min.css
js
contextMenu.min.js
style.css
tether
css
tether-theme-arrows-dark.css
tether-theme-arrows-dark.min.css
tether-theme-arrows.css
tether-theme-arrows.min.css
tether-theme-basic.css
tether-theme-basic.min.css
tether.css
tether.min.css
js
tether.js
tether.min.js
system
.htaccess
core
Benchmark.php
CodeIgniter.php
Common.php
Config.php
Controller.php
Exceptions.php
Hooks.php
Input.php
Lang.php
Loader.php
Log.php
Model.php
Output.php
Router.php
Security.php
URI.php
Utf8.php
compat
hash.php
index.html
mbstring.php
password.php
standard.php
index.html
database
DB.php
DB_cache.php
DB_driver.php
DB_forge.php
DB_query_builder.php
DB_result.php
DB_utility.php
drivers
cubrid
cubrid_driver.php
cubrid_forge.php
cubrid_result.php
cubrid_utility.php
index.html
ibase
ibase_driver.php
ibase_forge.php
ibase_result.php
ibase_utility.php
index.html
index.html
mssql
index.html
mssql_driver.php
mssql_forge.php
mssql_result.php
mssql_utility.php
mysql
index.html
mysql_driver.php
mysql_forge.php
mysql_result.php
mysql_utility.php
mysqli
index.html
mysqli_driver.php
mysqli_forge.php
mysqli_result.php
mysqli_utility.php
oci8
index.html
oci8_driver.php
oci8_forge.php
oci8_result.php
oci8_utility.php
odbc
index.html
odbc_driver.php
odbc_forge.php
odbc_result.php
odbc_utility.php
pdo
index.html
pdo_driver.php
pdo_forge.php
pdo_result.php
pdo_utility.php
subdrivers
index.html
pdo_4d_driver.php
pdo_4d_forge.php
pdo_cubrid_driver.php
pdo_cubrid_forge.php
pdo_dblib_driver.php
pdo_dblib_forge.php
pdo_firebird_driver.php
pdo_firebird_forge.php
pdo_ibm_driver.php
pdo_ibm_forge.php
pdo_informix_driver.php
pdo_informix_forge.php
pdo_mysql_driver.php
pdo_mysql_forge.php
pdo_oci_driver.php
pdo_oci_forge.php
pdo_odbc_driver.php
pdo_odbc_forge.php
pdo_pgsql_driver.php
pdo_pgsql_forge.php
pdo_sqlite_driver.php
pdo_sqlite_forge.php
pdo_sqlsrv_driver.php
pdo_sqlsrv_forge.php
postgre
index.html
postgre_driver.php
postgre_forge.php
postgre_result.php
postgre_utility.php
sqlite
index.html
sqlite_driver.php
sqlite_forge.php
sqlite_result.php
sqlite_utility.php
sqlite3
index.html
sqlite3_driver.php
sqlite3_forge.php
sqlite3_result.php
sqlite3_utility.php
sqlsrv
index.html
sqlsrv_driver.php
sqlsrv_forge.php
sqlsrv_result.php
sqlsrv_utility.php
index.html
fonts
index.html
texb.ttf
helpers
array_helper.php
captcha_helper.php
cookie_helper.php
date_helper.php
directory_helper.php
download_helper.php
email_helper.php
file_helper.php
form_helper.php
html_helper.php
index.html
inflector_helper.php
language_helper.php
number_helper.php
path_helper.php
security_helper.php
smiley_helper.php
string_helper.php
text_helper.php
typography_helper.php
url_helper.php
xml_helper.php
index.html
language
english
calendar_lang.php
date_lang.php
db_lang.php
email_lang.php
form_validation_lang.php
ftp_lang.php
imglib_lang.php
index.html
migration_lang.php
number_lang.php
pagination_lang.php
profiler_lang.php
unit_test_lang.php
upload_lang.php
index.html
libraries
Cache
Cache.php
drivers
Cache_apc.php
Cache_dummy.php
Cache_file.php
Cache_memcached.php
Cache_redis.php
Cache_wincache.php
index.html
index.html
Calendar.php
Cart.php
Driver.php
Email.php
Encrypt.php
Encryption.php
Form_validation.php
Ftp.php
Image_lib.php
Javascript
Jquery.php
index.html
Javascript.php
Migration.php
Pagination.php
Parser.php
Profiler.php
Session
Session.php
SessionHandlerInterface.php
Session_driver.php
drivers
Session_database_driver.php
Session_files_driver.php
Session_memcached_driver.php
Session_redis_driver.php
index.html
index.html
Table.php
Trackback.php
Typography.php
Unit_test.php
Upload.php
User_agent.php
Xmlrpc.php
Xmlrpcs.php
Zip.php
index.html
AesEncryption.php
LICENSE
application
.htaccess
cache
index.html
config
autoload.php
config.php
constants.php
database.php
doctypes.php
foreign_chars.php
hooks.php
index.html
memcached.php
migration.php
mimes.php
profiler.php
routes.php
smileys.php
user_agents.php
controllers
Systemid.php
Welcome.php
index.html
core
index.html
helpers
index.html
hooks
index.html
index.html
language
english
index.html
system_lang.php
index.html
libraries
index.html
logs
index.html
models
System_model.php
index.html
third_party
index.html
views
about.php
category
addedit.php
addeditsub.php
components.php
delete.php
errors
cli
error_404.php
error_db.php
error_exception.php
error_general.php
error_php.php
index.html
html
error_404.php
error_db.php
error_exception.php
error_general.php
error_php.php
index.html
index.html
foot.php
generator.php
head.php
index.html
login.php
main.php
pass
addedit.php
show.php
welcome_message.php
captcha
sys.txt
favicon.ico
index.php
install.php
library
AesEncryption.php
bootstrap
css
.DS_Store
bootstrap-grid.css
bootstrap-grid.css.map
bootstrap-grid.min.css
bootstrap-grid.min.css.map
bootstrap-reboot.css
bootstrap-reboot.css.map
bootstrap-reboot.min.css
bootstrap-reboot.min.css.map
bootstrap.css
bootstrap.css.map
bootstrap.min.css
bootstrap.min.css.map
js
bootstrap.bundle.js
bootstrap.bundle.js.map
bootstrap.bundle.min.js
bootstrap.bundle.min.js.map
bootstrap.js
bootstrap.js.map
bootstrap.min.js
bootstrap.min.js.map
font-awesome
HELP-US-OUT.txt
css
font-awesome.css
font-awesome.min.css
fonts
FontAwesome.otf
fontawesome-webfont.eot
fontawesome-webfont.svg
fontawesome-webfont.ttf
fontawesome-webfont.woff
fontawesome-webfont.woff2
less
animated.less
bordered-pulled.less
core.less
fixed-width.less
font-awesome.less
icons.less
larger.less
list.less
mixins.less
path.less
rotated-flipped.less
screen-reader.less
stacked.less
variables.less
scss
_animated.scss
_bordered-pulled.scss
_core.scss
_fixed-width.scss
_icons.scss
_larger.scss
_list.scss
_mixins.scss
_path.scss
_rotated-flipped.scss
_screen-reader.scss
_stacked.scss
_variables.scss
font-awesome.scss
font-awesome.min.css
jquery-ui
AUTHORS.txt
LICENSE.txt
external
jquery
jquery.js
images
ui-icons_444444_256x240.png
ui-icons_555555_256x240.png
ui-icons_777620_256x240.png
ui-icons_777777_256x240.png
ui-icons_cc0000_256x240.png
ui-icons_ffffff_256x240.png
index.html
jquery-ui.css
jquery-ui.js
jquery-ui.min.css
jquery-ui.min.js
jquery-ui.structure.css
jquery-ui.structure.min.css
jquery-ui.theme.css
jquery-ui.theme.min.css
package.json
jquery.min.js
jquerysctipttop.css
logo.png
password_indicator_bs4
css
signin.css
index.html
js
jaktutorial.js
popper.min.js
right-click
css
contextMenu.min.css
js
contextMenu.min.js
style.css
tether
css
tether-theme-arrows-dark.css
tether-theme-arrows-dark.min.css
tether-theme-arrows.css
tether-theme-arrows.min.css
tether-theme-basic.css
tether-theme-basic.min.css
tether.css
tether.min.css
js
tether.js
tether.min.js
system
.htaccess
core
Benchmark.php
CodeIgniter.php
Common.php
Config.php
Controller.php
Exceptions.php
Hooks.php
Input.php
Lang.php
Loader.php
Log.php
Model.php
Output.php
Router.php
Security.php
URI.php
Utf8.php
compat
hash.php
index.html
mbstring.php
password.php
standard.php
index.html
database
DB.php
DB_cache.php
DB_driver.php
DB_forge.php
DB_query_builder.php
DB_result.php
DB_utility.php
drivers
cubrid
cubrid_driver.php
cubrid_forge.php
cubrid_result.php
cubrid_utility.php
index.html
ibase
ibase_driver.php
ibase_forge.php
ibase_result.php
ibase_utility.php
index.html
index.html
mssql
index.html
mssql_driver.php
mssql_forge.php
mssql_result.php
mssql_utility.php
mysql
index.html
mysql_driver.php
mysql_forge.php
mysql_result.php
mysql_utility.php
mysqli
index.html
mysqli_driver.php
mysqli_forge.php
mysqli_result.php
mysqli_utility.php
oci8
index.html
oci8_driver.php
oci8_forge.php
oci8_result.php
oci8_utility.php
odbc
index.html
odbc_driver.php
odbc_forge.php
odbc_result.php
odbc_utility.php
pdo
index.html
pdo_driver.php
pdo_forge.php
pdo_result.php
pdo_utility.php
subdrivers
index.html
pdo_4d_driver.php
pdo_4d_forge.php
pdo_cubrid_driver.php
pdo_cubrid_forge.php
pdo_dblib_driver.php
pdo_dblib_forge.php
pdo_firebird_driver.php
pdo_firebird_forge.php
pdo_ibm_driver.php
pdo_ibm_forge.php
pdo_informix_driver.php
pdo_informix_forge.php
pdo_mysql_driver.php
pdo_mysql_forge.php
pdo_oci_driver.php
pdo_oci_forge.php
pdo_odbc_driver.php
pdo_odbc_forge.php
pdo_pgsql_driver.php
pdo_pgsql_forge.php
pdo_sqlite_driver.php
pdo_sqlite_forge.php
pdo_sqlsrv_driver.php
pdo_sqlsrv_forge.php
postgre
index.html
postgre_driver.php
postgre_forge.php
postgre_result.php
postgre_utility.php
sqlite
index.html
sqlite_driver.php
sqlite_forge.php
sqlite_result.php
sqlite_utility.php
sqlite3
index.html
sqlite3_driver.php
sqlite3_forge.php
sqlite3_result.php
sqlite3_utility.php
sqlsrv
index.html
sqlsrv_driver.php
sqlsrv_forge.php
sqlsrv_result.php
sqlsrv_utility.php
index.html
fonts
index.html
texb.ttf
helpers
array_helper.php
captcha_helper.php
cookie_helper.php
date_helper.php
directory_helper.php
download_helper.php
email_helper.php
file_helper.php
form_helper.php
html_helper.php
index.html
inflector_helper.php
language_helper.php
number_helper.php
path_helper.php
security_helper.php
smiley_helper.php
string_helper.php
text_helper.php
typography_helper.php
url_helper.php
xml_helper.php
index.html
language
english
calendar_lang.php
date_lang.php
db_lang.php
email_lang.php
form_validation_lang.php
ftp_lang.php
imglib_lang.php
index.html
migration_lang.php
number_lang.php
pagination_lang.php
profiler_lang.php
unit_test_lang.php
upload_lang.php
index.html
libraries
Cache
Cache.php
drivers
Cache_apc.php
Cache_dummy.php
Cache_file.php
Cache_memcached.php
Cache_redis.php
Cache_wincache.php
index.html
index.html
Calendar.php
Cart.php
Driver.php
Email.php
Encrypt.php
Encryption.php
Form_validation.php
Ftp.php
Image_lib.php
Javascript
Jquery.php
index.html
Javascript.php
Migration.php
Pagination.php
Parser.php
Profiler.php
Session
Session.php
SessionHandlerInterface.php
Session_driver.php
drivers
Session_database_driver.php
Session_files_driver.php
Session_memcached_driver.php
Session_redis_driver.php
index.html
index.html
Table.php
Trackback.php
Typography.php
Unit_test.php
Upload.php
User_agent.php
Xmlrpc.php
Xmlrpcs.php
Zip.php
index.html
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Typography Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Helpers
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/typography.html
*/
class CI_Typography {
/**
* Block level elements that should not be wrapped inside <p> tags
*
* @var string
*/
public $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';
/**
* Elements that should not have <p> and <br /> tags within them.
*
* @var string
*/
public $skip_elements = 'p|pre|ol|ul|dl|object|table|h\d';
/**
* Tags we want the parser to completely ignore when splitting the string.
*
* @var string
*/
public $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var';
/**
* array of block level elements that require inner content to be within another block level element
*
* @var array
*/
public $inner_block_required = array('blockquote');
/**
* the last block element parsed
*
* @var string
*/
public $last_block_element = '';
/**
* whether or not to protect quotes within { curly braces }
*
* @var bool
*/
public $protect_braced_quotes = FALSE;
/**
* Auto Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
* - Converts two spaces into entities
*
* @param string
* @param bool whether to reduce more then two consecutive newlines to two
* @return string
*/
public function auto_typography($str, $reduce_linebreaks = FALSE)
{
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 ($reduce_linebreaks === TRUE)
{
$str = preg_replace("/\n\n+/", "\n\n", $str);
}
// HTML comment tags don't conform to patterns of normal tags, so pull them out separately, only if needed
$html_comments = array();
if (strpos($str, '<!--') !== FALSE && preg_match_all('#(<!\-\-.*?\-\->)#s', $str, $matches))
{
for ($i = 0, $total = count($matches[0]); $i < $total; $i++)
{
$html_comments[] = $matches[0][$i];
$str = str_replace($matches[0][$i], '{@HC'.$i.'}', $str);
}
}
// match and yank <pre> tags if they exist. It's cheaper to do this separately since most content will
// not contain <pre> tags, and it keeps the PCRE patterns below simpler and faster
if (strpos($str, '<pre') !== FALSE)
{
$str = preg_replace_callback('#<pre.*?>.*?</pre>#si', array($this, '_protect_characters'), $str);
}
// Convert quotes within tags to temporary markers.
$str = preg_replace_callback('#<.+?>#si', array($this, '_protect_characters'), $str);
// Do the same with braces if necessary
if ($this->protect_braced_quotes === TRUE)
{
$str = preg_replace_callback('#\{.+?\}#si', array($this, '_protect_characters'), $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->inline_elements.')([ >])#i', '{@TAG}\\1\\2\\3', $str);
/* Split the string at every tag. This expression creates an array with this prototype:
*
* [array]
* {
* [0] = <opening tag>
* [1] = Content...
* [2] = <closing tag>
* Etc...
* }
*/
$chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
// Build our finalized string. We cycle through the array, skipping tags, and processing the contained text
$str = '';
$process = TRUE;
for ($i = 0, $c = count($chunks) - 1; $i <= $c; $i++)
{
// Are we dealing with a tag? If so, we'll skip the processing for this cycle.
// Well also set the "process" flag which allows us to skip <pre> tags and a few other things.
if (preg_match('#<(/*)('.$this->block_elements.').*?>#', $chunks[$i], $match))
{
if (preg_match('#'.$this->skip_elements.'#', $match[2]))
{
$process = ($match[1] === '/');
}
if ($match[1] === '')
{
$this->last_block_element = $match[2];
}
$str .= $chunks[$i];
continue;
}
if ($process === FALSE)
{
$str .= $chunks[$i];
continue;
}
// Force a newline to make sure end tags get processed by _format_newlines()
if ($i === $c)
{
$chunks[$i] .= "\n";
}
// Convert Newlines into <p> and <br /> tags
$str .= $this->_format_newlines($chunks[$i]);
}
// No opening block level tag? Add it if needed.
if ( ! preg_match('/^\s*<(?:'.$this->block_elements.')/i', $str))
{
$str = preg_replace('/^(.*?)<('.$this->block_elements.')/i', '<p>$1</p><$2', $str);
}
// Convert quotes, elipsis, em-dashes, non-breaking spaces, and ampersands
$str = $this->format_characters($str);
// restore HTML comments
for ($i = 0, $total = count($html_comments); $i < $total; $i++)
{
// remove surrounding paragraph tags, but only if there's an opening paragraph tag
// otherwise HTML comments at the ends of paragraphs will have the closing tag removed
// if '<p>{@HC1}' then replace <p>{@HC1}</p> with the comment, else replace only {@HC1} with the comment
$str = preg_replace('#(?(?=<p>\{@HC'.$i.'\})<p>\{@HC'.$i.'\}(\s*</p>)|\{@HC'.$i.'\})#s', $html_comments[$i], $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.
'/(<p[^>*?]>)<p>/' => '$1', // <?php BBEdit syntax coloring bug fix
// Reduce multiple instances of opening/closing paragraph tags to a single one
'#(</p>)+#' => '</p>',
'/(<p>\W*<p>)+/' => '<p>',
// Clean up stray paragraph tags that appear before block level elements
'#<p></p><('.$this->block_elements.')#' => '<$1',
// Clean up stray non-breaking spaces preceding block elements
'#( \s*)+<('.$this->block_elements.')#' => ' <$2',
// Replace the temporary markers we added earlier
'/\{@TAG\}/' => '<',
'/\{@DQ\}/' => '"',
'/\{@SQ\}/' => "'",
'/\{@DD\}/' => '--',
'/\{@NBS\}/' => ' ',
// An unintended consequence of the _format_newlines function is that
// some of the newlines get truncated, resulting in <p> tags
// starting immediately after <block> tags on the same line.
// This forces a newline after such occurrences, which looks much nicer.
"/><p>\n/" => ">\n<p>",
// Similarly, there might be cases where a closing </block> will follow
// a closing </p> tag, so we'll correct it by adding a newline in between
'#</p></#' => "</p>\n</"
);
// Do we need to reduce empty lines?
if ($reduce_linebreaks === TRUE)
{
$table['#<p>\n*</p>#'] = '';
}
else
{
// If we have empty paragraph tags we add a non-breaking space
// otherwise most browsers won't treat them as true paragraphs
$table['#<p></p>#'] = '<p> </p>';
}
return preg_replace(array_keys($table), $table, $str);
}
// --------------------------------------------------------------------
/**
* Format Characters
*
* This function mainly converts double and single quotes
* to curly entities, but it also converts em-dashes,
* double spaces, and ampersands
*
* @param string
* @return string
*/
public function format_characters($str)
{
static $table;
if ( ! isset($table))
{
$table = array(
// nested smart quotes, opening and closing
// note that rules for grammar (English) allow only for two levels deep
// and that single quotes are _supposed_ to always be on the outside
// but we'll accommodate both
// Note that in all cases, whitespace is the primary determining factor
// on which direction to curl, with non-word characters like punctuation
// being a secondary factor only after whitespace is addressed.
'/\'"(\s|$)/' => '’”$1',
'/(^|\s|<p>)\'"/' => '$1‘“',
'/\'"(\W)/' => '’”$1',
'/(\W)\'"/' => '$1‘“',
'/"\'(\s|$)/' => '”’$1',
'/(^|\s|<p>)"\'/' => '$1“‘',
'/"\'(\W)/' => '”’$1',
'/(\W)"\'/' => '$1“‘',
// single quote smart quotes
'/\'(\s|$)/' => '’$1',
'/(^|\s|<p>)\'/' => '$1‘',
'/\'(\W)/' => '’$1',
'/(\W)\'/' => '$1‘',
// double quote smart quotes
'/"(\s|$)/' => '”$1',
'/(^|\s|<p>)"/' => '$1“',
'/"(\W)/' => '”$1',
'/(\W)"/' => '$1“',
// apostrophes
"/(\w)'(\w)/" => '$1’$2',
// Em dash and ellipses dots
'/\s?\-\-\s?/' => '—',
'/(\w)\.{3}/' => '$1…',
// double space after sentences
'/(\W) /' => '$1 ',
// ampersands, if not a character entity
'/&(?!#?[a-zA-Z0-9]{2,};)/' => '&'
);
}
return preg_replace(array_keys($table), $table, $str);
}
// --------------------------------------------------------------------
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
*
* @param string
* @return string
*/
protected function _format_newlines($str)
{
if ($str === '' OR (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)))
{
return $str;
}
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);
// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n")
{
// We trim off the right-side new line so that the closing </p> tag
// will be positioned immediately following the string, matching
// the behavior of the opening <p> tag
$str = '<p>'.rtrim($str).'</p>';
}
// Remove empty paragraphs if they are on the first line, as this
// is a potential unintended consequence of the previous code
return preg_replace('/<p><\/p>(.*)/', '\\1', $str, 1);
}
// ------------------------------------------------------------------------
/**
* Protect Characters
*
* Protects special characters from being formatted later
* We don't want quotes converted within tags so we'll temporarily convert them to {@DQ} and {@SQ}
* and we don't want double dashes converted to emdash entities, so they are marked with {@DD}
* likewise double spaces are converted to {@NBS} to prevent entity conversion
*
* @param array
* @return string
*/
protected function _protect_characters($match)
{
return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]);
}
// --------------------------------------------------------------------
/**
* Convert newlines to HTML line breaks except within PRE tags
*
* @param string
* @return string
*/
public function nl2br_except_pre($str)
{
$newstr = '';
for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++)
{
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
if ($ct - 1 !== $i)
{
$newstr .= 'pre>';
}
}
return $newstr;
}
}