DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Convert Emacs Region To HTML

04.08.2005
| 7717 views |
  • submit to reddit
        Sometimes while I'm editing, I want to convert a region to HTML. I use Perl's HTML::FromText. First I create this script and call it <em>tohtml</em>.

#!/usr/bin/perl

 use HTML::FromText;
 use strict;

 my $text = join '',<>;
 my $html = text2html($text, urls => 1, email => 1, bold=>1, paras => 1, allcaps => 1, tables => 1, bullets => 1, underline=>1);

print $html;

Then from within Emacs, I select the region and do

C-x ESC-1 ESC-| tohtml RET