<?xml version='1.0' encoding='utf-8' ?>
<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <channel>
    <title>Wolfmans Howlings: Howto format ruby code for blogs</title>
    <link>http://blog.wolfman.com/articles/2006/5/26/howto-format-ruby-code-for-blogs</link>
    <description>A programmers Blog about Ruby, Rails and a few other issue</description>
    <language>en-us</language>
    <ttl>40</ttl>
    <item>
      <title>Howto format ruby code for blogs</title>
      <description>
        &lt;p&gt;How do I get that nice formatted ruby code inline?&lt;/p&gt;
        
        &lt;p&gt;Well if you are on typo trunk use this...&lt;/p&gt;
        
        &lt;pre&gt;&lt;code&gt;&amp;lt;typo:code lang=&quot;ruby&quot;&amp;gt;
           ...ruby code...
        &amp;lt;/typo:code&amp;gt;
        &lt;/code&gt;&lt;/pre&gt;
        
        &lt;p&gt;If you are not on typo trunk (which I am not yet) you can do the following...&lt;/p&gt;
        
        &lt;p&gt;I had to search around for this so I thought I'd put the recipe here.&lt;/p&gt;
        
        &lt;p&gt;I got most of my information from this
        &lt;a href=&quot;http://www.carldr.com/blog/article/3/ruby-syntax-highlighting&quot;&gt;site&lt;/a&gt;,
        you can also use &lt;a href=&quot;http://syntax.carldr.com&quot;&gt;this site&lt;/a&gt; to convert the
        code for you, but I found that more cumbersome than what I do below.&lt;/p&gt;
        
        &lt;p&gt;Basically all the hard work is done by the syntax gem install it as...&lt;/p&gt;
        
        &lt;div class=&quot;terminal&quot;&gt;
        &gt; gem install syntax
        &lt;/div&gt;
        
        &lt;p&gt;Then I use this little script called code2html.rb which converts the code in the clipboard and puts it back in the clipbboard...&lt;/p&gt;
        
        &lt;pre&gt;&lt;span class=&quot;ident&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;rio&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
        &lt;span class=&quot;ident&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;rubygems&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
        &lt;span class=&quot;ident&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;syntax/convertors/html&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
        
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;ARGV&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
            &lt;span class=&quot;ident&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;ARGV&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;])&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;
            &lt;span class=&quot;ident&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; `&lt;span class=&quot;ident&quot;&gt;dcop&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;klipper&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;klipper&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;getClipboardContents`&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
        
        &lt;span class=&quot;ident&quot;&gt;convertor&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;Syntax&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Convertors&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;HTML&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;for_syntax&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;ruby&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;attribute&quot;&gt;@code_html&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;convertor&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;convert&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;code&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@code_html&lt;/span&gt;
        
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;ARGV&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
            &lt;span class=&quot;ident&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&lt;span class=&quot;expr&quot;&gt;#{File.basename(ARGV[0], File.extname(ARGV[0]))}&lt;/span&gt;.html&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;
            &lt;span class=&quot;ident&quot;&gt;rio&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@code_html&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;
            &lt;span class=&quot;comment&quot;&gt;# put the results back on the clipboard, NB this may fail if there are shell specific characters&lt;/span&gt;
            &lt;span class=&quot;ident&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;dcop klipper klipper setClipboardContents &lt;span class=&quot;escape&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;expr&quot;&gt;#{@code_html}&lt;/span&gt;&lt;span class=&quot;escape&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;)&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
        
        &lt;/pre&gt;
        
        &lt;p&gt;The clipboard stuff is kind of kde specific.&lt;/p&gt;
        
        &lt;p&gt;Alternatively you can specify a filename on the command line, and it
        will convert that file and put the results in a file with .html as the extension.
        (Note this requires the rio gem).&lt;/p&gt;
        
        &lt;p&gt;You will need this CSS available to your web page to render it nicely.&lt;/p&gt;
        
        &lt;pre&gt;&lt;code&gt;pre {
            background-color: #f1f1f3;
            color: #112;
            padding: 10px;
            font-size: 1.1em;
            overflow: auto;
            margin: 4px 0px;
                  width: 95%;
        }
        
        
        
        /* Syntax highlighting */
        pre .normal {}
        pre .comment { color: #005; font-style: italic; }
        pre .keyword { color: #A00; font-weight: bold; }
        pre .method { color: #077; }
        pre .class { color: #074; }
        pre .module { color: #050; }
        pre .punct { color: #447; font-weight: bold; }
        pre .symbol { color: #099; }
        pre .string { color: #944; background: #FFE; }
        pre .char { color: #F07; }
        pre .ident { color: #004; }
        pre .constant { color: #07F; }
        pre .regex { color: #B66; background: #FEF; }
        pre .number { color: #F99; }
        pre .attribute { color: #5bb; }
        pre .global { color: #7FB; }
        pre .expr { color: #227; }
        pre .escape { color: #277; }
        &lt;/code&gt;&lt;/pre&gt;
      </description>
      <author>Jim Morris</author>
      <pubDate>Fri, 26 May 2006 00:14:00 -0700</pubDate>
      <link>http://blog.wolfman.com/articles/2006/5/26/howto-format-ruby-code-for-blogs</link>
      <guid isPermaLink='false'>urn:uuid:0d03c376940926bb644bb94acf0fc3eb</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by rio4ruby@rubyforge.org</title>
      <description>
        I like your use of Rio here. It illustrates well the reason for Rio's existence -- to make common I/O operations simple, so that one could spend their time writing code that does something worthwhile.  With your approval, I would like to use this example in Rio's documentation -- with a couple of changes that illustrate some of Rio's functionality besides its copy operator:
        
          code= File.read(ARGV[0])
        could be replaced with
          code = rio(ARGV[0]).read
        
        and
        
           fn= &quot;#{File.basename(ARGV[0], File.extname(ARGV[0]))}.html&quot;
           rio(fn) &lt;&lt; @code_html
        
        could be replaced with
        
          rio(ARGV[0]).basename + '.html' &lt; @code_html
        
        Cheers, 
        -Christopher
      </description>
      <pubDate>Thu, 28 Sep 2006 23:31:46 -0700</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-16</link>
      <guid isPermaLink='false'>urn:uuid:31827b08-e59d-48a2-8ecb-b005ceeb9d5b</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by madcoderspeak.blogspot.com</title>
      <description>
        Thanks a lot for this post..
        My blog ate a lot of my ruby code... had to use your script to make sure my blog doesn't do it again :D
        
        Cool post this one!
      </description>
      <pubDate>Mon, 19 Feb 2007 10:38:28 -0800</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-17</link>
      <guid isPermaLink='false'>urn:uuid:50b1c6f1-2f10-4381-9a06-abd4939f2030</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by Romulo A. Ceccon</title>
      <description>
        Something might have happened to www.carldr.com. Neither the blog entry nor the convert tool is there anymore.
        
        Thanks for the tips, by the way.
      </description>
      <pubDate>Thu, 03 May 2007 05:35:14 -0700</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-18</link>
      <guid isPermaLink='false'>urn:uuid:5f89758a-abc8-4ed9-b2a7-0a250eb330a9</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by Brent</title>
      <description>Thanks, this is really helpful.  I had been wondering how people get their Ruby code to display so nicely on blogs.  I've posted code on my blog at http://brentrubyrails.blogspot.com/2007/12/formatting-ruby-and-html-code-for-blog.html that uses Syntax for Ruby and HTML code, and copies it to the Windows clipboard.</description>
      <pubDate>Sun, 02 Dec 2007 20:05:56 -0800</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-19</link>
      <guid isPermaLink='false'>urn:uuid:1ae0b89c-581a-4deb-a6ad-0eaf3fdc57e0</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by ritu sodhi</title>
      <description>syntax/convertors/html  The error comes that its unable to find convertor</description>
      <pubDate>Sun, 09 Mar 2008 03:26:15 -0700</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-20</link>
      <guid isPermaLink='false'>urn:uuid:dfe9c4aa-3d9d-4359-8ac6-aaf849e4406f</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by aidy_lewis</title>
      <description>
        It doesn't seem that the ruby publishing code, syntax highlights. I could just use
        &lt;code&gt;
        
        &lt;/code&gt;
      </description>
      <pubDate>Mon, 14 Apr 2008 05:54:53 -0700</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-21</link>
      <guid isPermaLink='false'>urn:uuid:1bc1287f-b48d-4dff-b73c-0ec53c5043cc</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by aidy_lewis</title>
      <description>meant to say I could just use the code tag</description>
      <pubDate>Tue, 15 Apr 2008 04:19:33 -0700</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-22</link>
      <guid isPermaLink='false'>urn:uuid:fa7e900f-47c7-4dec-a7ce-d7907b0fe1c7</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by Andi Schacke</title>
      <description>Thanks, great post. After implementing your tips I just realized that - if you're using TextMate as your editor - you can use the builtin function 'Convert Document to HTML'. I described how to do it [in this post](http://blog.andischacke.com/2008/10/code-syntax-highlighting-on-web-pages.html).</description>
      <pubDate>Fri, 10 Oct 2008 07:39:50 -0700</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-23</link>
      <guid isPermaLink='false'>urn:uuid:122e3bd5-18ea-42d5-b2ec-a89f06380240</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by EH</title>
      <description>I would think that Rails developers could come up with a solution that didn't involve horizontal scroll bars. Too many times, blog posts contain code which is scrunched into a 40char textbox to preserve the precious page structure. However, this is an arbitrary constraint that does not aid usability.</description>
      <pubDate>Tue, 06 Jan 2009 12:04:08 -0800</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-24</link>
      <guid isPermaLink='false'>urn:uuid:5a49ad42-11f5-49f8-8857-ff4dd76bd319</guid>
    </item>
    <item>
      <title>"Howto format ruby code for blogs" by Tom</title>
      <description>
        Maybe this can help you. It's a nice online source code formatter.It supports almost all of the popular program languages, such as Java, PHP, Ruby, C++ etc. And you can choose the theme you like and embed it into any web you want easily.You can take it a try here
        	http://www.codetie.com.
      </description>
      <pubDate>Mon, 02 Feb 2009 22:11:03 -0800</pubDate>
      <link>http://blog.wolfman.com/posts/4#comment-240</link>
      <guid isPermaLink='false'>urn:uuid:9ac0cf3c-b95a-4c93-9e6d-2ab0feb99319</guid>
    </item>
  </channel>
</rss>
