Skip to content

Commit

Permalink
Fixes removeMd crashing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
velopert committed Apr 15, 2019
1 parent f494898 commit e740e79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions velog-backend/src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export const extractKeys = (object: any, params: Array<string>): any => {

export function formatShortDescription(markdown: string): string {
const replaced = markdown
.replace(/ +/g, '')
.replace(/--/g, '')
.replace(/\|/g, '')
.replace(/\n/g, ' ')
.replace(/```(.*)```/g, '')
.replace(/[<>]/g, '');
Expand Down
18 changes: 13 additions & 5 deletions velog-frontend/src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,19 @@ export const fromNow = (date: string) => {
};

export function convertToPlainText(markdown: string): string {
if (!markdown) return '';
const replaced = markdown.replace(/\n/g, ' ').replace(/```(.*)```/g, '');
return removeMd(replaced)
.slice(0, 150)
.replace(/#/g, '');
const replaced = markdown
.replace(/ +/g, '')
.replace(/--/g, '')
.replace(/\|/g, '')
.replace(/\n/g, ' ')
.replace(/```(.*)```/g, '')
.replace(/[<>]/g, '');

return (
removeMd(replaced.slice(0, 500))
.slice(0, 200)
.replace(/#/g, '') + (replaced.length > 200 ? '...' : '')
);
}

export function resizeImage(url: string, width?: number = 256) {
Expand Down

0 comments on commit e740e79

Please sign in to comment.