mirror of https://gitlab.com/curben/blog
fix(copy-button): add button to every codeblock
This commit is contained in:
parent
586adc63cd
commit
a429e0fd81
|
@ -6,11 +6,11 @@
|
|||
*/
|
||||
|
||||
hexo.extend.filter.register('after_render:html', (data) => {
|
||||
// Avoid duplicate button
|
||||
if (data.includes('</button></td>')) return;
|
||||
|
||||
const copyBtn = '<button class="copy-button">Copy</button>'
|
||||
|
||||
// Regex is based on https://github.com/hexojs/hexo/pull/3697
|
||||
return data.replace(/<td class="code">(?!<\/td>).+?<\/td>/, (str) => str.replace('</td>', copyBtn + '</td>'))
|
||||
return data.replace(/<td class="code">(?!<\/td>).+?<\/td>/ig, (str) => {
|
||||
if (!str.includes(copyBtn)) return str.replace('</td>', copyBtn + '</td>')
|
||||
return str
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue