Skip to content

Commit

Permalink
🔥 Remove replaceMagic function
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Oct 20, 2023
1 parent f6c30bb commit 7c122dc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
3 changes: 1 addition & 2 deletions src/components/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Message as MessageType } from '../lib/types'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import localizedFormat from 'dayjs/plugin/localizedFormat'
import { replaceMagic } from '../lib/helper'
import Attachments from './Attachments'
import styled from 'styled-components'
import Map from './Map'
Expand Down Expand Up @@ -34,7 +33,7 @@ const Message: FC<Props> = props => {
<CardContent>
<div
dangerouslySetInnerHTML={{
__html: replaceMagic(props.message.text),
__html: props.message.text.replace(/(?:\r\n|\r|\n)/g, '<br/>'),
}}
/>
</CardContent>
Expand Down
13 changes: 0 additions & 13 deletions src/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,3 @@ export const isMobile = (): boolean => {
const width = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth
return width < breakpoints.mobile
}

// FIXME: Might be better to use a library like validator.js
// to catch more cases.
export const replaceMagic = (text: string): string => {
return text
? text
.replace(/(https?:\/\/([a-zA-Z0-9._\-/]+))/g, '<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>')
.replace(/#(\S+)/g, '<a target="_blank" rel="noopener noreferrer" href="https://twitter.com/search?q=%23$1">#$1</a>')
.replace(/ @(\S+)/g, ' <a target="_blank" rel="noopener noreferrer" href="https://twitter.com/$1">@$1</a>')
.replace(/([a-zA-Z0-9_\-.]+@[a-zA-Z0-9_-]+.[a-zA-Z]+)/g, '<a href="mailto:$1">$1</a>')
.replace(/(?:\r\n|\r|\n)/g, '<br/>')
: ''
}

0 comments on commit 7c122dc

Please sign in to comment.