File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33feat: 仅新增复制按钮
44
55feat: 新增自动高亮
6+
7+ fix: 网址形式的内容在高亮块显示不为 herf 问题
Original file line number Diff line number Diff line change @@ -134,7 +134,31 @@ function highlightCodeBlocks() {
134134 continue ;
135135 } else {
136136 if ( languageFlag ) {
137- codeContentArr . push ( memo_p_array [ i ] . innerHTML ) ;
137+ // 处理内容中的a标签
138+ let content = memo_p_array [ i ] . innerHTML ;
139+
140+ // 创建临时DOM元素来解析HTML
141+ const tempDiv = document . createElement ( 'div' ) ;
142+ tempDiv . innerHTML = content ;
143+
144+ // 查找所有a标签
145+ const links = tempDiv . querySelectorAll ( 'a' ) ;
146+ links . forEach ( ( link ) => {
147+ // 获取href属性
148+ const href = link . getAttribute ( 'href' ) ;
149+ if ( href ) {
150+ // 替换整个a标签为@+href
151+ const linkText = `${ href } ` ;
152+ // 创建文本节点
153+ const textNode = document . createTextNode ( linkText ) ;
154+ // 替换a标签为文本节点
155+ link . parentNode . replaceChild ( textNode , link ) ;
156+ }
157+ } ) ;
158+
159+ // 获取处理后的内容
160+ content = tempDiv . innerHTML ;
161+ codeContentArr . push ( content ) ;
138162 memo . removeChild ( memo_p_array [ i ] ) ;
139163 }
140164 }
You can’t perform that action at this time.
0 commit comments