Skip to content

Commit 054e5f4

Browse files
committed
Add lineBreakReplacer extention
1 parent ae1dc40 commit 054e5f4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/lib/holocene/code-block.svelte

+11
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@
9191
9292
$: value = formatValue({ value: content, language });
9393
94+
const lineBreakReplacer = EditorView.updateListener.of((update) => {
95+
if (editable) return;
96+
const newText = update.state.doc.toString().replace(/\\n/g, '\n');
97+
if (newText !== update.state.doc.toString()) {
98+
update.view.dispatch({
99+
changes: { from: 0, to: update.state.doc.length, insert: newText },
100+
});
101+
}
102+
});
103+
94104
const createEditorView = (isDark: boolean): EditorView => {
95105
return new EditorView({
96106
parent: editor,
@@ -120,6 +130,7 @@
120130
EditorState.readOnly.of(!editable),
121131
EditorView.editable.of(editable),
122132
EditorView.contentAttributes.of({ 'aria-label': label }),
133+
lineBreakReplacer,
123134
];
124135
125136
if (language === 'json') {

0 commit comments

Comments
 (0)