Ben said:
I have THE BENGAL LEAGUE but in order to use small-caps I would need
The Bengal League.
Indeedy, so why don't you?
Why can't you just change it to title-case ("The Bengal League") in the
HTML, and then apply small-caps using CSS?
If you have some sort of allergy to that, then you could use a bit of
Javascript trickery:
<h2 id="foo">THE BENGAL LEAGUE</h2>
<script type="text/javascript">
//
http://querylog.com/q/Javascript+converting+string+to+TitleCase
/**
* Extend the native String class to include an array that lists silly
* words that shouldn't be capitalised.
*/
String.noLC = new Object
({the:1, a:1, an:1, and:1, or:1, but:1, aboard:1,
about:1, above:1, across:1, after:1, against:1,
along:1, amid:1, among:1, around:1, as:1, at:1,
before:1, behind:1, below:1, beneath:1, beside:1,
besides:1, between:1, beyond:1, but:1, by:1, 'for':1,
from:1, 'in':1, inside:1, into:1, like:1, minus:1,
near:1, of:1, off:1, on:1, onto:1, opposite:1,
outside:1, over:1, past:1, per:1, plus:1,
regarding:1, since:1, than:1, through:1, to:1,
toward:1, towards:1, under:1, underneath:1, unlike:1,
until:1, up:1, upon:1, versus:1, via:1, 'with':1,
within:1, without:1});
/**
* Extend the native String class with a titleCase function.
*/
String.prototype.titleCase = function ()
{
// Special case for just one word.
if (!this.match(/(\s+)/))
return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
// Multiple words, so split into words, storing whitespace safely.
var gaps = this.match(/(\s+)/g);
var parts = this.split(/\s+/);
if ( parts.length == 0 ) return '';
var fixed = new Array();
for ( var i in parts )
{
var fix = '';
if ( String.noLC[parts
] )
fix = parts.toLowerCase();
else if ( parts.match(/^([A-Z]\.)+$/i) ) // will mess up "i.e." and like
fix = parts.toUpperCase();
else if ( parts.match(/^[^aeiouy]+$/i) ) // voweless words are almost always acronyms
fix = parts.toUpperCase();
else
fix = parts.substr(0,1).toUpperCase() +
parts.substr(1,parts.length);
fixed.push(fix);
}
fixed[0] = fixed[0].substr(0,1).toUpperCase() +
fixed[0].substr(1,fixed[0].length);
var out = '';
for ( var i in fixed )
{
if (gaps)
out += fixed + gaps;
else
out += fixed;
}
return out;
}
var foo = document.getElementById('foo');
foo.innerHTML = foo.innerHTML.titleCase();
</script>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!