Post Archive

› April 20, 2002

Text Cleanup Button for Forms

  • Reported by Nate

Francois has started creating a character entity filter that is intended to replace various common text entry entities with the entities that are supposed to be used (e.g. "double primes" with “double quotation marks”). We are going to put K10K’s new “matchmaker” service to the test by posting a request for javascript help. If you are, or know of someone who can hack it, please let us know.

Comments

1. April 20, 2002 08:20 PM

Quote this comment

Nate Posted…

Ok, I've submitted the project to on the k10k site, it might take a while to be reviewed and (hopefully) accepted. I noticed by the category groupings available that the matchmaker service seems to be setup for larger scale or longer term efforts. No problems submitting the request for help mind you, just didn't seem to be setup for such a small and focused need. Lets see what happens.

2. April 21, 2002 01:15 AM

Quote this comment

Dave Posted…

Here is my attempt. Not sure if this is what you had in mind. I noticed that some of the regular expressions had to dance around possible HTML tags, so my approach was to remove the tags, make the changes, and restore the tags. This made the regular expressions much simpler (though I am not sure if I handle every possible case). Also, this script does not lend itself to the kinds of buttons that Francois includes in his example. It performs all of the changes in one fell swoop, when the textarea focus is lost.

3. April 21, 2002 01:35 AM

Quote this comment

Dave Posted…

Oog. I am finding some problems with my implementation. Damn you regular expressions!

4. April 21, 2002 01:41 AM

Quote this comment

Nate Posted…

Dave! Way to step up to the plate! No better way to “test the water” than by letting folks polk–a–stick at it right here. You‘ve mentioned problems, but I guess I’m not seeing them yet.

5. April 21, 2002 01:47 AM

Quote this comment

Nate Posted…

Ah, it seems that single quotations like: ‘ only want to be replaced if there’s a second one around. Which makes sense for double qoutes, which shouldn‘t be “left hanging by themselves”, but sometimes the single quote is used in words like: that’s great. Well, I‘ll stop pestering and wait for the next version of this awesome script.

6. April 21, 2002 01:52 AM

Quote this comment

Dave Posted…

Yep. The single quotes are the problem. Francois has the right idea with his TextPad regexes. I should have studied them a little more before I jumped in the fray. Live and learn!

7. April 21, 2002 02:53 AM

Quote this comment

Dave Posted…

OK, I think I fixed it. The single quotes/apostrophes seem to be working now. Thanks Francois for doing the legwork with the regexes. I made one minor alteration to the single–quote regex, and that was to make it match a single quote at the beginning of a string. This whole exercise has got me thinking about all the ways the apostrophe is used. 'Twas a learning experience. :)

8. April 21, 2002 10:34 AM

Quote this comment

Nate Posted…

Ok wonderful! A round of applause for Dave. I’ve installed the latest version of the wonderful filterChars.js script. This is great, dave you should publish this on gazingus, I can see it this being a super valuable tool. In fact, it might even be helpful to have a big ‘ol textarea somewhere with this script attached for everyday coding translation!

9. April 21, 2002 02:21 PM

Quote this comment

Todd Dominey Posted…

Someone should shoot this over to Ben and Mena at MT as a radio option when creating new entries. If that’s cool, of course. ;) Oh, and just as a test – “foo”

10. April 21, 2002 05:07 PM

Quote this comment

francois Posted…

Internet community. Never ceases to amaze me. Many thanks, Dave. Very clever that about removing the tags first — without them, the regexes are a cinch. But I don’t think I’d be able to use that approach for the Textpad macro (which I’m still struggling with).

Anyway, I really hope if this script travels around a bit (spread the word), proper quotes and dashes on blogs will start becoming the rule, rather than the exception. It certainly is the next logical step after writing about it. I’m going to be adding it to my own MT posting and commenting configuration, and if somebody hasn’t done so already, I’ll write Ben and Mena about it. Thanks to all again :)

11. April 22, 2002 08:46 AM

Quote this comment

Todd Dominey Posted…

I could be biased, since I use special characters all the time on my site, but this script seems important enough to have a quick page set up to contain it, along with a description and usage instructions so that others can easily link to it.

12. April 22, 2002 09:02 AM

Quote this comment

Dave Posted…

I will post a usage page on my web site shortly. First, I need to change the script so that it works with non–roman character sets. Should be an easy fix.

13. April 22, 2002 10:24 AM

14. April 22, 2002 07:07 PM

Quote this comment

Dave Posted…

I added a page on my web site describing the script and its usage. I also updated the script to accomodate international characters in one of the regular expressions. Might be overkill, but thought I would cover my bases.

15. April 23, 2002 12:14 PM

Quote this comment

Joshua Kaufman Posted…

Excellent work Dave! I love it.

16. April 23, 2002 05:15 PM

Quote this comment

francois Posted…

