dom.ts 586 B

1234567891011121314151617181920212223
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormFieldValue } from '#shared/components/Form/types.ts'
  3. export const domFrom = (html: string, document_ = document) => {
  4. const dom = document_.createElement('div')
  5. dom.innerHTML = html
  6. return dom
  7. }
  8. export const removeSignatureFromBody = (input: FormFieldValue) => {
  9. if (!input || typeof input !== 'string') {
  10. return input
  11. }
  12. const dom = domFrom(input)
  13. dom
  14. .querySelectorAll('div[data-signature="true"]')
  15. .forEach((elem) => elem.remove())
  16. return dom.innerHTML
  17. }