Skip to content

Commit

Permalink
feat: convert urls in response text to links and add styling
Browse files Browse the repository at this point in the history
  • Loading branch information
lpm0073 committed Jan 23, 2024
1 parent 9033b6d commit 031eac7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions client/src/components/chatApp/Component.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@
.cs-conversation-header {
text-align: center;
}

a {
text-decoration: underline;
color: black;
}
a:hover {
text-decoration: underline;
color: midnightblue;
}
13 changes: 12 additions & 1 deletion client/src/components/chatApp/Component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,20 @@ function ChatApp(props) {
return conversation_header;
}

function convertMarkdownLinksToHTML(message) {
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
return message.replace(markdownLinkRegex, '<a href="$2">$1</a>');
}
function convertURLsToHTML(message) {
const urlRegex = /(https?:\/\/[^\s]+)/g;
return message.replace(urlRegex, '<a href="$1">$1</a>');
}

function messageFactory(message, direction, sender) {
const converted_message = convertMarkdownLinksToHTML(message);
const converted_message2 = convertURLsToHTML(converted_message);
return {
message: message,
message: converted_message2,
direction: direction,
sentTime: new Date().toLocaleString(),
sender: sender,
Expand Down

0 comments on commit 031eac7

Please sign in to comment.