Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 Remove replaceMagic function #525

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/>')
: ''
}