From c36b4ace13ec589631b1072993d64ad3095ad32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Tue, 16 Jun 2026 09:43:31 +0200 Subject: [PATCH] Nicer code copy, bumped to v28 --- main.go | 2 +- static/js/marked_position.mjs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index e9bd88d..5d8bf68 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ import ( "text/template" ) -const VERSION = "v27" +const VERSION = "v28" const CONTEXT_USER = 1 const SYNC_PAGINATION = 200 diff --git a/static/js/marked_position.mjs b/static/js/marked_position.mjs index 63f76f7..8c81eb4 100644 --- a/static/js/marked_position.mjs +++ b/static/js/marked_position.mjs @@ -94,7 +94,7 @@ export class MarkedPosition { constructor() {// {{{ window.marked_setpos = (event) => this.setpos(event) window.marked_changecheckbox = (event) => this.changecheckbox(event) - window.marked_copy_to_clipboard = (event) => this.copy_to_clipboard(event) + window.marked_copy_to_clipboard = (event, tagname) => this.copy_to_clipboard(event, tagname) this.render() }// }}} setpos(event) {// {{{ @@ -120,7 +120,7 @@ export class MarkedPosition { } }) }// }}} - async copy_to_clipboard(event) {// {{{ + async copy_to_clipboard(event, tagname) {// {{{ if (!event.shiftKey) return @@ -134,8 +134,11 @@ export class MarkedPosition { const text = event.target.innerText await navigator.clipboard.writeText(text) - event.target.classList.add('copy') - setTimeout(()=>event.target.classList.remove('copy'), 250) + + const tagClasslist = event.target.closest(tagname).classList + tagClasslist.add('copy') + setTimeout(()=>tagClasslist.remove('copy'), 250) + } catch (err) { console.error('Failed to copy: ', err) alert('Failed to copy: ', err) @@ -143,7 +146,6 @@ export class MarkedPosition { }// }}} render() {// {{{ - const markedObject = this this.marked = new Marked() this.marked.use(markedTokenPosition()) this.marked.use({ @@ -188,12 +190,12 @@ export class MarkedPosition { const code = token.text.replace(other.endingNewline, '') + '\n' if (!langString) { - return `
`
+						return `
`
 							+ (token.escaped ? code : escapeHtmlEntities(code, true))
 							+ '
\n' } - return `
'
 						+ (token.escaped ? code : escapeHtmlEntities(code, true))
@@ -283,7 +285,7 @@ export class MarkedPosition {
 				},
 
 				codespan(token) {
-					return `${escapeHtmlEntities(token.text, true)}`
+					return `${escapeHtmlEntities(token.text, true)}`
 				},
 
 				br(token) {