The Accidental Rubyist

invalid byte sequence in UTF-8

Publishing code on this blog through Ecto

leave a comment »

Background: All attempts to publish some simple source code on this blog failed. Be it directly on WP or through Ecto. PRE and CODE tags made no difference. How many tags I might have to manually change, i do not know. But < and \ we certainly disappearing !

And so now, I run the code samples (sniff) through vim’s TOhtml plugin, and copy the resultant HTML here. Now I know that this has generated an AWFUL lot of code for just a few lines of ruby. I give you inter.rb:

#!/usr/bin/env ruby
file = ARGV[0];
text =,"r").readlines.join;
urlmap = {"w" => "",
  "g" => "",
  "dict" => "",
  "http" => "http:%s",
  "th" => ""
text.gsub!(/\\[\\[(w+?):(.+?)\\]\\]/) { |match|
  if path == nil then
    puts "%s not found in urlmap" % $1
    str = $2.split('|')
    if str.size == 1 then
      str << str[0];
    ('<a href="' + path + '">%s</a>') % [str[0], str[1]]
#puts text, "w").puts text;

And now here is

# take textile text as stdin and output as html
# textile.psh < filename.html
# :%!textile.psh  (in vim)
use Text::Textile qw(textile);
my $text = "";
my $entryfile = $ARGV[0];

while (<>) {
 $text .= $_;
# procedural usage
my $html = textile($text);
#print $html;
open ( FILE, ">$entryfile" ) or die;
print FILE $html;
close FILE;
# OOP usage
#    my $textile = new Text::Textile;
#    $html = $textile->process($text);
#    print $html;

And finally here is the markdown plugin script:

#!/usr/bin/env ruby
# Markdown'ise things.
# Take Markdown markup on STDIN, and output HTML to STDOUT
require 'rubygems'
require 'bluecloth'
#print (
file = ARGV[0];
text =,"r").readlines.join;
html = ( text).to_html, "w").puts html;

Hope this comes through fine.



Written by totalrecall

February 28, 2007 at 9:28 pm

Posted in ecto, Mac OS X, ruby

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: