目標
讓心得內容更可讀:自動偵測網址轉連結、支援 @名字 高亮、長文斷行。
改哪裡:js/reviews.js(render 內容處理)、style.css
style.css)/* Day 17:內容可讀性 */
.review-content a{ color: var(--primary); text-decoration: underline; word-break: break-all; }
.review-content .mention{ background: #f5f3ff; border-radius: 6px; padding: 0 4px; }
esc(item.content) 的處理)function linkify(str){
// 先跳脫、再把 URL 與 @xxx 轉成標籤
const s = esc(str);
const withUrl = s.replace(/(https?:\/\/[^\s]+)/g, '<a href="$1" target="_blank" rel="noopener">$1</a>');
const withMention = withUrl.replace(/@([\p{L}\d_]{2,20})/gu, '<span class="mention">@$1</span>');
return withMention;
}
// render 內容處改成:
<p class="review-content">${linkify(item.content)}</p>