473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

inserting text into HTML

I have a big list of HTML files, which need to be updated with a
common text.
<script language=JavaScript
src="./highlight.js"></script>

I need to add the above line in each of the html files, before the
text "<\head>". All the HTML files have this text and I think some
kind of search on this string and either replacing "</head>" with the
text above and appending "<\headto it, might be one way to do it or
just find the <\headpart and insert the text before that.

On similar lines, the text below goes towards the end. The problem is
similar to the above one and I think all that needs to be done, is
read the text below from a file, do a similar search for some text
below which this insert part should go and put it there.
<p><script type="text/javascript">var mailSubject = 'Hardware
Overview';
var mailBody = 'Your Technical Support Team hopes this topic will
be helpful: ' + location.href;
var mailDisplay = 'Click here to email this topic.';
document.write(
'<a href="mailto:Yo******@YourAddress.com'
+ '?subject=' + escape(mailSubject)
+ '&body=' + escape(mailBody)
+ '">' + mailDisplay + '</a>'
);</script></p>

<script type="text/javascript"
language=JavaScript1.2><!--
beginSearch ();
//--></script>
Any ideas would be helpful. I do not know much about perl and hence
the more the better.
Thanks a lot

May 18 '07 #1
2 4360
Scripsit Slain:
I need to add the above line in each of the html files, before the
text "<\head>". All the HTML files have this text
Oh, you mean </head>. Are you sure? Well, then you could write a Perl
few-liner to do the job, or ask someone to write it for you. You would still
need to learn how to run a Perl program _on the server_. The program could
be something like the following (untested):

undef $/;
while(<*.html>) {
$filename = $_;
open(FILE,"<$filename")
|| die "Can't open file \"$filename\":\n $!";
$stuff = <FILE>;
$stuff =~ s?</head>?<script language=JavaScript
src="./highlight.js"></script></head>?;
close(FILE);
open(FILE,">$filename")
|| die "Can't open file \"$filename\" for writing:\n $!";
print FILE $stuff;
close(FILE);
}

Of course, this isn't real about authoring in HTML. The c.i.w.a.tools group
would have been more suitable. And of course you might find an editor with a
built-in multi-file string replace feature that could be used for the job.
On similar lines, the text below goes towards the end.
Well, of course it would be similar, with similar solutions, though
detecting the end is non-trivial. But...
var mailDisplay = 'Click here to email this topic.';
document.write(
'<a href="mailto:Yo******@YourAddress.com'
+ '?subject=' + escape(mailSubject)
+ '&body=' + escape(mailBody)
+ '">' + mailDisplay + '</a>'
);</script></p>
This sounds like a _very_ clueless method of giving some users some poor way
of contacting you, instead of simply telling all users your email address.
So if you do something _so_ stupid, at least do it via some server-side
include feature, so that when you come to your senses, you won't have to fix
a zillion files again but can simply fix the included file.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

May 18 '07 #2
Slain wrote :
I have a big list of HTML files, which need to be updated with a
common text.
<script language=JavaScript
src="./highlight.js"></script>
First language is deprecated; type is the normal replacement and it is
both backward and forward-compatible.
I need to add the above line in each of the html files, before the
text "<\head>".
It's </head>.
Just use an advanced text editor to do that. It's simple to do.

Free software (libre/open-source) text editors:
http://en.wikipedia.org/wiki/List_of...open-source.29
All the HTML files have this text and I think some
kind of search on this string and either replacing "</head>" with the
text above and appending "<\headto it, might be one way to do it or
just find the <\headpart and insert the text before that.

On similar lines, the text below goes towards the end. The problem is
similar to the above one and I think all that needs to be done, is
read the text below from a file, do a similar search for some text
below which this insert part should go and put it there.
<p><script type="text/javascript">var mailSubject = 'Hardware
Overview';
var mailBody = 'Your Technical Support Team hopes this topic will
be helpful: ' + location.href;
var mailDisplay = 'Click here to email this topic.';
document.write(
'<a href="mailto:Yo******@YourAddress.com'
+ '?subject=' + escape(mailSubject)
+ '&body=' + escape(mailBody)
+ '">' + mailDisplay + '</a>'
);</script></p>
You're overreaching here in my opinion. And your code has problems.
First, you must escape the ampersand with &amp;
Second, you are adding a closing </ptag when there is not a start <p>.
Third, you'll need to escape the closing tags inside the document.write
block:

Common HTML Validation Problems
Writing HTML in a SCRIPT element
http://www.htmlhelp.com/tools/valida...html.en#script

HTML 4, Section 18.2.4 Dynamic modification of documents
http://www.w3.org/TR/html4/interact/....html#h-18.2.4

HTML 4, Appendix B.3.2 Specifying non-HTML data, Element Content
http://www.w3.org/TR/html4/appendix/...html#h-B.3.2.1
"When script or style data is the content of an element (SCRIPT and
STYLE), the data begins immediately after the element start tag and ends
at the first ETAGO ("</") delimiter followed by a name start character
([a-zA-Z]); note that this may not be the element's end tag. Authors
should therefore escape "</" within the content."

<script type="text/javascript"
language=JavaScript1.2><!--
As mentioned already, language attribute is deprecated.

Don't use HTML comments as they are unneeded, unnecessary and
potentially harmful.

Don't Use HTML Comments In Script Blocks
http://www.javascripttoolbox.com/bes...ices/#comments

beginSearch ();
//--></script>

>

Any ideas would be helpful.

Validate your markup code! Preferably with/for a strict DTD.
http://validator.w3.org/

Gérard
--
Using Web Standards in your Web Pages (Updated Apr. 2007)
http://developer.mozilla.org/en/docs...your_Web_Pages
May 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Miranda | last post by:
Hi, I have a ASP/vbscript program that generates random passwords. The problem is I need to insert those passwords into an Access database of 327 clients. I have the random password program...
2
by: Wim Roffal | last post by:
I want to insert an option into a select. I know you can do something like: - Myselect.options = new Option('Hello 3'); but that doesn't do what I want because it overwrites an existing option....
2
by: j van c | last post by:
I have a menubar on my main page. when clicking on a menu item I want to open an existing htm page at a certain position in my main page I use no frames. It should be replacing a div-section....
1
by: Scott Chapman | last post by:
I am working with Python (psycopg). I have HTML with embedded Python that I'm inserting into a database and it could contain any character. Single quotes, at least, must be escaped (to two...
1
by: ajk | last post by:
. Hi, All: I know how to insert files into a Word doc using C#. However, the program I've written to do this runs much too slowly. The "myObj".Application.Selection.InsertFile method executes...
5
by: bob44 | last post by:
Hi, I recently created a mysql database using phpmyadmin. I then proceeded to make a form to insert data into the database, but the problem is that the form is only able to insert one record, and...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
5
by: atlanteavila | last post by:
Hello all, I have a problem with inserting text with quotes, or html code in to a MYSql Database. I've been trying to create my own content management system, and unfortunately I've come accross a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.