Skip to content

Instantly share code, notes, and snippets.

@johan
Created October 30, 2012 00:36
Show Gist options
  • Save johan/3977584 to your computer and use it in GitHub Desktop.
Save johan/3977584 to your computer and use it in GitHub Desktop.
A more useful DocumentType.prototype.toString implementation than present-day browsers provide.
# browser portability notes on this here: http://help.dottoro.com/ljlsvbgj.php
window.DocumentType::toString = ->
pub = " #{JSON.stringify pub}" if pub = @publicId or ''
sys = " #{JSON.stringify sys}" if sys = @systemId or ''
availability = ''
availability = ' SYSTEM' if sys
availability = ' PUBLIC' if pub
declarations = " [#{declarations}]" if declarations = @internalSubset or ''
"<!DOCTYPE #{@name}#{availability}#{pub}#{sys}#{declarations}>"
// browser portability notes on this here: http://help.dottoro.com/ljlsvbgj.php
window.DocumentType.prototype.toString = function() {
var pub = this.publicId || ''
, sys = this.systemId || ''
, availability = pub ? ' PUBLIC' : sys ? ' SYSTEM' : ''
, declarations = this.internalSubset || ''
;
if (pub) pub = ' ' + JSON.stringify(pub);
if (sys) sys = ' ' + JSON.stringify(sys);
if (declarations) declarations = ' [' + declarations + ']';
return '<!DOCTYPE ' + this.name + availability + pub + sys + declarations + '>';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment