2023年1月13日 星期五

JavaScript text to hyperlink 和 自動換行

nl2br() 函數在字符串中的每個新行(\n) 之前插入HTML 換行符(<br />)。 


function nl2br (str, is_xhtml) {

    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br ' + '/>' : '<br>';

    var regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/=\/_\.]*(\?\S+)?)?)?)/ig

    var str = str.replace(regex, "<a href='$1' target='_blank'>$1</a>");

    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');

}

【2026 最新】VS Code 導入 pstack AI Skills 完整教學:用 Copilot 打造嚴謹的 Agent 工作流

在 VS Code 使用 AI Skills 打造嚴謹工程工作流:從 pstack 到原生 AGENTS.md 實戰指南 「If you want to go fast, go deep first.」 — Lauren Tan(@poteto) 進入 2026 年, AI Co...