Skip to content

Commit

Permalink
Adding decode logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Arunkumarlnr authored Mar 3, 2025
1 parent e35d78f commit e3b8ef3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion web/src/app/util/Markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ import makeStyles from '@mui/styles/makeStyles'
import AppLink from './AppLink'
import timestampSupport from './Markdown.timestampSupport'

function decodeUnicode(url) {
return url.replace(/\\u([0-9A-Fa-f]{4})/g, (_, p1) => {
return String.fromCharCode(parseInt(p1, 16))
});
}

function decodeHtmlEntities(url) {
const span = document.createElement('span');
span.innerHTML = url
return span.innerText
}

function decodeUrl(url) {
const decodedUrl = decodeURIComponent(url)
const unicodeDecodedUrl = decodeUnicode(decodedUrl)
return decodeHtmlEntities(unicodeDecodedUrl)
}

const useStyles = makeStyles({
markdown: {
overflowWrap: 'break-word',
Expand Down Expand Up @@ -69,7 +87,9 @@ export default function Markdown(props) {
components={{
td: TableCell,
a: ({ node, inline, className, children, ...props }) => (
<AppLink to={props.href} newTab {...props}>
const decodedURL= decodeUrl(props.href)
props.href=decodedURL
<AppLink to={decodedURL} newTab {...props}>
{children}
</AppLink>
),
Expand Down

0 comments on commit e3b8ef3

Please sign in to comment.