Skip to content

Commit 7a45805

Browse files
author
ComputelessComputer
committed
simplify storage: remove ZWSP workarounds now that json2md output is clean
1 parent 985a85e commit 7a45805

1 file changed

Lines changed: 2 additions & 40 deletions

File tree

src/services/storage.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/ /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(/([-*] (?!\[[ xX]\] ).+)\n\n([-*] \[[ xX]\] )/g, `$1\n\n${ZWSP}\n\n$2`,)
52-
// Single blank line: task item → regular bullet
53-
.replace(/([-*] \[[ xX]\] .+)\n\n([-*] (?!\[[ xX]\] ))/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-
6430
export 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 &nbsp; 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

Comments
 (0)