Just a few tests... Although the EM ‘n EN article recommends using a dash for ranges like 1–10, that would also mean screwing up emoticons :–( and hyphenated words like “font–weight”. And how is “” empty quotes and “ ” handled? And a single "? Just testing...

17. April 23, 2002 05:17 PM

Quote this comment

francois Posted…

All’s well then :)

18. April 23, 2002 06:10 PM

Quote this comment

Joshua Kaufman Posted…

I started a discussion over at moveabletype.org regarding implementing this in the Moveable Type “Create New Entry” form. It’s currently in the Tips/Tricks section but it may be better suited to the Request a Feature section.

19. April 24, 2002 09:27 AM

Quote this comment

francois Posted…

Scratch my last comment — all’s not well. Dave, hyphens should only be converted to dashes if there’s a space on either side.

Joshua, I think the Request A Feature section might be a better place. Of course, I think it’ll be possible for any of us to integrate Dave’s client–side script with MT’s blog posting forms. But if we want a server–side solution, as described here, we may have to wait for Ben to do it for us. (If he likes the idea :)

20. April 24, 2002 01:23 PM

Quote this comment

Joshua Kaufman Posted…

Yes, I’m sure it’ll be possible to integrate the script with MT’s blog posting forms but I can’t do it myself. Until Ben does the server–side integration, I know I, for one, would appreciate an MT hack tutorial for this script. Any takers?

21. April 24, 2002 02:47 PM

Quote this comment

Dave Posted…

I made the change Francois suggested above. The script now changes single dashes only if there are one or more spaces on both sides. Otherwise, it remains a hyphen (or minus). Is this behavior correct?

22. April 25, 2002 03:40 AM

Quote this comment

francois Posted…

Dave, re en–dashes: yes, that’s correct (but not implemented here yet – Nate?) And I think a double–hyphen can stay as it is — be converted to an em–dash with or without spaces either side. (And, uh, another optional improvement — it might be nice to be able to “escape” these characters with a \ if we absolutely want, say, a double–prime. Hacks beget hacks...)

23. April 25, 2002 03:44 AM

Quote this comment

francois Posted…

Joshua, I’m planning to implement Dave’s script on my comment forms and MT posting forms as soon as I get time — probably only next weekend as I’m on holiday this weekend. When I’ve done that, and assuming nobody else has done so yet, I’ll document the process on my site.

24. April 25, 2002 11:40 AM

Quote this comment

Joshua Kaufman Posted…

That would be fantastic Francois! Please keep the web–graphics community updated.

25. April 25, 2002 01:06 PM

Quote this comment

Nate Posted…

The new script is live here now. I think I’ve located the files which can be hacked in MT to provide this functionality when posting (rather than just commenting)–but I hesitate to post about it until I’ve tried it first, and somewhere safe, like on a fake temporary blog. Not enough time to play around.

26. April 28, 2002 03:30 PM

Quote this comment

samff Posted…

Nate, you think I’ve located the files which can be hacked in MT to provide this functionality when posting... whereabouts? I have some time and have been watching this space for someone else to do the dirty work ;) but I just so happen to have some free time....

27. April 28, 2002 03:31 PM

Quote this comment

samff Posted…

...[you]‘ve I meant....

28. April 28, 2002 04:50 PM

Quote this comment

Nate Posted…

samff, I think the files in question are located in the [mt install root] [tmpl] [cms] folder. Honestly I could be way off here, please be sure to back up your files and be careful. We’d really like to hear if it works out. Thanks!

29. May 1, 2002 04:15 PM

Quote this comment

samff Posted…

WooHoo! It’s not so hard to implement this script within the MT editing environment. In fact, you only have to alter one .tmpl!

  • back up your copy of /mt/tmpl/cms/ — yeah, all of it, just in case ;)
  • copy my version of edit_entries.txt (IE might try to parse this file, by the way)
  • overwrite your local copy of edit_entries.tmpl with this .txt file
  • upload the new .tmpl and the .js (alter the path, if necessary)
  • This seems to work for New and Editing Entries. Have fun!

    PS Any chance of adding the conversion of & to &?

    30. May 1, 2002 05:50 PM

    Quote this comment

    Nate Posted…

    Excellent Samff! I’ll fold in the alterations to the webgraphics moveabletype cms, thank you for sharing your findings.
    It seems that the end of spring has brought about the desire for many redesigns, whether directly related to the reboot project or not. Webgraphics is no exception, but unfortunately time is much to sparse for any progress for at least a short while.

    31. February 11, 2003 10:34 AM

    Quote this comment

    ff Posted…

    ff

    32. February 7, 2004 12:47 PM

    Quote this comment

    Tom Posted…

    Great tool, Dave!

    Maybe you could convert three dots (...) to &#8230 (…)

    33. August 17, 2005 11:32 AM

    Quote this comment

    Bryan Posted…

    Tom

    Just add the following lines in the appropriate places

    var ELIPSIS = new RegExp( '\\.\\.\\.', 'g' );

    formatted = formatted.replace( ELIPSIS, '…' );