<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://php.apsique.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Php y otras yerbas - Mi primer módulo drupaliano : codefilter - Comentarios</title>
 <link>http://php.apsique.com/contenido/mi_primer_modulo_drupaliano_codefilter</link>
 <description>Comentarios para &quot;Mi primer módulo drupaliano : codefilter&quot;</description>
 <language>es</language>
<item>
 <title>Ufff, aunque con un &quot;poco&quot;</title>
 <link>http://php.apsique.com/contenido/mi_primer_modulo_drupaliano_codefilter#comment-91081</link>
 <description>&lt;p&gt;Ufff, aunque con un &quot;poco&quot; de retraso, jejejeje, aquí está el link:&lt;br /&gt;
http://www.educasitio.com/codefilter&lt;/p&gt;
</description>
 <pubDate>Sun, 25 Jan 2009 11:08:28 -0800</pubDate>
 <dc:creator>cantidubi</dc:creator>
 <guid isPermaLink="false">comment 91081 at http://php.apsique.com</guid>
</item>
<item>
 <title>Que bueno que te haya servido</title>
 <link>http://php.apsique.com/contenido/mi_primer_modulo_drupaliano_codefilter#comment-65542</link>
 <description>&lt;p&gt;Que bueno que te haya servido. ¿Cual es el link del artículo?&lt;/p&gt;
</description>
 <pubDate>Mon, 19 Feb 2007 08:32:58 -0800</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">comment 65542 at http://php.apsique.com</guid>
</item>
<item>
 <title>Sentía la necesidad de agrad</title>
 <link>http://php.apsique.com/contenido/mi_primer_modulo_drupaliano_codefilter#comment-65540</link>
 <description>&lt;p&gt;Sentía la necesidad de agradecerte éste aporte que encontré en drupal.org y que me ha sido muy útil. En mi web he realizado una pequeña descripción y guia de instalación y configuración para principiantes.&lt;br /&gt;
He puesto un enlace a éste artículo desde mi web para los que quieran ver el funcionamiento &quot;por dentro&quot;.&lt;br /&gt;
Un saludo.&lt;/p&gt;
</description>
 <pubDate>Mon, 19 Feb 2007 06:58:42 -0800</pubDate>
 <dc:creator>cantidubi</dc:creator>
 <guid isPermaLink="false">comment 65540 at http://php.apsique.com</guid>
</item>
<item>
 <title>Mi primer módulo drupaliano : codefilter</title>
 <link>http://php.apsique.com/contenido/mi_primer_modulo_drupaliano_codefilter</link>
 <description>&lt;p&gt;Bueno, tenía que pasar algún día, no? Como suelo publicar mi buena cantidad de código, me gusta que se vea lo más bonito posible. En Wordpress ocupaba un plug-in que pasaba todo texto entre &amp;lt;pre lang=&#039;php&amp;gt; por &lt;code&gt;highlight_string&lt;/code&gt;. Al pasar a Drupal, no me quedó más que activar el modo php en algunos post y hacerlo a mano.&lt;/p&gt;
&lt;p&gt;Obviamente, esto aburre. Así que decidí gastar un par de neuronas y ver si podía crear un filtro. En la página de &lt;a href=&#039;http://drupaldocs.org/api/4.5/file/contributions/docs/developer/examples/filter_example.module&#039;&gt; ejemplo de módulo de filtro&lt;/a&gt; de la documentación de Drupal encontré la información que necesitaba.&lt;/p&gt;
&lt;p&gt;Como ya he señalado en más de mil ocasiones, soy un flojo rematado, así que no me iba a dar la lata de crear un marcador de código. Entonces, mi neurona MLP recordó que había un paquete de Pear cuya única misión en la vida es mostrar código bónito: &lt;a href=&#039;http://pear.php.net/package/Text_Highlighter/&#039;&gt;Text_Highlighter&lt;/a&gt;. Tiene soporte, además de código PHP, para código XML, Ruby, Python, C, y otra infinidad de cosas, así que mi soporte para otros lenguajes estaba garantizado.
&lt;/p&gt;
&lt;p&gt;Les remito a la descarga para el código del módulo, pero les muestro el par de líneas que hacen la verdadera magia&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-inlinetags&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;codefilter_filter&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$op&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$delta&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$format&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; = -&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$text&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;swith&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$op&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;case&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;:&lt;/li&gt;
&lt;li&gt;&amp;nbsp;          &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;preg_replace_callback&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;/&amp;lt;code lang=[&lt;/span&gt;&lt;span class=&quot;hl-special&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;&#039;]([^&lt;/span&gt;&lt;span class=&quot;hl-special&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;&#039;]+)[&lt;/span&gt;&lt;span class=&quot;hl-special&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;&#039;]&amp;gt;(.+?)&amp;lt;\/code&amp;gt;/ms&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;_codefilter_process&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$text&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;      &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;_codefilter_process&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$match&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$lang&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$match&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$text&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$match&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$options&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;        &lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; =&amp;gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;HL_NUMBERS_LI&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;        &lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;tabsize&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; =&amp;gt; &lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;,&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$renderer&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; =&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;Text_Highlighter_Renderer_HTML&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$options&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$hl&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; =&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;Text_Highlighter&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$lang&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;        &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$hl&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;setRenderer&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$renderer&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$hl&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;highlight&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;trim&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$text&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$text&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;
Si lo leen con atención, lo primera es una &lt;code&gt;preg_replace_callback&lt;/code&gt;  reemplaza todos los textos que van entre tags &lt;code&gt;code&lt;/code&gt; con atributo &lt;code&gt;lang&lt;/code&gt; por el resultado de la función &lt;code&gt;_codefilter_process&lt;/code&gt;. Esta, a su vez, instancia dos objetos, una subclase de &lt;code&gt;Text_Highlighter&lt;/code&gt; y un &lt;code&gt;Text_Highlighter_Renderer_HTML&lt;/code&gt;, siendo el primero encargado de procesar el texto y el segundo, de mostrarlo como HTML. La subclase de Text_Highlighter la obtengo directamente del atributo, así que hay que tener cuidado de que el lenguaje esté soportado.&lt;/p&gt;
&lt;p&gt;El código que mostré de ejemplo está procesado, precisamente, con el módulo. Si les sirve o quieren saber más, cosa de comentar&lt;/p&gt;
</description>
 <comments>http://php.apsique.com/contenido/mi_primer_modulo_drupaliano_codefilter#comments</comments>
 <category domain="http://php.apsique.com/categoria/temas_generales/autoreferencia">Autoreferencia</category>
 <category domain="http://php.apsique.com/categoria/lenguajes/php_php_retorcido">Php retorcido</category>
 <category domain="http://php.apsique.com/categoria/temas_generales/programacion">Programación</category>
 <enclosure url="http://php.apsique.com/files/codefilter.module.gz" length="1101" type="application/gzip" />
 <pubDate>Fri, 18 Mar 2005 12:24:28 -0800</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">412 at http://php.apsique.com</guid>
</item>
</channel>
</rss>
