contrib/html: support click on code block to copy to clipboard

This commit is contained in:
Christian Hesse 2025-11-17 09:31:36 +01:00
parent c80dd7d891
commit 1c11d77bce
3 changed files with 7 additions and 0 deletions

View file

@ -10,12 +10,14 @@ sed \
-e "s|__LOGO__|$(realpath --relative-to="${RELTO}" logo.png)|" \ -e "s|__LOGO__|$(realpath --relative-to="${RELTO}" logo.png)|" \
-e "s|__EWORM__|$(realpath --relative-to="${RELTO}" general/eworm-meadow.avif)|" \ -e "s|__EWORM__|$(realpath --relative-to="${RELTO}" general/eworm-meadow.avif)|" \
-e "s|__QR_CODE__|$(realpath --relative-to="${RELTO}" general/qr-code.png)|" \ -e "s|__QR_CODE__|$(realpath --relative-to="${RELTO}" general/qr-code.png)|" \
-e "s|__CLIPBOARD__|$(realpath --relative-to="${RELTO}" general/clipboard.js)|" \
< "${0}.d/head.html" < "${0}.d/head.html"
markdown -f toc,idanchor "${1}" | sed \ markdown -f toc,idanchor "${1}" | sed \
-e 's/href="\([-_\./[:alnum:]]*\)\.md\(#[-[:alnum:]]*\)\?"/href="\1.html\2"/g' \ -e 's/href="\([-_\./[:alnum:]]*\)\.md\(#[-[:alnum:]]*\)\?"/href="\1.html\2"/g' \
-e '/<h[1234] /s| id="\(.*\)">| id="\L\1">|' \ -e '/<h[1234] /s| id="\(.*\)">| id="\L\1">|' \
-e '/<h[1234] /s|-2c-||g' -e '/<h[1234] /s|--26-amp-3b-||g' \ -e '/<h[1234] /s|-2c-||g' -e '/<h[1234] /s|--26-amp-3b-||g' \
-e '/^<pre>/s|pre|pre onclick="CopyToClipboard(this)"|g' \
-e '/The above link may be broken on code hosting sites/s|blockquote|blockquote style="display: none;"|' -e '/The above link may be broken on code hosting sites/s|blockquote|blockquote style="display: none;"|'
sed \ sed \

View file

@ -3,6 +3,7 @@
<title>RouterOS Scripts :: __TITLE__</title> <title>RouterOS Scripts :: __TITLE__</title>
<link rel="stylesheet" type="text/css" href="__STYLE__"> <link rel="stylesheet" type="text/css" href="__STYLE__">
<link rel="icon" type="image/png" href="__LOGO__"> <link rel="icon" type="image/png" href="__LOGO__">
<script type="text/javascript" src="__CLIPBOARD__"></script>
</head><body> </head><body>
<table><tr> <table><tr>

4
general/clipboard.js Normal file
View file

@ -0,0 +1,4 @@
/* copy code to clipboard */
function CopyToClipboard(pre) {
navigator.clipboard.writeText(pre.firstElementChild.innerHTML);
}