From 789a4dedf0e2d59264fcae694f92b7f0c25f3a6c Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Thu, 20 Feb 2025 10:27:05 +1000 Subject: [PATCH] feat(#202): Add clipboard library --- src/parser/copycode.ts | 2 +- src/routes/viewer.ts | 2 ++ static/copycode/client.js | 5 +++++ static/copycode/clipboard.min.js | 7 +++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 static/copycode/client.js create mode 100644 static/copycode/clipboard.min.js diff --git a/src/parser/copycode.ts b/src/parser/copycode.ts index 2fedd6c..92a939b 100644 --- a/src/parser/copycode.ts +++ b/src/parser/copycode.ts @@ -11,7 +11,7 @@ export default function copycode(md: MarkdownIt) {
${renderedPreBlock}
- +
`; diff --git a/src/routes/viewer.ts b/src/routes/viewer.ts index b53e80a..ec569c4 100644 --- a/src/routes/viewer.ts +++ b/src/routes/viewer.ts @@ -88,6 +88,8 @@ router.get(/.*/, async (req: Request, res: Response) => { ${config.scripts ? `` : ''} + + `); }); diff --git a/static/copycode/client.js b/static/copycode/client.js new file mode 100644 index 0000000..ed5e111 --- /dev/null +++ b/static/copycode/client.js @@ -0,0 +1,5 @@ +var clipboard = new ClipboardJS('.copy-button'); + +//TODO: Implement success callback + +//TODO: Implement failure callback diff --git a/static/copycode/clipboard.min.js b/static/copycode/clipboard.min.js new file mode 100644 index 0000000..1103f81 --- /dev/null +++ b/static/copycode/clipboard.min.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v2.0.11 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={686:function(t,e,n){"use strict";n.d(e,{default:function(){return b}});var e=n(279),i=n.n(e),e=n(370),u=n.n(e),e=n(817),r=n.n(e);function c(t){try{return document.execCommand(t)}catch(t){return}}var a=function(t){t=r()(t);return c("cut"),t};function o(t,e){var n,o,t=(n=t,o="rtl"===document.documentElement.getAttribute("dir"),(t=document.createElement("textarea")).style.fontSize="12pt",t.style.border="0",t.style.padding="0",t.style.margin="0",t.style.position="absolute",t.style[o?"right":"left"]="-9999px",o=window.pageYOffset||document.documentElement.scrollTop,t.style.top="".concat(o,"px"),t.setAttribute("readonly",""),t.value=n,t);return e.container.appendChild(t),e=r()(t),c("copy"),t.remove(),e}var f=function(t){var e=1