]> Untitled Git - lemmy-ui.git/commitdiff
Add inline markdown rendering for post titles. Fixes #827 (#860)
authorDessalines <dessalines@users.noreply.github.com>
Fri, 18 Nov 2022 02:01:52 +0000 (21:01 -0500)
committerGitHub <noreply@github.com>
Fri, 18 Nov 2022 02:01:52 +0000 (21:01 -0500)
src/shared/components/post/post-listing.tsx
src/shared/utils.ts

index c14ea2f41edb3d97332aa0ef81f1c5465b5e90c4..7a8bdb61e8b8f98d3c1b57bbffb9a9a799b1418d 100644 (file)
@@ -42,6 +42,7 @@ import {
   isVideo,
   md,
   mdToHtml,
+  mdToHtmlInline,
   numToSI,
   relTags,
   setupTippy,
@@ -459,7 +460,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                 title={url}
                 rel={relTags}
               >
-                {post.name}
+                <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
               </a>
             ),
             none: (
@@ -468,7 +469,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                 to={`/post/${post.id}`}
                 title={i18n.t("comments")}
               >
-                {post.name}
+                <div dangerouslySetInnerHTML={mdToHtmlInline(post.name)} />
               </Link>
             ),
           })}
index 6494a7d9ea17c98b4049830a999149349d126d9d..23acfe51a55d8aadcb5036f7ae99c13ffd3a2fbc 100644 (file)
@@ -167,6 +167,10 @@ export function mdToHtml(text: string) {
   return { __html: md.render(text) };
 }
 
+export function mdToHtmlInline(text: string) {
+  return { __html: md.renderInline(text) };
+}
+
 export function getUnixTime(text: string): number {
   return text ? new Date(text).getTime() / 1000 : undefined;
 }