cvs: peardoc /en/package text.xml /en/package/text text-highlighter.xml

From: Date: Sun, 09 Apr 2006 19:50:39 +0000
Subject: cvs: peardoc /en/package text.xml /en/package/text text-highlighter.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-7770@lists.php.net to get a copy of this message
mj Sun Apr 9 19:50:39 2006 UTC Added files: /peardoc/en/package/text text-highlighter.xml Modified files: /peardoc/en/package text.xml Log: * Documentation for Text_Highlighter.

http://cvs.php.net/viewcvs.cgi/peardoc/en/package/text.xml?r1=1.8&r2=1.9&diff_format=u Index: peardoc/en/package/text.xml diff -u peardoc/en/package/text.xml:1.8 peardoc/en/package/text.xml:1.9 --- peardoc/en/package/text.xml:1.8 Fri Feb 17 16:04:31 2006 +++ peardoc/en/package/text.xml Sun Apr 9 19:50:39 2006 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <chapter id="package.text"> <title>Text</title> <titleabbrev>Text</titleabbrev> @@ -10,6 +10,7 @@ &blankpagehack; &package.text.text-captcha; + &package.text.text-highlighter; &package.text.text-password; &package.text.text-statistics; &package.text.text-wiki; http://cvs.php.net/viewcvs.cgi/peardoc/en/package/text/text-highlighter.xml?view=markup&rev=1.1 Index: peardoc/en/package/text/text-highlighter.xml +++ peardoc/en/package/text/text-highlighter.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.text.text-highlighter"> <title>Text_Highlighter</title> <para> Provides functionality to perform syntax highlighting for different file formats. </para> <sect2> <title>Introduction</title> <para> With <classname>Text_Highlighter</classname> it is possible to create syntax highlighted versions of different file formats. </para> <para> Currently, the following formats are supported: </para> <itemizedlist> <listitem> <simpara>C++</simpara> </listitem> <listitem> <simpara><acronym>CSS</acronym></simpara> </listitem> <listitem> <simpara>output of <command>diff(1)</command></simpara> </listitem> <listitem> <simpara><acronym>DTD</acronym></simpara> </listitem> <listitem> <simpara><acronym>HTML</acronym></simpara> </listitem> <listitem> <simpara>Java</simpara> </listitem> <listitem> <simpara>Javascript</simpara> </listitem> <listitem> <simpara>MySQL</simpara> </listitem> <listitem> <simpara>Perl</simpara> </listitem> <listitem> <simpara><acronym>PHP</acronym></simpara> </listitem> <listitem> <simpara>Python</simpara> </listitem> <listitem> <simpara>Ruby</simpara> </listitem> <listitem> <simpara><acronym>SQL</acronym></simpara> </listitem> <listitem> <simpara><acronym>XML</acronym></simpara> </listitem> </itemizedlist> </sect2> <sect2> <title>Usage</title> <para> The class <classname>Text_Highlighter</classname> contains all necessary functionality to perform the syntax highlighting except for the actual highlighting rules for the different formats. These rules are defined in subclasses of <classname>Text_Highlighter</classname>, but one must not directly instantiate these subclasses. Instead the object-oriented factory pattern is used to create a highlighter object depending on the format: </para> <example> <title>Highlighting a SQL file</title> <programlisting role="php"> <![CDATA[ require_once "Text/Highlighter.php"; $hlSQL =& Text_Highlighter::factory("SQL"); echo $hlSQL->highlight("SELECT * FROM some_table WHERE id = 12"); ]]> </programlisting> <para> This code generates a highlighted version of the SQL SELECT-query that is passed to <methodname>Text_Highlighter::highlight</methodname> in HTML. It is possible to customize the output to e.g. instead generate output suitable for usage on a console. This is described in the section <link linkend="package.text.text-highlighter.oc"> Output Customization</link>. </para> </example> <para> In order to produce syntax highlighting for other formats, one must replace the argument value <literal>SQL</literal> of <methodname>Text_Highlighter::factory</methodname> with one of <literal>CPP</literal>, <literal>CSS</literal>, <literal>DIFF</literal>, <literal>DTD</literal>, <literal>HTML</literal>, <literal>JAVA</literal>, <literal>JAVASCRIPT</literal>, <literal>MYSQL</literal>, <literal>PERL</literal>, <literal>PHP</literal>, <literal>PYTHON</literal>, <literal>RUBY</literal>, <literal>SQL</literal>, or <literal>XML</literal>. </para> </sect2> <sect2 id="package.text.text-highlighter.oc"> <title>Output Customization</title> <para> The default behaviour of <classname>Text_Highlighter</classname> is to generate a syntax highlighted HTML version of the input. </para> <para> It is possible to instead generate output that is suitable for being displayed on color-capable terminals such as <command>xterm</command> or through <command>less(1)</command> by telling <classname>Text_Highlighter</classname> to use another renderer: </para> <example> <title>Using the console renderer</title> <programlisting role="php"> <![CDATA[ require_once "Text/Highlighter.php"; require_once "Text/Highlighter/Renderer/Console.php"; $hlSQL =& Text_Highlighter::factory("SQL"); $hlSQL->setRenderer(new Text_Highlighter_Renderer_Console); echo $hlSQL->highlight("SELECT * FROM some_table WHERE id = 12"); ]]> </programlisting> </example> <para> Also it is possible to further customize the output of both the HTML- and the console-renderer by passing an associative array of options to the constructor: </para> <example> <title>Options for the HTML renderer</title> <programlisting role="php"> <![CDATA[ require_once "Text/Highlighter.php"; require_once "Text/Highlighter/Renderer/Html.php"; $renderer = new Text_Highlighter_Renderer_Html(array("numbers" => HL_NUMBERS_OL, "tabsize" => 4)); $hlJava =& Text_Highlighter::factory("JAVA"); $hlJava->setRenderer($renderer); echo $hlJava->highlight('class JavaProgram { public static void main(String args[]) { System.out.println("Hello World!"); } }'); ]]> </programlisting> <para> The above example configures a HTML renderer with two options: The first one tells it to number the lines in the output using the <literal>&lt;ol /&gt;</literal> HTML tag and the second one instructs the renderer to use a tab width of 4 spaces for indentation. </para> </example> <para> The following options are applicable: </para> <table> <title>Possible options for the renderer classes</title> <tgroup cols="5"> <colspec colname="option" /> <colspec colname="description" /> <colspec colname="inHTML" /> <colspec colname="inConsole" /> <colspec colname="hints" /> <thead> <row> <entry>Name</entry> <entry>Description</entry> <entry>Available in HTML renderer</entry> <entry>Available in console renderer</entry> <entry>Hints</entry> </row> </thead> <tbody> <row> <entry align="center"><literal>numbers</literal></entry> <entry>Line numbering style</entry> <entry align="center">yes</entry> <entry align="center">yes</entry> <entry> In the console renderer, this option takes just &true; or &false; in order to denote if line numbers should be displayed or not. The HTML rendered accepts three different values: <constant>HL_NUMBERS_LI</constant> instructs the class to number the lines using the <literal>&lt;ol /&gt;</literal> HTML tag, while <constant>HL_NUMBERS_TABLE</constant> uses a two-column table with the line numbers in the first and the source code in the second column. Setting the value to &false; turns line numbering off in the HTML renderer. </entry> </row> <row> <entry align="center"><literal>tabsize</literal></entry> <entry>Tab width</entry> <entry align="center">yes</entry> <entry align="center">yes</entry> <entry /> </row> <row> <entry align="center"><literal>colors</literal></entry> <entry>Additional colors</entry> <entry align="center">no</entry> <entry align="center">yes</entry> <entry> An associate array of additional colors for color-enabled consoles. The key of each array entry must be the name of the color and the corresponding value must be the escape sequence for it. (Example: <literal>\033[1;31mRed</literal>.) </entry> </row> </tbody> </tgroup> </table> </sect2> </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.pear.doc (#7770) next »