Skip to content

Instantly share code, notes, and snippets.

@johan
Created October 30, 2012 00:36

Revisions

  1. johan revised this gist Oct 31, 2012. 2 changed files with 6 additions and 19 deletions.
    12 changes: 3 additions & 9 deletions document.doctype.toString.coffee
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,3 @@
    # 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}>"
    # With thanks to Stewart Brodie for the reminder: http://goo.gl/IHa4p
    # (See old version of this gist for a more roundabout hack I came up with)
    window.DocumentType::toString = -> (new XMLSerializer).serializeToString @
    13 changes: 3 additions & 10 deletions document.doctype.toString.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,5 @@
    // browser portability notes on this here: http://help.dottoro.com/ljlsvbgj.php
    // With thanks to Stewart Brodie for the reminder: http://goo.gl/IHa4p
    // (See old version of this gist for a more roundabout hack I came up with)
    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 + '>';
    return (new XMLSerializer).serializeToString(this);
    };
  2. johan revised this gist Oct 30, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions document.doctype.toString.coffee
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ 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)
    availability = ' SYSTEM' if sys
    availability = ' PUBLIC' if pub
    declarations = " [#{declarations}]" if declarations = @internalSubset or ''
    "<!DOCTYPE #{@name}#{availability}#{pub}#{sys}#{declarations}>"
  3. johan revised this gist Oct 30, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion document.doctype.toString.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    window.DocumentType.prototype.toString = function() {
    var pub = this.publicId || ''
    , sys = this.systemId || ''
    , availability = pub ? ' PUBLIC' : ' SYSTEM' : ''
    , availability = pub ? ' PUBLIC' : sys ? ' SYSTEM' : ''
    , declarations = this.internalSubset || ''
    ;
    if (pub) pub = ' ' + JSON.stringify(pub);
  4. johan created this gist Oct 30, 2012.
    9 changes: 9 additions & 0 deletions document.doctype.toString.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # 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}>"
    12 changes: 12 additions & 0 deletions document.doctype.toString.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    // 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' : ' 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 + '>';
    };