@@ -27,46 +27,11 @@ async function ensureDir(dir: string,) {
2727 }
2828}
2929
30- /**
31- * Strip entities that TipTap's markdown serializer produces for
32- * empty paragraphs / list items. Left in the file they render as literal
33- * text on reload.
34- */
35- function stripNbsp ( markdown : string , ) : string {
36- return markdown . replace ( / & n b s p ; / g, "" , ) ;
37- }
38-
39- const ZWSP = "\u200B" ;
40-
41- /**
42- * Convert blank lines in markdown into zero-width-space paragraphs so
43- * TipTap renders them as visible empty lines in the editor.
44- */
45- function preserveBlankLines ( markdown : string , ) : string {
46- return markdown
47- . trimEnd ( )
48- // 2+ blank lines → ZWSP paragraph
49- . replace ( / \n { 3 , } / g, `\n\n${ ZWSP } \n\n` , )
50- // Single blank line: regular bullet → task item
51- . replace ( / ( [ - * ] (? ! \[ [ x X ] \] ) .+ ) \n \n ( [ - * ] \[ [ x X ] \] ) / g, `$1\n\n${ ZWSP } \n\n$2` , )
52- // Single blank line: task item → regular bullet
53- . replace ( / ( [ - * ] \[ [ x X ] \] .+ ) \n \n ( [ - * ] (? ! \[ [ x X ] \] ) ) / g, `$1\n\n${ ZWSP } \n\n$2` , ) ;
54- }
55-
56- /**
57- * Normalize serialized markdown for writing to disk:
58- * strip ZWSP characters and collapse runs of 3+ newlines back to 2.
59- */
60- function normalizeForSave ( markdown : string , ) : string {
61- return markdown . replace ( / \u200B / g, "" , ) . replace ( / \n { 3 , } / g, "\n\n" , ) ;
62- }
63-
6430export async function saveDailyNote ( note : DailyNote , ) : Promise < void > {
6531 const noteDir = await getNoteDir ( note . date , ) ;
6632 await ensureDir ( noteDir , ) ;
6733 const filepath = await getNotePath ( note . date , ) ;
68- // Convert asset:// URLs back to relative paths, strip ZWSP, normalize blanks
69- let body = normalizeForSave ( stripNbsp ( unresolveMarkdownImages ( note . content , ) , ) , ) ;
34+ let body = unresolveMarkdownImages ( note . content , ) ;
7035 if ( ! body . endsWith ( "\n" , ) ) body += "\n" ;
7136 await writeTextFile ( filepath , buildFrontmatter ( note . city , body , ) , ) ;
7237}
@@ -81,10 +46,7 @@ export async function loadDailyNote(date: string,): Promise<DailyNote | null> {
8146
8247 const raw = await readTextFile ( filepath , ) ;
8348 const { city, body, } = parseFrontmatter ( raw , ) ;
84- // Strip from existing files, resolve asset paths, then
85- // convert blank lines into ZWSP paragraphs so TipTap shows them.
86- const resolved = await resolveMarkdownImages ( stripNbsp ( body , ) , ) ;
87- const content = preserveBlankLines ( resolved , ) ;
49+ const content = await resolveMarkdownImages ( body , ) ;
8850 return { date, content, city, } ;
8951}
9052
0 commit comments