Typography¶
The Typography library contains methods that help you format text in semantically relevant ways.
ライブラリの読み込み¶
Like all services in CodeIgniter, it can be loaded via Config\Services
, though you usually will not need
to load it manually:
$typography = \Config\Services::typography();
Available static functions¶
The following functions are available:
autoTypography()
-
autoTypography
($str[, $reduce_linebreaks = FALSE])¶ パラメータ: - $str (string) -- Input string
- $reduce_linebreaks (bool) -- Whether to reduce multiple instances of double newlines to two
戻り値: HTML-formatted typography-safe string
戻り値の型: string
Formats text so that it is semantically and typographically correct HTML.
使用例:
$string = $typography->autoTypography($string);
注釈
Typographic formatting can be processor intensive, particularly if you have a lot of content being formatted. If you choose to use this function you may want to consider caching your pages.
formatCharacters()
-
formatCharacters
($str)¶ パラメータ: - $str (string) -- Input string
戻り値: String with formatted characters.
戻り値の型: string
This function mainly converts double and single quotes to curly entities, but it also converts em-dashes, double spaces, and ampersands.
使用例:
$string = $typography->formatCharacters($string);
nl2brExceptPre()
-
nl2brExceptPre
($str)¶ パラメータ: - $str (string) -- Input string
戻り値: String with HTML-formatted line breaks
戻り値の型: string
Converts newlines to <br /> tags unless they appear within <pre> tags. This function is identical to the native PHP
nl2br()
function, except that it ignores <pre> tags.使用例:
$string = $typography->nl2brExceptPre($string);