Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 9e5e6a5

Browse files
committed
refactor: modify serialize/deserialize API for easier testing
1 parent 2ba3476 commit 9e5e6a5

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/components/views/rooms/EditMessageComposer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ function createEditContent(
9595
body: `${plainPrefix} * ${body}`,
9696
};
9797

98-
const formattedBody = htmlSerializeIfNeeded(model, { forceHTML: isReply });
98+
const formattedBody = htmlSerializeIfNeeded(model, {
99+
forceHTML: isReply,
100+
useMarkdown: SettingsStore.getValue("MessageComposerInput.useMarkdown"),
101+
});
99102
if (formattedBody) {
100103
newContent.format = "org.matrix.custom.html";
101104
newContent.formatted_body = formattedBody;

src/components/views/rooms/SendMessageComposer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export function createMessageContent(
9191
msgtype: isEmote ? "m.emote" : "m.text",
9292
body: body,
9393
};
94-
const formattedBody = htmlSerializeIfNeeded(model, { forceHTML: !!replyToEvent });
94+
const formattedBody = htmlSerializeIfNeeded(model, {
95+
forceHTML: !!replyToEvent,
96+
useMarkdown: SettingsStore.getValue("MessageComposerInput.useMarkdown"),
97+
});
9598
if (formattedBody) {
9699
content.format = "org.matrix.custom.html";
97100
content.formatted_body = formattedBody;

src/editor/serialize.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,16 @@ export function mdSerialize(model: EditorModel): string {
4949
}, "");
5050
}
5151

52-
export function htmlSerializeIfNeeded(model: EditorModel, { forceHTML = false } = {}): string {
53-
if (!SettingsStore.getValue("MessageComposerInput.useMarkdown")) {
52+
interface ISerializeOpts {
53+
forceHTML?: boolean;
54+
useMarkdown?: boolean;
55+
}
56+
57+
export function htmlSerializeIfNeeded(
58+
model: EditorModel,
59+
{ forceHTML = false, useMarkdown = true }: ISerializeOpts = {},
60+
): string {
61+
if (!useMarkdown) {
5462
return escapeHtml(textSerialize(model)).replace(/\n/g, '<br/>');
5563
}
5664

0 commit comments

Comments
 (0)