Not-So-SmartyPants
Tags:
Does anyone know of a reversed SmartyPants (for lack of a better description) plugin that's out there?
The SmartyPants plugin for Movable Type will convert regular quotes and dashes into the nicely formatted ones.
But what I want is a plugin that will (sorta) do the opposite: if I copy and paste some text that already contains "—", "“" or the like into my Entry Body, it will automatically turn them into their HTML character entities (— and “, respectively).
I would imagine that I can write my own plugin, that loops through the characters one at a time, and replaces those outside the ASCII range, but why reinvent the wheel if it's already been done.
update To clarify, the reason why I want this tool is so that all my entries will be XHTML-compliant. Some tools, such as the LJCrosspost's XML-RPC will break if there are non-ASCII characters involved.
How integrated do you need this to be? A simple HTML page with two <textarea>'s and some JavaScript with an action button ought to do the trick.
Cut and paste text into the "before" , click the action button, and the post-processed text appears in the "after" .
I want it integrated enough that:
(1) I don't need to think about it.
(2) I dont' need to add extra steps.
(3) I don't need to make any MT modifications that'll get overwritten the next time I upgrade.
I may just make an MT plugin that does it in the background, like SmartyPants.
Posted by: Joe Grossberg on March 3, 2005 3:47 PM | permalinkJust saw your update -- in this case, wouldn't it be smarter to hack SmartyPants to emit the correct XML entities rather than the actual values? Is there a nice configuration option for SmartyPants's encoder to tell it to do this?
Yeah, that's possible.
Or I could just contact the plugin author and make a feature request. ;)
Posted by: Joe Grossberg on March 3, 2005 5:26 PM | permalinkYou could write a filter in Python:
#!/usr/bin/env python
#
# usage:
# charref.py utf-8 < infile > outfile
import sys
encoding = (sys.argv[1:2] or ['utf-8'])[0]
sys.stdout.write(sys.stdin.read().decode(encoding).encode('ascii', 'xmlcharrefreplace'))
No more comments! Either someone has violated Godwin's Law, I'm tired of the discussion or, most likely, the ten-week window has closed. You can, however, contact me through email.