tangled
alpha
login
or
join now
ajamesphillips.com
/
leaflet
forked from
leaflet.pub/leaflet
a tool for shared writing and social publishing
0
fork
atom
overview
issues
pulls
pipelines
add hard breaks
awarm.space
2 months ago
06e5d699
695201ca
+29
-8
4 changed files
expand all
collapse all
unified
split
app
lish
[did]
[publication]
[rkey]
BaseTextBlock.tsx
components
Blocks
TextBlock
RenderYJSFragment.tsx
keymap.ts
schema.ts
+9
-3
app/lish/[did]/[publication]/[rkey]/BaseTextBlock.tsx
···
36
36
${isStrikethrough ? "line-through decoration-tertiary" : ""}
37
37
${isHighlighted ? "highlight bg-highlight-1" : ""}`.replaceAll("\n", " ");
38
38
39
39
+
// Split text by newlines and insert <br> tags
40
40
+
const textParts = segment.text.split('\n');
41
41
+
const renderedText = textParts.flatMap((part, i) =>
42
42
+
i < textParts.length - 1 ? [part, <br key={`br-${counter}-${i}`} />] : [part]
43
43
+
);
44
44
+
39
45
if (isCode) {
40
46
children.push(
41
47
<code key={counter} className={className} id={id?.id}>
42
42
-
{segment.text}
48
48
+
{renderedText}
43
49
</code>,
44
50
);
45
51
} else if (link) {
···
50
56
className={`text-accent-contrast hover:underline ${className}`}
51
57
target="_blank"
52
58
>
53
53
-
{segment.text}
59
59
+
{renderedText}
54
60
</a>,
55
61
);
56
62
} else {
57
63
children.push(
58
64
<span key={counter} className={className} id={id?.id}>
59
59
-
{segment.text}
65
65
+
{renderedText}
60
66
</span>,
61
67
);
62
68
}
+8
components/Blocks/TextBlock/RenderYJSFragment.tsx
···
60
60
);
61
61
}
62
62
63
63
+
if (node.constructor === XmlElement && node.nodeName === "hard_break") {
64
64
+
return <br key={index} />;
65
65
+
}
66
66
+
63
67
return null;
64
68
})
65
69
)}
···
144
148
node: XmlElement | XmlText | XmlHook,
145
149
): string {
146
150
if (node.constructor === XmlElement) {
151
151
+
// Handle hard_break nodes specially
152
152
+
if (node.nodeName === "hard_break") {
153
153
+
return "\n";
154
154
+
}
147
155
return node
148
156
.toArray()
149
157
.map((f) => YJSFragmentToString(f))
+5
-5
components/Blocks/TextBlock/keymap.ts
···
145
145
);
146
146
},
147
147
"Shift-Enter": (state, dispatch, view) => {
148
148
-
if (multiLine) {
149
149
-
return baseKeymap.Enter(state, dispatch, view);
148
148
+
// Insert a hard break
149
149
+
let hardBreak = schema.nodes.hard_break.create();
150
150
+
if (dispatch) {
151
151
+
dispatch(state.tr.replaceSelectionWith(hardBreak).scrollIntoView());
150
152
}
151
151
-
return um.withUndoGroup(() =>
152
152
-
enter(propsRef, repRef)(state, dispatch, view),
153
153
-
);
153
153
+
return true;
154
154
},
155
155
"Ctrl-Enter": CtrlEnter(propsRef, repRef),
156
156
"Meta-Enter": CtrlEnter(propsRef, repRef),
+7
components/Blocks/TextBlock/schema.ts
···
115
115
text: {
116
116
group: "inline",
117
117
},
118
118
+
hard_break: {
119
119
+
group: "inline",
120
120
+
inline: true,
121
121
+
selectable: false,
122
122
+
parseDOM: [{ tag: "br" }],
123
123
+
toDOM: () => ["br"] as const,
124
124
+
},
118
125
},
119
126
};
120
127
export const schema = new Schema(baseSchema);