import { Strapi } from '@strapi/strapi'; export default ({ strapi }: { strapi: Strapi }) => { strapi.db?.lifecycles.subscribe({ beforeUpdate(event) { const tiptapModel = Object.values(event.model.attributes)?.filter( (model: any) => model.customField === 'plugin::tiptap.tiptap' ); if (tiptapModel.length > 0) { const { data } = event.params; tiptapModel.map((model: any) => { if (data[model.columnName]) { data[model.columnName] = data[model.columnName] .replace(new RegExp(/(

)?<\/?htmlsource>(<\/p>)?/g), '') .replace(new RegExp(/</g), '<') .replace(new RegExp(/>/g), '>'); } }); } }, beforeCreate(event) { const tiptapModel = Object.values(event.model.attributes)?.filter( (model: any) => model.customField === 'plugin::tiptap.tiptap' ); if (tiptapModel.length > 0) { const { data } = event.params; tiptapModel.map((model: any) => { if (data[model.columnName]) { data[model.columnName] = data[model.columnName] .replace(new RegExp(/<\/?(htmlsource)>/g), '') .replace(new RegExp(/</g), '<') .replace(new RegExp(/>/g), '>'); } }); } } }); };