Closed Thread Icon

Topic awaiting preservation: Typesetting Problems (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=23893" title="Pages that link to Topic awaiting preservation: Typesetting Problems (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Typesetting Problems <span class="small">(Page 1 of 1)</span>\

 
Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 11-02-2004 17:23

I am making a website for a homework assignment, and one of the things I wanted to do on it was to make my life easy and automatically convert certain constructs into their proper typeset equivalent (i.e. double primes into the proper double quotes, three periods into an ellipsis, two hypens into a dash, etc.). I wrote some code, and it ended up working flawlessly in Firefox, but failing horribly in MSIE 6 (the page doesn't display anything other than the body's background colod). Does anyone know why this might be?

code:
window.onload = function() {
var paragraph = document.getElementsByTagName("p");

for(var i = 0; i < paragraph.length; ++i) {
var typeset = paragraph[i].innerHTML;

// Dash
typeset = typeset.replace(/--/g, "&#8211;");

// Ellipsis
typeset = typeset.replace(/\.\.\./g, "&#8230;");

// Single Quotes
typeset = typeset.replace(/(\s+)'/g, "$1&#8216;");
typeset = typeset.replace(/'(\s+)/g, "&#8217;$1");

// Double Quotes
typeset = typeset.replace(/(\s+)"/g, "$1&#8220;");
typeset = typeset.replace(/"(\s+)/g, "&#8221;$1");

paragraph[i].innerHTML = typeset;
}
}



Thanks, guys!

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

(Edited by Iron Wallaby on 11-02-2004 17:27)

Blaise
Bipolar (III) Inmate

From: London
Insane since: Jun 2003

posted posted 11-02-2004 17:31

Well off the cuff, it may be to do with how you've declared your onLoad function, sometimes you may eneed to put the window.onLoad call near the bottom of the page, ensuring that it's called after all the elements if refers to in it's function have already been loaded, or maybe put an onload attribute in your body tag.

Can't say for sure this is the answer but I've had some strange things like this happen before with using the window.onLoad, so it may be worth a try.

Good luck!

Cheers,

Blaise.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 11-02-2004 17:39

That doesn't work either, but at least it dies more gracefully -- the page remains unchanges as far as typesetting goes, but at least displays properly. If it cannot be solved, that will be a useable solution -- thanks

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-02-2004 18:20

hmm..

This page works for me in IE 6.0 Win XP

code:
<html>
<head>
<script>

window.onload = function() {
var paragraph = document.getElementsByTagName("p");

for(var i = 0; i < paragraph.length; ++i) {
var typeset = paragraph[i].innerHTML;

// Dash
typeset = typeset.replace(/--/g, "&#8211;");

// Ellipsis
typeset = typeset.replace(/\.\.\./g, "&#8230;");

// Single Quotes
typeset = typeset.replace(/(\s+)'/g, "$1&#8216;");
typeset = typeset.replace(/'(\s+)/g, "&#8217;$1");

// Double Quotes
typeset = typeset.replace(/(\s+)"/g, "$1&#8220;");
typeset = typeset.replace(/"(\s+)/g, "&#8221;$1");

paragraph[i].innerHTML = typeset;
}
}
</script>
</head>
<body>
<p>
This is something...
</p>
<p>
This is something -- else
<p>
This is 'another'
</p>

<p>
This is "another 2"
</p>
</div>

</body>
</html>





.:[ Never resist a perfect moment ]:.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 11-02-2004 19:10

Ok -- problem pinpointed.

The problems result when I have the javascript code in an external file. Apparently, MSIE doesn't like to load the second file and THEN process the onLoad handler...

[EDIT:]Figured it out. MSIE can't handle XHTML. Duh.[/EDIT]

Thanks!

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

(Edited by Iron Wallaby on 11-02-2004 19:23)

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 11-03-2004 01:32

Ok, final form: easily extendable. If any of you feel the need to use it or expand upon it, feel free:

code:
var map = [
[/---/g, "&mdash;"], // em-dash
[/--/g, "&ndash;"], // en-dash
[/(\S+)'(\S+)/g, "$1&apos;$2"], // apostrophe (bordered on both sides)
[/'(\S+)/g, "&lsquo;$1"], // left single quote (bordered on the right)
[/(\S+)'/g, "$1&rsquo;"], // right single quote (bordered on the left)
[/"(\S+)/g, "&ldquo;$1"], // left double quote (bordered on the right)
[/(\S+)"/g, "$1&rdquo;"] // right double quote (bordered on the left)
];

var typeset = function() {
var paragraph = document.getElementsByTagName("p");

for(var i = paragraph.length; i--; ) {
var typeset = paragraph[i].innerHTML;

for(var j = map.length; j--; )
typeset = typeset.replace(map[j][0], map[j][1]);

paragraph[i].innerHTML = typeset;
}
}



I would do ligatures too (fi, fl, ff, ft, ffi, ffl, et, etc.) if MSIE didn't suck.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

« BackwardsOnwards »

Show Forum Drop Down Menu