Never been to DZone Snippets before?

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

About this user

Thomas Beutel http://www.beutelevision.com

« Newer Snippets
Older Snippets »
Showing 11-13 of 13 total

UTF8 Curly Quotes to ASCII

Here's a cheap hack to convert UTF8 curly quotes to ASCII (but try to use CPAN module instead of this if you can).

   1  
   2   $xml =~ s/\xe2\x80\x99/\'/gs;
   3   $xml =~ s/\xe2\x80\x98/\'/gs;
   4   $xml =~ s/\xe2\x80\x9c/\"/gs;
   5   $xml =~ s/\xe2\x80\x9d/\"/gs;

Convert Emacs Region to HTML

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 tohtml.

   1  
   2  #!/usr/bin/perl
   3  
   4   use HTML::FromText;
   5   use strict;
   6  
   7   my $text = join '',<>;
   8   my $html = text2html($text, urls => 1, email => 1, bold=>1, paras => 1, allcaps => 1, tables => 1, bullets => 1, underline=>1);
   9  
  10  print $html;


Then from within Emacs, I select the region and do

   1  
   2  C-x ESC-1 ESC-| tohtml RET

Write list as XML to HTML form - Javascript

Suppose that you have a draggable list as described at http://tool-man.org/examples/sorting.html. To send that list from a form, do

   1  
   2  function listToXml(){
   3  	var vList = document.getElementById('phonetic');
   4          var vLen  = vList.childNodes.length;
   5  	var vXml  = "<ul>";
   6          for(var i = 0; i < vLen - 1; i++){
   7  	  if(vList.childNodes[i].innerHTML){
   8  	    vXml = vXml + '<li>' + vList.childNodes[i].innerHTML + '</li>';
   9  	  }
  10          }
  11  	vXml = vXml + '</ul>';
  12  	document.myform.listfield.value = vXml;
  13  }
  14  
  15  ...
  16  
  17  	<ul id="phonetic" class="sortable boxy" style="margin-left: 1em;">
  18  		<li>alpha</li>
  19  		<li>bravo</li>
  20  		<li>charlie</li>
  21  		<li>delta</li>
  22  		<li>echo</li>
  23  		<li>foxtrot</li>
  24          </ul>
  25  
  26  <form name="myform">
  27  <input type="text" name="listfield" value="" size="60">
  28  <input type="button" value="submit2" name="submit2" onClick="listToXml()">
  29  </form>
  30  
« Newer Snippets
Older Snippets »
Showing 11-13 of 13 total