Skip to content

Commit

Permalink
Fix addListener, change .d.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpdev committed Feb 12, 2022
1 parent 0a34ff4 commit 17697e7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { ShowdownExtension } from "showdown";

export function addListener(className: string): void;

declare function showdownCopyCode({ className }?: {
className?: string;
}): ShowdownExtension[];
Expand Down
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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") {
Expand All @@ -24,7 +28,7 @@ module.exports = function showdownCopyCode({ className = "copy-code" } = {}) {
{
type: "output",
filter: function (text) {
addListener();
addListener(className);

return text.replace(
/<pre.*><code/g,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"copy"
],
"license": "MIT",
"version": "1.0.0",
"version": "1.0.1",
"main": "lib/index.js",
"author": "Piotr Placzek (piotrpdev)",
"scripts": {
Expand Down

0 comments on commit 17697e7

Please sign in to comment.