typography.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="utf-8" lang="utf-8">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0" />
  6. <title>排版类 - CodeIgniter 中文手册|用户手册|用户指南|Wiki文档</title>
  7. <link rel="shortcut icon" href="http://codeigniter.org.cn/user_guide/../images/design/favicon.ico" type="image/x-icon" />
  8. <link rel="stylesheet" type="text/css" media="all" href="../userguide.css" />
  9. <link rel="search" href="http://codeigniter.org.cn/user_guide/../CodeIgniterSearch.xml" type="application/opensearchdescription+xml" title="CodeIgniter 搜索"/>
  10. <link rel="canonical" href="http://codeigniter.org.cn/user_guide/libraries/typography.html" />
  11. <script type="text/javascript" src="../nav/mootools.js-ver=20130324.js"></script>
  12. <script type="text/javascript" src="../nav/mootools-more.js-ver=20130324.js"></script>
  13. <script type="text/javascript" src="../nav/nav.js-ver=20130324.js"></script>
  14. <script type="text/javascript" src="../nav/user_guide_menu.js-ver=20130324.js"></script>
  15. <meta name="robots" content="all" />
  16. <meta name="author" content="ExpressionEngine Dev Team" />
  17. <meta name="description" content="CodeIgniter 中文手册, CodeIgniter 用户指南, CodeIgniter User Guide, Wiki 文档" />
  18. </head>
  19. <body>
  20. <!-- START NAVIGATION -->
  21. <div id="nav">
  22. <div id="nav_inner">
  23. <script type="text/javascript">create_menu('../');</script>
  24. </div>
  25. </div>
  26. <script type="text/javascript">_setNavigation();</script>
  27. <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="切换目录" alt="切换目录" /></a></div>
  28. <div id="masthead" class="clearfix">
  29. <div class="topbar-hd"><h1>CodeIgniter 用户指南 版本 2.2.0</h1></div>
  30. <div class="topbar-tip">编辑文档、查看近期更改请 <a href="#">登录</a> 或 <a href="#">注册</a>  <a href="#">找回密码</a></div> <div id="breadcrumb_right"><a href="../toc.html">目录页</a></div>
  31. </div>
  32. <!-- END NAVIGATION -->
  33. <!-- START BREADCRUMB -->
  34. <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
  35. <tr>
  36. <td id="breadcrumb">
  37. <a href="#" target="_blank">CodeIgniter 中国首页</a>&nbsp;&#8250;&nbsp;
  38. <a href="../index.html">用户指南首页</a>&nbsp;&#8250;&nbsp;排版类 </td>
  39. <td id="searchbox">
  40. <form method="get" action="http://www.google.com.hk/search" target="google_window">
  41. <input type="hidden" name="client" value="pub-0176846097796333"></input>
  42. <input type="hidden" name="forid" value="1"></input>
  43. <input type="hidden" name="ie" value="UTF-8"></input>
  44. <input type="hidden" name="oe" value="UTF-8"></input>
  45. <input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.org.cn/user_guide/" />
  46. 搜索用户指南&nbsp;
  47. <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />
  48. &nbsp;
  49. <input type="submit" class="submit" name="sa" value="Go" />
  50. </form>
  51. </td>
  52. </tr>
  53. </table>
  54. <!-- END BREADCRUMB -->
  55. <div style="clear:both;text-align:right;padding: 6px 40px 0 0;">
  56. <a href="#" target="_blank">查看原文</a>
  57. </div>
  58. <!--<br clear="all" />--><!-- START CONTENT -->
  59. <div id="content">
  60. <h1>排版类</h1>
  61. <p>排版类提供帮助你格式化文本的函数。</p>
  62. <h2>初始化排版类</h2>
  63. <p>和CI中的其他类一样, 排版类也需要在控制器中这样用 <dfn>$this-&gt;load-&gt;library</dfn> 方法初始化:</p>
  64. <code>$this-&gt;load-&gt;library('typography');</code>
  65. <p>一旦被加载, 排版类的对象就可以这样使用: <dfn>$this-&gt;typography</dfn></p>
  66. <h2>auto_typography()</h2>
  67. <p>格式化文本以便纠正语义和印刷的错误HTML代码。输入一个字符串输出如下的格式化文本:</p>
  68. <ul>
  69. <li>用一对P标签包住段落(看起来像是用两个换行符把段落分隔开似的)。</li>
  70. <li>除了出现 &lt;pre&gt; 标签外,所有的单个换行符被转换为 &lt;br /&gt;。</li>
  71. <li>块级别的元素,如&lt;div&gt;标签,没有被段落包装,但是如果他们包含段落的话就会包含文本。</li>
  72. <li>除了出现在标签中的引号外,引号会被转换成正确的实体。</li>
  73. <li>撇号“'”被转换为相应的实体。</li>
  74. <li>双破折号 (像 -- 或--) 被转换成 em&#8212;破折号.</li>
  75. <li>三个连续的点也会被转换为省略号&#8230;</li>
  76. <li>句子后连续的多个空格将被转换为&amp;nbsp;以便在网页中显示。</li>
  77. </ul>
  78. <p>例如:</p>
  79. <code>$string = $this-&gt;typography-&gt;auto_typography($string);</code>
  80. <h3>参数</h3>
  81. <p>有一个可选参数:布尔值 <kbd>TRUE</kbd> 或 <kbd>FALSE</kbd>决定是否对超过两个的换行进行压缩,减少到两行。</p>
  82. <p>默认不压缩. 也就是说, 如果这个参数不设置, 它将如下工作:</p>
  83. <code>$string = $this-&gt;typography-&gt;auto_typography($string, <kbd>FALSE</kbd>);</code>
  84. <p class="important"><strong>提示:</strong> 排版格式化可以处理密集数据, 特别是你有很多内容需要格式化处理。如果你选择这个函数处理,你可以考虑<a href="../general/caching.html">缓存</a>你的网页。</p>
  85. <h2>format_characters()</h2>
  86. <p>This function is similar to the <dfn>auto_typography</dfn> function above, except that it only does character conversion:</p>
  87. <p><strong>试翻译:</strong>此函数与上面出现的<dfn>auto_typography</dfn>函数类似, 唯一不同的是此函数仅对以下字符进行转换:</p>
  88. <ul>
  89. <li>Quotes are converted to correctly facing curly quote entities, except those that appear within tags.</li>
  90. <li><strong>试翻译:</strong>除了在标签中的引号外,其他引号将被转换成字符实体.</li>
  91. <li>Apostrophes are converted to curly apostrophe entities.</li>
  92. <li><strong>试翻译:</strong>省略号将被转换成正确的格式.</li>
  93. <li>Double dashes (either like -- this or like--this) are converted to em&#8212;dashes.</li>
  94. <li><strong>试翻译:</strong>双破折号(比如 -- 或--) 将被转换成 em&#8212;符号.</li>
  95. <li>Three consecutive periods either preceding or following a word are converted to ellipsis&#8230;</li>
  96. <li><strong>试翻译:</strong>任何位置(词前或词后)的三个连续点号将被转换成省略号&#8230;</li>
  97. <li>Double spaces following sentences are converted to non-breaking spaces to mimic double spacing.</li>
  98. <li><strong>试翻译:</strong>句末的双空格将被转换成看似双空格的一个整体符号.</li>
  99. </ul>
  100. <p>Usage example:</p>
  101. <p><strong>试翻译:</strong> 例子:</p>
  102. <code>$string = $this-&gt;typography-&gt;format_characters($string);</code>
  103. <h2>nl2br_except_pre()</h2>
  104. <p>Converts newlines to &lt;br /&gt; tags unless they appear within &lt;pre&gt; tags.
  105. This function is identical to the native PHP <dfn>nl2br()</dfn> function, except that it ignores &lt;pre&gt; tags.</p>
  106. <p><strong>试翻译:</strong> 除了 &lt;pre&gt; 标签内的新行,将被转换为 &lt;br /&gt; 标签.
  107. 除了本函(方法)数支持 &lt;pre&gt; 标签外, 其与PHP内置函数 <dfn>nl2br()</dfn> 相同.</p>
  108. <p>Usage example:</p>
  109. <p><strong>试翻译:</strong>例子:</p>
  110. <code>$string = $this-&gt;typography-&gt;nl2br_except_pre($string);</code>
  111. <h2>protect_braced_quotes</h2>
  112. <p>When using the Typography library in conjunction with the Template Parser library it can often be desirable to protect single
  113. and double quotes within curly braces. To enable this, set the <kbd>protect_braced_quotes</kbd> class property to <samp>TRUE</samp>.</p>
  114. <p><strong>试翻译:</strong> 当排版类与模板解析器类结合使用时,为了使显示正常,经常需要把单引号和双引号放在大括号中。如果你是这种情况,可以把<kbd>protect_braced_quotes</kbd>类属性设置为 <samp>TRUE</samp>.</p>
  115. <p>Usage example:</p>
  116. <p><strong>试翻译:</strong>例子:</p>
  117. <code>$this-&gt;load-&gt;library('typography');<br />
  118. $this-&gt;typography-&gt;protect_braced_quotes = TRUE;
  119. </code><p>&nbsp;</p>
  120. <div id="Contributors">
  121. 翻译贡献者:
  122. drazzi, Hex, icebird, neversaylate, noproblem, tonera, zhou78620051</div>
  123. <div id="DocDate">
  124. 最后修改: 2012-11-14 14:56:28</div>
  125. </div>
  126. <!-- END CONTENT -->
  127. <div id="footer">
  128. <p>
  129. 上一个主题:&nbsp;&nbsp;<a href="parser.html">模板解析器</a>&nbsp;&nbsp;&middot;&nbsp;&nbsp;<a href="#top">页首</a>
  130. &nbsp;&middot;&nbsp;&nbsp;<a href="../index.html">用户指南首页</a>&nbsp;&nbsp;&middot;&nbsp;&nbsp;下一个主题:&nbsp;&nbsp;<a href="unit_testing.html">单元测试类</a> </p>
  131. <p><a href="#">CodeIgniter</a> &nbsp;&middot;&nbsp; 版权所有 &#169; 2006-2013 &nbsp;&middot;&nbsp; <a href="#">Ellislab, Inc.</a></p>
  132. <p>中文化: <a href="#">CodeIgniter 中国</a> &nbsp;&middot;&nbsp; 制作: Hex &nbsp;&middot;&nbsp; 版本: 1.30 &nbsp;&middot;&nbsp; 鸣谢: 子非鱼</p>
  133. </div>
  134. </body>
  135. </html>