Widon’t for Movable Type
26th Aug 2006
Widon’t for Movable Type is a plugin to prevent widows from appearing in titles and entry headers. Widows are single words, left on their lonesome on a line at the end of a paragraph, and generally look poo.
Widon’t simply adds a non-breaking space entity between the last two words of an entry title, so if the last word has to wrap, it takes a friend with it.
Widon’t for Wordpress was originally released a few days ago by Shaun Inman, but I didn’t want to be left out as an MT user, so I’ve ported it across to Perl. All credit for the idea and PHP version goes to Shaun, any failures in this MT version are down to me.
Download
Widon’t for Movable Type v1.4 (2008-07-11)
Installation
Unzip the file and place Widont.pl in the plugins directory of your Movable Type installation.
(mthome)/plugins/Widont.plUsage
For titles, add the global filter widont="1" to your entry title tags:
<mt:EntryTitle widont="1" />To prevent widows in header tags used in entries, add the widont filter to the appropriate MTEntry tag:
<mt:EntryExcerpt widont="1" />
<mt:EntryBody widont="1" />
<mt:EntryMore widont="1" />I’m no Perl ninja, so if there are any problems let me know.
Comments
1.
Shaun Inman - 29th Aug 2006, 12.53 AM
Will this only work on any MT tag or just entry titles?
2.
Brook Elgie - 29th Aug 2006, 8.16 AM
It should work with any container tag, but probably not as expected. For example, if used with the MTEntryBody tag where the body has several paragraphs, only the last paragraph will get the Widon’t treatment.
It’s also more likely cause an error. Testing it out on an entry that ended with:
blah blah blah <span class=”caps”>CSS.</span>
has Widon’t inserting the non-breaking space between “span” and “class”, breaking the tag.
I’m definitely looking into it for version 1.1 :)
3.
Ruben Arakelyan - 31st Aug 2006, 7.52 PM
Great plugin - I’m using it right now. It works OK, but there is one major problem that I’ve found - if the title is only one word with no spaces, then the plugin inserts the space just before the last character, strips it, and repeats the word. For example, “Writings” becomes “Writing Writings”.
A couple of small nit-picks as well: The first line says package MT::Plugin::Windot; instead of package MT::Plugin::Widont; Also, the non-breaking space HTML entity may not work for people who serve their pages as application/xhtml+xml. Simply changing the & nbsp; to & #160; should solve the problem.
Sorry for all the negatives! :)
4.
Ruben Arakelyan - 31st Aug 2006, 8.07 PM
I just had a little play with the code and I’ve found out why this was happening. Apparently, the rindex function doesn’t always return null. In my case, it returned -1.
I changed the line that read
if($space != null) {
to read
if($space = -1) {
and it works now!
5.
Brook Elgie - 31st Aug 2006, 10.29 PM
Nice one, thanks Ruben! I’ve corrected the two errors you mentioned, thanks for spotting them. I’ll look into the entity issue, but I think you’re right.
I happen to be working on extending the functionality to prevent widows in the main entry content. I might as well upload a preview of the new beta version now. It should suppress widows in any header tag (h1, h2, h3, etc.) when used with MTEntryBody etc. If you’re feeling brave you can open the file and toggle the commented variable “$tags_to_widont” to suppress widows in paragraphs as well.
btw: I think MovableType isn’t allowing some code in comments. I can see what you mean though.
6.
Ruben Arakelyan - 1st Sep 2006, 10.30 AM
Great! I know MT wouldn’t let me post the correct code but it’s fixed now anyway. I might give the beta version a go as well and see how it does with content.
7.
Brook Elgie - 31st Dec 2006, 6.08 PM
The new version (1.2) suppresses widows in header tags within the entry (just like the beta version mentioned above).
8.
Nicholas Jesson - 19th Feb 2007, 6.14 PM
I am running MT 3.2. I installed Widont 1.2 the other day. I have a Cron job running MT’s “run-periodic-tasks” overnight. I have received the following error messages:
Unquoted string “widont” may clash with future reserved word at /dnshome/ecumenism.net/cgi-bin/mt/plugins/Widont.pl line 48.
Unquoted string “null” may clash with future reserved word at /dnshome/ecumenism.net/cgi-bin/mt/plugins/Widont.pl line 59.
I don’t know Perl, so I don’t know whether quotes can be added to these strings, or where to add them.
Any suggestions?
Nick
9.
c.libre - 19th Feb 2007, 9.40 PM
Nick,
I noticed the same problems. It’s been a long time since I’ve written any Perl, but I think you can fix this by doing the following:
1) Change line 49 to read:
MT::Template::Context->add_global_filter(widont => \&widont);
2) Change line 60 to read:
if($space = -1){
10.
Brook Elgie - 21st Mar 2007, 9.39 AM
I think this is just a warning and it shouldn’t have an adverse impact on anything. I do intend to get it fixed though, but I need to set up a separate test environment for MT that’s not my live site :). Thanks for drawing it to my attention.
11.
Brook Elgie - 15th Jul 2007, 7.54 AM
I finally got a test installation of MT set up and fixed those unquoted string warnings. I also checked the plugin works with the latest version of MT4 beta and made some small changes to get Widon’t to display properly in the plugins list. New version (1.3) available above.
12.
Brook Elgie - 11th Jul 2008, 3.59 PM
Widon’t for Movable Type has been updated to version 1.4. This updates adds support for Pages and better compatibility with MT4. This version is no longer compatible with MT3, though you can still download v1.3, which is.
Comment preview: