Don't render markdown for summaries. Fixes #658 (#659)

This commit is contained in:
Dessalines 2022-05-23 07:13:41 -04:00 committed by GitHub
parent b77689ebd1
commit 321339c6c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 30 deletions

View file

@ -374,3 +374,11 @@ br.big {
.slight-radius { .slight-radius {
border-radius: 4px; border-radius: 4px;
} }
.preview-lines {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}

View file

@ -34,7 +34,6 @@ import {
isMod, isMod,
mdToHtml, mdToHtml,
numToSI, numToSI,
previewLines,
relTags, relTags,
restoreScrollPosition, restoreScrollPosition,
routeSortTypeToEnum, routeSortTypeToEnum,
@ -221,7 +220,7 @@ export class Profile extends Component<any, ProfileState> {
get bioTag(): string { get bioTag(): string {
return this.state.personRes.person_view.person.bio return this.state.personRes.person_view.person.bio
? previewLines(this.state.personRes.person_view.person.bio) ? this.state.personRes.person_view.person.bio
: undefined; : undefined;
} }

View file

@ -35,7 +35,6 @@ import {
md, md,
mdToHtml, mdToHtml,
numToSI, numToSI,
previewLines,
relTags, relTags,
setupTippy, setupTippy,
showScores, showScores,
@ -355,9 +354,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
<li className="list-inline-item"> <li className="list-inline-item">
<button <button
className="text-muted btn btn-sm btn-link p-0" className="text-muted btn btn-sm btn-link p-0"
data-tippy-content={md.render( data-tippy-content={md.render(post_view.post.body)}
previewLines(post_view.post.body)
)}
data-tippy-allowHtml={true} data-tippy-allowHtml={true}
onClick={linkEvent(this, this.handleShowBody)} onClick={linkEvent(this, this.handleShowBody)}
> >
@ -1093,12 +1090,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
return ( return (
post.body && post.body &&
!this.showBody && ( !this.showBody && (
<div <div className="md-div mb-1 preview-lines">{post.body}</div>
className="md-div mb-1"
dangerouslySetInnerHTML={{
__html: md.render(previewLines(post.body)),
}}
/>
) )
); );
} }

View file

@ -46,7 +46,6 @@ import {
insertCommentIntoTree, insertCommentIntoTree,
isBrowser, isBrowser,
isImage, isImage,
previewLines,
restoreScrollPosition, restoreScrollPosition,
saveCommentRes, saveCommentRes,
saveScrollPosition, saveScrollPosition,
@ -287,8 +286,7 @@ export class Post extends Component<any, PostState> {
} }
get descriptionTag(): string { get descriptionTag(): string {
let body = this.state.postRes.post_view.post.body; return this.state.postRes.post_view.post.body;
return body ? previewLines(body) : undefined;
} }
render() { render() {

View file

@ -1034,21 +1034,6 @@ function hsl(num: number) {
return `hsla(${num}, 35%, 50%, 1)`; return `hsla(${num}, 35%, 50%, 1)`;
} }
export function previewLines(
text: string,
maxChars = 300,
maxLines = 1
): string {
return (
text
.slice(0, maxChars)
.split("\n")
// Use lines * 2 because markdown requires 2 lines
.slice(0, maxLines * 2)
.join("\n") + "..."
);
}
export function hostname(url: string): string { export function hostname(url: string): string {
let cUrl = new URL(url); let cUrl = new URL(url);
return cUrl.port ? `${cUrl.hostname}:${cUrl.port}` : `${cUrl.hostname}`; return cUrl.port ? `${cUrl.hostname}:${cUrl.port}` : `${cUrl.hostname}`;