Skip to content

Commit 1be9627

Browse files
committed
refac
1 parent f0e0cfc commit 1be9627

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,7 +3011,7 @@
30113011
if (e.detail || files.length > 0) {
30123012
await tick();
30133013

3014-
submitHandler(e.detail.replaceAll('\n\n', '\n'));
3014+
submitHandler(e.detail);
30153015
}
30163016
}}
30173017
/>
@@ -3054,7 +3054,7 @@
30543054
clearDraft();
30553055
if (e.detail || files.length > 0) {
30563056
await tick();
3057-
submitHandler(e.detail.replaceAll('\n\n', '\n'));
3057+
submitHandler(e.detail);
30583058
}
30593059
}}
30603060
/>

src/lib/components/common/RichTextInput.svelte

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
});
3737
turndownService.escape = (string) => string;
3838
39+
// Produce single newlines between paragraphs instead of double.
40+
// TipTap wraps every line in <p> tags; the default Turndown rule emits
41+
// \n\n around each paragraph which then required a destructive
42+
// replaceAll('\n\n','\n') that also wiped blank lines inside code blocks.
43+
// This rule eliminates that hack so <pre><code> content is untouched.
44+
turndownService.addRule('singleNewlineParagraphs', {
45+
filter: 'p',
46+
replacement: function (content) {
47+
return '\n' + content + '\n';
48+
}
49+
});
50+
3951
// Use turndown-plugin-gfm for proper GFM table support
4052
turndownService.use(gfm);
4153
@@ -435,7 +447,6 @@
435447
436448
export const setText = (text: string) => {
437449
if (!editor || !editor.view) return;
438-
text = text.replaceAll('\n\n', '\n');
439450
440451
if (text === '') {
441452
editor.commands.clearContent();

0 commit comments

Comments
 (0)