Skip to content

Commit f583f67

Browse files
committed
Render headings in preview
1 parent f97aa29 commit f583f67

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

services/backend-api/client/src/components/DiscordView/utils/markdown.jsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,36 @@ function translateSurrogatesToInlineEmoji(surrogates) {
167167

168168
const baseRules = {
169169
newline: SimpleMarkdown.defaultRules.newline,
170+
heading: {
171+
order: SimpleMarkdown.defaultRules.heading.order,
172+
match: SimpleMarkdown.blockRegex(/^(#{1,3})\s+([^\n]+?)(?:\n|$)/),
173+
parse(capture, parse, state) {
174+
return {
175+
level: capture[1].length,
176+
content: parse(capture[2].trim(), state),
177+
};
178+
},
179+
react(node, recurseOutput, state) {
180+
const sizes = {
181+
1: "1.5rem",
182+
2: "1.25rem",
183+
3: "1rem",
184+
};
185+
const style = {
186+
fontWeight: "bold",
187+
fontSize: sizes[node.level] || "1rem",
188+
lineHeight: "1.375",
189+
marginTop: "1rem",
190+
marginBottom: "0.5rem",
191+
};
192+
193+
return (
194+
<div key={state.key} style={style}>
195+
{recurseOutput(node.content, state)}
196+
</div>
197+
);
198+
},
199+
},
170200
paragraph: SimpleMarkdown.defaultRules.paragraph,
171201
escape: SimpleMarkdown.defaultRules.escape,
172202
link: SimpleMarkdown.defaultRules.link,

services/backend-api/client/src/pages/MessageBuilder/DiscordMessagePreview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export const DiscordMessagePreview: React.FC<DiscordMessagePreviewProps> = ({ ma
315315
<VStack align="start" spacing={1} flex={1}>
316316
{comp.components?.map((td, i) => (
317317
<Box key={td.content || `text-${index}-${i}`} fontSize="sm" className="markup">
318-
{td.content ? parseAllowLinks(td.content, true, {}, jumboify) : "[missing text]"}
318+
{td.content ? parseAllowLinks(td.content, false, {}, jumboify) : "[missing text]"}
319319
</Box>
320320
))}
321321
</VStack>
@@ -350,7 +350,7 @@ export const DiscordMessagePreview: React.FC<DiscordMessagePreviewProps> = ({ ma
350350

351351
return (
352352
<Box key={`textdisplay-${index}`} fontSize="sm" className="markup">
353-
{content ? parseAllowLinks(content, true, {}, jumboify) : "[missing text]"}
353+
{content ? parseAllowLinks(content, false, {}, jumboify) : "[missing text]"}
354354
</Box>
355355
);
356356
}

0 commit comments

Comments
 (0)