util.js 735 B

123456789101112131415161718192021222324252627
  1. (function() {
  2. singlefile.util = {};
  3. function getDoctype(doc) {
  4. var docType = doc.doctype, docTypeStr;
  5. if (docType) {
  6. docTypeStr = "<!DOCTYPE " + docType.nodeName;
  7. if (docType.publicId) {
  8. docTypeStr += " PUBLIC \"" + docType.publicId + "\"";
  9. if (docType.systemId)
  10. docTypeStr += " \"" + docType.systemId + "\"";
  11. } else if (docType.systemId)
  12. docTypeStr += " SYSTEM \"" + docType.systemId + "\"";
  13. if (docType.internalSubset)
  14. docTypeStr += " [" + docType.internalSubset + "]";
  15. return docTypeStr + ">\n";
  16. }
  17. return "";
  18. }
  19. singlefile.util.getDocContent = function(doc, docElement) {
  20. docElement = docElement || doc.documentElement;
  21. return getDoctype(doc) + docElement.outerHTML;
  22. };
  23. })();