Files
Foundry-VTT-Docker/resources/app/dist/database/documents/journal-page.mjs
2025-01-04 00:34:03 +01:00

1 line
1.5 KiB
JavaScript

import ServerDocumentMixin from"../backend/server-document.mjs";import BaseJournalEntryPage from"../../../common/documents/journal-entry-page.mjs";import showdown from"showdown";import{cleanHTML}from"../validators.mjs";export default class JournalEntryPage extends(ServerDocumentMixin(BaseJournalEntryPage)){static _migrationRegistry=[...super._migrationRegistry,{fn:migrateBaseToText,version:12}];static#t=(()=>(Object.entries(CONST.SHOWDOWN_OPTIONS).forEach((([t,e])=>showdown.setOption(t,e))),new showdown.Converter))();async _preCreate(t,e,r){if(!1===await super._preCreate(t,e,r))return!1;this.text.format===CONST.JOURNAL_ENTRY_PAGE_FORMATS.MARKDOWN?this.updateSource({"text.content":this.#e(this.text.markdown)}):this.updateSource({"text.markdown":void 0})}async _preUpdate(t,e,r){if(!1===await super._preUpdate(t,e,r))return!1;if("text"in t){const e="format"in t.text?t.text.format??CONST.JOURNAL_ENTRY_PAGE_FORMATS.HTML:this.text.format;if(e===CONST.JOURNAL_ENTRY_PAGE_FORMATS.MARKDOWN){const r="markdown"in t.text?t.text.markdown:this.text.markdown;t.text.content=this.#e(r,e),void 0!==this.text.content&&(t.text.content||="")}else this.text.markdown?t.text.markdown="":"markdown"in t.text&&delete t.text.markdown}}#e(t,e){const r=CONST.JOURNAL_ENTRY_PAGE_FORMATS,n=(e??this.text.format)===r.MARKDOWN&&t;if("text"!==this.type||!n)return;let o=JournalEntryPage.#t.makeHtml(t);return cleanHTML(o)}}function migrateBaseToText(t){return t.type===CONST.BASE_DOCUMENT_TYPE&&(t.type="text",!0)}