diff --git a/lib/index.d.ts b/lib/index.d.ts index 2903897..7baf262 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,5 +1,7 @@ import type { ShowdownExtension } from "showdown"; +export function addListener(className: string): void; + declare function showdownCopyCode({ className }?: { className?: string; }): ShowdownExtension[]; diff --git a/lib/index.js b/lib/index.js index 3bd66e7..4b6485e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,8 @@ -function addListener() { +/** + * Adds an event listener to the window that listens for clicks. + * @param {String} className The class name of the button. + */ +function addListener(className) { if (typeof window !== "undefined" && window.copyCodeListener !== true) { window.addEventListener("click", (e) => { if (e.target?.classList?.contains(className) && e.target.nextElementSibling?.tagName === "PRE") { @@ -24,7 +28,7 @@ module.exports = function showdownCopyCode({ className = "copy-code" } = {}) { { type: "output", filter: function (text) { - addListener(); + addListener(className); return text.replace( /