Convert a DOM DocumentType into a string, e.g. "<!DOCTYPE html>"

doctype-to-string/ index.js
14 lines
462 B

  1. export default function doctypeToString(doctype) {
  2. if (doctype === null) {
  3. return ''
  4. }
  5. const doctypeString = `<!DOCTYPE ${doctype.name}`
  6. + (doctype.publicId ? ` PUBLIC "${doctype.publicId}"` : '')
  7. + (doctype.systemId
  8. ? (doctype.publicId ? `` : ` SYSTEM`) + ` "${doctype.systemId}"`
  9. : ``)
  10. + (doctype.internalSubset ? ` [${doctype.internalSubset}]` : ``)
  11. + `>`
  12. return doctypeString
  13. }