Skip to content

Commit

Permalink
Show whitespace and links in violation details
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev committed Oct 25, 2024
1 parent d4e0c86 commit cfb7832
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/modules/violations/ViolationDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { TableStyle } from '../Profile'
import styled from 'styled-components'
import CommentSection from './CommentSection'

import { formatDateShort, formatTime } from '../../utils/Util'
import {
formatDateShort,
formatTime,
formatTextWithLinks,
} from '../../utils/Util'
import PublishModal from './PublishModal'

const UpdatesTable = styled(TableStyle)`
Expand Down Expand Up @@ -378,7 +382,12 @@ export default (props) => {
</FancyButtonRed>
<hr />
<h2>Описание</h2>
<p>{data.description}</p>
<p
style={{ whiteSpace: 'pre-wrap' }}
dangerouslySetInnerHTML={{
__html: formatTextWithLinks(data.description),
}}
/>
<hr />
{!data.publishedText ? null : (
<>
Expand Down
10 changes: 10 additions & 0 deletions src/components/utils/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ const checkPaths = (path1, path2) => {
return path1 === path2
}

const formatTextWithLinks = (text) => {
const urlRegex = /(https?:\/\/[^\s]+)/g
return text.replace(
urlRegex,
(url) =>
`<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`
)
}

module.exports = {
formatLv,
formatPop,
Expand All @@ -146,4 +155,5 @@ module.exports = {
format,
checkPaths,
mapRoleLocalization,
formatTextWithLinks,
}

0 comments on commit cfb7832

Please sign in to comment.