Re: string.replace not working - D'OH!
On Feb 17, 2008 3:48 PM, I wrote: [earlier missive deleted] > > I realized that the string.replace function doesn't actually do > anything to the string, so I have to assign b.replace to a variable > and write that back, something like 'var c = b.replace...', then > document.body.innerHTML = c. That, though, writes the string back > literally into the page, even when I replace < with <, etc. Actually, it doesn't - my mistake - it creates links properly. > So, I'm going to do a document.evaluate to get all the text nodes I > want, and then process them, replacing any citations to US reports > with a document.createElement('a'). This, it turns out, although I think it would be more elegant, is rather hard to do; I can't quite figure out how to insert a link element inside a text node. pw -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: string.replace not working - D'OH!
On Feb 17, 2008 11:38 AM, I wrote: > At this URL (which happens to be Brown v. Bd. of Ed.), > http://bulk.resource.org/courts.gov/c/US/347/347.US.483.html, I'm > trying to convert data which looks so, " 123 U.S. 456", into a link, > so, " 123 U.S. 456". > > This text.replace works on a literal string: "blah blah 123 U.S. 456 > blah blah 789 U.S. 123".replace(/\s+(\d+)\s+U\.S\.\s+(\d+)/g, " href=\"../$1/$1.US.$2.html\">$&"); replacing both > citations with the appropriate link. > > but I cannot get it to work on the document. Here's the script: > > var b = document.body.innerHTML; > b.replace(/\s+(\d+)\s+U\.S\.\s+(\d+)/g, " href=\"../$1/$1.US.$2.html\">$&"); > b = "" + b; > document.body.innerHTML = b; I realized that the string.replace function doesn't actually do anything to the string, so I have to assign b.replace to a variable and write that back, something like 'var c = b.replace...', then document.body.innerHTML = c. That, though, writes the string back literally into the page, even when I replace < with <, etc. So, I'm going to do a document.evaluate to get all the text nodes I want, and then process them, replacing any citations to US reports with a document.createElement('a'). Sorry to be so thick today! pw -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
string.replace not working
Hello: A new repository of US caselaw[1] has recently been released, and I'm trying to make it a little more useful. At this URL (which happens to be Brown v. Bd. of Ed.), http://bulk.resource.org/courts.gov/c/US/347/347.US.483.html, I'm trying to convert data which looks so, " 123 U.S. 456", into a link, so, " 123 U.S. 456". This text.replace works on a literal string: "blah blah 123 U.S. 456 blah blah 789 U.S. 123".replace(/\s+(\d+)\s+U\.S\.\s+(\d+)/g, " $&"); replacing both citations with the appropriate link. but I cannot get it to work on the document. Here's the script: var b = document.body.innerHTML; b.replace(/\s+(\d+)\s+U\.S\.\s+(\d+)/g, " $&"); b = "" + b; document.body.innerHTML = b; I stuck the 'modified content' comment in there as a sanity check, and it appears in the modified source. I tried wrapping the last line inside a window.addEventListener load statement, but it made no difference. I have a feeling I'm missing something incredibly obvious! I re-read the common pitfalls chapter, but saw nothing there. Any insights would be much appreciated. pw [1] See http://bulk.resource.org/courts.gov/ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]