<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marcus Hellberg &#187; ruby</title>
	<atom:link href="http://www.marcushellberg.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcushellberg.com</link>
	<description>blog.</description>
	<lastBuildDate>Sat, 20 Mar 2010 12:39:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Textile to XHTML converter</title>
		<link>http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/</link>
		<comments>http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 11:42:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.marcushellberg.com/?p=225</guid>
		<description><![CDATA[A while back, I needed to quickly write some documentation that needed to be in XHTML format. Writing in plain XHTML is a pain, so I decided to write the documentation in Textile and then convert it to XHTML before publishing.
The problem I found was that all Textile converters were made for use in blogs [...]]]></description>
			<content:encoded><![CDATA[<p>A while back, I needed to quickly write some documentation that needed to be in XHTML format. Writing in plain XHTML is a pain, so I decided to write the documentation in Textile and then convert it to XHTML before publishing.</p>
<p>The problem I found was that all Textile converters were made for use in blogs and other online tools. What I needed was a good old-fashioned command line program to convert a given textile file into XHTML.</p>
<p>Fortunately, using Ruby and the excellent RedCloth gem, I could write a small script to accomplish this in a few minutes.</p>
<p>If you have any similar needs, copy the source into a file named textile2html, make it executable (chmod +x) and place it somewhere in your path. Then all you have to do is call textile2html with the textile file as an argument:</p>
<pre>$ textile2html documentation.textile</pre>
<pre class="brush:ruby">#!/usr/bin/env ruby -wKU
require "rubygems"
require "RedCloth"

if ARGV.size != 1
puts "Usage: textile2html file.textile"
exit
end

# Read input file
textile_string = ""
begin
  input_file = File.new(ARGV[0], "r")
  input_file.each do |line|
    textile_string+=line
  end
  input_file.close
rescue
  puts "Could not read input file."
  exit
end

# Create output file
filename = ARGV[0].gsub(/\.\w+$/, "")
begin
  output_file = File.new("#{filename}.html", "w")
rescue
  puts "Could not create output file."
  exit
end

html_header = &lt;&lt;DOC
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
&lt;head&gt;
&lt;title&gt;
DOC

html_header += filename;
html_header += &lt;&lt;DOC
&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
DOC

html_footer = &lt;&lt;DOC
&lt;/body&gt;
&lt;/html&gt;
DOC

html_output = RedCloth.new(textile_string).to_html
output_file.puts(html_header)
output_file.puts(html_output)
output_file.puts(html_footer)
output_file.close

puts "Done."
</pre>
<p>Questions? Comments? Post them below.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/&amp;title=Textile+to+XHTML+converter" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/&amp;title=Textile+to+XHTML+converter" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/&amp;t=Textile+to+XHTML+converter" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Textile+to+XHTML+converter+-+http://b2l.me/ede5D+(via+@marcushellberg)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/&amp;title=Textile+to+XHTML+converter&amp;summary=A%20while%20back%2C%20I%20needed%20to%20quickly%20write%20some%20documentation%20that%20needed%20to%20be%20in%20XHTML%20format.%20Writing%20in%20plain%20XHTML%20is%20a%20pain%2C%20so%20I%20decided%20to%20write%20the%20documentation%20in%20Textile%20and%20then%20convert%20it%20to%20XHTML%20before%20publishing.%0D%0A%0D%0AThe%20problem%20I%20found%20was%20that%20all%20Textile%20converters%20were%20made%20for%20use%20&amp;source=Marcus Hellberg" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/&amp;title=Textile+to+XHTML+converter" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/&amp;t=Textile+to+XHTML+converter" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-blogger">
			<a href="http://www.blogger.com/blog_this.pyra?t&amp;u=http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/&amp;n=Textile+to+XHTML+converter&amp;pli=1" rel="nofollow" class="external" title="Blog this on Blogger">Blog this on Blogger</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.marcushellberg.com/2010/01/22/textile-to-xhtml-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
