Skip to content

Commit

Permalink
optimize exported Markdown style, treat user input as H2
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoukuncheng committed Mar 29, 2024
1 parent 1e6359b commit 7168b6d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/app/components/Share/MarkdownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ const MarkdownView: FC<Props> = ({ messages }) => {
const content = useMemo(() => {
return messages
.filter((m) => !!m.text)
.map((m) => `**${m.author}**: ` + m.text)
.join('\n\n')
}, [messages])

.map((m) => {
// Check if author is "user"
if (m.author === "user") {
// Format as an h2 markdown element
return `## ${m.author}: ${m.text}`;
} else {
return `**${m.author}**: ${m.text}`;
}
})
.join('\n\n');
}, [messages]);

const copy = useCallback(() => {
navigator.clipboard.writeText(content)
setCopied(true)
Expand Down

0 comments on commit 7168b6d

Please sign in to comment.