Commit e9ee1a1f authored by 金伟强's avatar 金伟强

feat: handle link highlight

parent 54cf870d
...@@ -8,6 +8,8 @@ import s from './style.module.css' ...@@ -8,6 +8,8 @@ import s from './style.module.css'
import { DataSet, Search, ThoughtList, WebReader } from '@/app/components/base/icons/src/public/thought' import { DataSet, Search, ThoughtList, WebReader } from '@/app/components/base/icons/src/public/thought'
import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows' import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows'
// https://www.freecodecamp.org/news/how-to-write-a-regular-expression-for-a-url/
const urlRegex = /(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?\/[a-zA-Z0-9]{2,}|((https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?)|(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})?/gi
export type IThoughtProps = { export type IThoughtProps = {
list: ThoughtItem[] list: ThoughtItem[]
} }
...@@ -32,7 +34,11 @@ const Thought: FC<IThoughtProps> = ({ ...@@ -32,7 +34,11 @@ const Thought: FC<IThoughtProps> = ({
const renderItem = (item: ThoughtItem) => ( const renderItem = (item: ThoughtItem) => (
<div className='flex space-x-1 py-[3px] leading-[18px]' key={item.id}> <div className='flex space-x-1 py-[3px] leading-[18px]' key={item.id}>
<div className='flex items-center h-[18px] shrink-0'>{getIcon(item.tool)}</div> <div className='flex items-center h-[18px] shrink-0'>{getIcon(item.tool)}</div>
<div>{item.thought}</div> <div dangerouslySetInnerHTML={{
__html: item.thought.replace(urlRegex, (url) => {
return `<a href="${url}" class="text-[#155EEF]">${url}</a>`
}),
}}></div>
</div> </div>
) )
return ( return (
......
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
.markdown-body a { .markdown-body a {
background-color: transparent; background-color: transparent;
color: var(--color-accent-fg); color: #155EEF;
text-decoration: none; text-decoration: none;
} }
...@@ -1042,4 +1042,4 @@ ...@@ -1042,4 +1042,4 @@
.markdown-body ::-webkit-calendar-picker-indicator { .markdown-body ::-webkit-calendar-picker-indicator {
filter: invert(50%); filter: invert(50%);
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment