Omit needless words, codified
I continue to try to improve my writing. “Omit needless words” is all well and good, but identifying needless words can be a difficult task for the untrained eye. Paul Ford’s Passivator bookmarklet highlights adverbs and passive verbs, both of which can indicate weak writing.
I wonder how well Joyce would have fared with his "Ulysses". Would a single page survive? :)
M.
Moose - 28th March 2004 00:23 - #
Paul Ford - 28th March 2004 02:03 - #
Tom - 28th March 2004 19:35 - #
Simon Willison - 28th March 2004 20:10 - #
Paul Ford - 28th March 2004 20:30 - #
Gina - 30th March 2004 22:27 - #
The problem is innerHTML is non-standard.
Apparently, Mozilla's DOM implementation for XHTML-MIME'd content doesn't support it.
That, unforunately, kills that chance of using string.replace(/regex/,"$1<span>$2...") to do the work.
I took it as a personal challenge to get this working using DOM manipulation, since I could use the practice.
But it's turned out to be surprisingly non-trivial. I hadn't finished it yet, and so had not commented.
But my advice to people writing code for content with the XHTML mime-type is to use DOM 2 Core at most. Don't expect anything non-standard in an XHTML-mode client (at this point), and I'm not even sure it's safe to expect HTML DOM.
Jeremy Dunck - 30th March 2004 23:04 - #
Oh yeah, another thing about the Passivator, maybe it could be made to recognize the imperfect tense? Possibly with:
/(?:was|were) \w*ing/igm(that would be the regular expression to match imperfect [or at least, I hope it works])Yeah, I heard about innerHTML not being standard. (on scriptygoodness, I think)
Eh... that's not good. How else are you supposed to do it? You could use textContent to match it, I suppose, but I still don't know how you'd make the span tags. document.createElement; document.replaceChild, but what would you replace?
Tom - 31st March 2004 05:38 - #
You have to split the textNodes, and replace the node containing the offending bit of text with a span containing the text.
I just haven't figured out how to get an offset (necessary for the split) from a RegExp match. The hack approach I came up with is to split all textNodes into tokens containing with all whitespace or all non-whitespace, and then if the RegExp matches, do the swap.
innerHTML is damned useful-- there's a significant disconnect between the standard and common usage here.
Jeremy Dunck - 31st March 2004 17:40 - #
The javascript on Paul's page has an error in the regex that matches passive verbs. The regex for "you're" is missing the escaping back slash.
This is great and all, but what about something to use in your favorite editor? I don't use Word, or the like when writing, especially for Blogs.
Tzicha - 31st March 2004 21:11 - #
If you want to fix bugs other than the XHTML issue, there is also the problem that it will only execute the replacements if verbsRE is satisfied.
As far as I can tell, this could be completely removed:
if(verbsRE.test(tempNodeVal))
Jeremy Dunck - 31st March 2004 22:20 - #
Maybe you could use charAt? Or you could split every single word up (matching a space) and loop through those textNodes.
Oh yeah, you're right. He fixed it now, though.
I was going to say that. :-D
Tom - 1st April 2004 05:19 - #
um .... "Omit needless words" ... isn't that a bit wordy?
Eschew Surplusage.
:-)
For a good lesson in writing, pick up the SHORT book "Elements of Style" by Strunk & White. Its the best 90 pages you can give to your writing.
Erik
Erik - 4th May 2004 02:29 - #
Simon Willison - 4th May 2004 04:59 - #