11import { Notice , TFile } from "obsidian" ;
22import type AtmospherePlugin from "../main" ;
3+ import type { ContentFormat } from "../settings" ;
34import { createDocument , putDocument , getPublication , markdownToLeafletContent , stripMarkdown , markdownToPcktContent , buildDocumentUrl } from "../lib" ;
45import { PublicationSelection , SelectPublicationModal } from "../components/selectPublicationModal" ;
56import { type ResourceUri , } from "@atcute/lexicons" ;
@@ -87,6 +88,17 @@ async function updateFrontMatter(
8788 } ) ;
8889}
8990
91+ function normalizeFormat ( raw : unknown ) : ContentFormat | undefined {
92+ if ( typeof raw !== "string" ) {
93+ return undefined ;
94+ }
95+ const trimmed = raw . trim ( ) . toLowerCase ( ) ;
96+ if ( trimmed === "leaflet" || trimmed === "pckt" || trimmed === "plaintext" ) {
97+ return trimmed ;
98+ }
99+ return undefined ;
100+ }
101+
90102
91103async function buildDocumentRecord ( plugin : AtmospherePlugin , file : TFile ) : Promise < { record : SiteStandardDocument . Main ; docUri ?: ResourceUri } > {
92104 const full = await plugin . app . vault . read ( file ) ;
@@ -105,6 +117,7 @@ async function buildDocumentRecord(plugin: AtmospherePlugin, file: TFile): Promi
105117 let path : string | undefined ;
106118 let tags : string [ ] | undefined ;
107119 let publishedAt : string | undefined ;
120+ let format : ContentFormat | undefined ;
108121 if ( fm ) {
109122 pubUri = fm [ "atPublication" ] ;
110123 docUri = fm [ "atDocument" ] as ResourceUri ;
@@ -114,6 +127,7 @@ async function buildDocumentRecord(plugin: AtmospherePlugin, file: TFile): Promi
114127 tags = fm [ "tags" ] && Array . isArray ( fm [ "tags" ] ) ? fm [ "tags" ] : undefined ;
115128 publishedAt = fm [ "publishedAt" ] ; // Preserve existing if updating
116129 }
130+ format = normalizeFormat ( fm ?. [ "format" ] ) ;
117131
118132 if ( ! title && plugin . settings . publish . useFirstHeaderAsTitle ) {
119133 title = extractFirstH1 ( content ) ;
@@ -142,10 +156,20 @@ async function buildDocumentRecord(plugin: AtmospherePlugin, file: TFile): Promi
142156 let textContent = stripMarkdown ( content ) ;
143157
144158 let richContent : PubLeafletContent . Main | BlogPcktContent . Main | null = null ;
159+ const publicationFormat = pubUri ? normalizeFormat ( plugin . settings . publicationFormats ?. [ pubUri ] ) : undefined ;
160+ let contentFormat : ContentFormat = "plaintext" ;
145161 if ( pub ?. url . contains ( "leaflet.pub" ) ) {
146- richContent = markdownToLeafletContent ( content )
162+ contentFormat = "leaflet" ;
147163 } else if ( pub ?. url . contains ( "pckt.blog" ) ) {
148- richContent = markdownToPcktContent ( content )
164+ contentFormat = "pckt" ;
165+ } else {
166+ contentFormat = format ?? publicationFormat ?? "plaintext" ;
167+ }
168+
169+ if ( contentFormat === "leaflet" ) {
170+ richContent = markdownToLeafletContent ( content ) ;
171+ } else if ( contentFormat === "pckt" ) {
172+ richContent = markdownToPcktContent ( content ) ;
149173 }
150174
151175 let record = {
0 commit comments