From 1244c3929f771d8c03daa4171771ba7eb2334d1e Mon Sep 17 00:00:00 2001 From: Alex Henry Date: Tue, 18 Aug 2026 00:00:00 -0300 Subject: [PATCH] Convert from Common to pure JS and support Deno. --- CHANGELOG.md | 6 + README.md | 11 +- deno.lock | 487 ++++++++++++++++++ index.js | 4 +- ...ve-markdown.js => remove-markdown.test.js} | 87 ++-- 5 files changed, 542 insertions(+), 53 deletions(-) create mode 100644 deno.lock rename test/{remove-markdown.js => remove-markdown.test.js} (82%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ea259..b98c7db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [0.7.0] - 2026-08-18 + +### Converted +- Converted from Common to pure JS module +- Deno compatibility + ## [0.6.3] - 2026-01-14 ### Added diff --git a/README.md b/README.md index 0eb2064..ba51672 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,16 @@ [![GitHub Actions Build Status](https://github.com/zuchka/remove-markdown/actions/workflows/default.yaml/badge.svg)](https://github.com/zuchka/remove-markdown/actions/workflows/default.yaml) ## What is it? -**remove-markdown** is a node.js module that will remove (strip) Markdown formatting from text. +**remove-markdown** is a JS module that will remove (strip) Markdown formatting from text. *Markdown formatting* means pretty much anything that doesn’t look like regular text, like square brackets, asterisks etc. ## When do I need it? The typical use case is to display an excerpt from some Markdown text, without any of the actual Markdown syntax - for example in a list of posts. -## Installation - -``` -npm install remove-markdown -``` - ## Usage ```js -const removeMd = require('remove-markdown'); +import removeMd from '../index.js' + const markdown = '# This is a heading\n\nThis is a paragraph with [a link](http://www.disney.com/) in it.'; const plainText = removeMd(markdown); // plainText is now 'This is a heading\n\nThis is a paragraph with a link in it.' ``` diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..3b5978a --- /dev/null +++ b/deno.lock @@ -0,0 +1,487 @@ +{ + "version": "5", + "specifiers": { + "jsr:@std/assert@^1.0.13": "1.0.19", + "jsr:@std/assert@^1.0.14": "1.0.19", + "jsr:@std/expect@*": "1.0.17", + "jsr:@std/internal@^1.0.10": "1.0.14", + "jsr:@std/internal@^1.0.12": "1.0.14", + "jsr:@std/testing@*": "1.0.15", + "npm:chai@^4.0.2": "4.5.0", + "npm:mocha@^10.2.0": "10.8.2", + "npm:should@5": "5.2.0" + }, + "jsr": { + "@std/assert@1.0.19": { + "integrity": "eaada96ee120cb980bc47e040f82814d786fe8162ecc53c91d8df60b8755991e", + "dependencies": [ + "jsr:@std/internal@^1.0.12" + ] + }, + "@std/expect@1.0.17": { + "integrity": "316b47dd65c33e3151344eb3267bf42efba17d1415425f07ed96185d67fc04d9", + "dependencies": [ + "jsr:@std/assert@^1.0.14", + "jsr:@std/internal@^1.0.10" + ] + }, + "@std/internal@1.0.14": { + "integrity": "291516b3d4c35024d6ffbc0a9df5bf4c64116e05b50012cf846710152d2ffdf7" + }, + "@std/testing@1.0.15": { + "integrity": "a490169f5ccb0f3ae9c94fbc69d2cd43603f2cffb41713a85f99bbb0e3087cbc", + "dependencies": [ + "jsr:@std/assert@^1.0.13", + "jsr:@std/internal@^1.0.10" + ] + } + }, + "npm": { + "ansi-colors@4.1.3": { + "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==" + }, + "ansi-regex@5.0.1": { + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + }, + "ansi-styles@4.3.0": { + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": [ + "color-convert" + ] + }, + "anymatch@3.1.3": { + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dependencies": [ + "normalize-path", + "picomatch" + ] + }, + "argparse@2.0.1": { + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, + "assertion-error@1.1.0": { + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==" + }, + "balanced-match@1.0.2": { + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "binary-extensions@2.3.0": { + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==" + }, + "brace-expansion@2.1.0": { + "integrity": "sha512-TN1kCZAgdgweJhWWpgKYrQaMNHcDULHkWwQIspdtjV4Y5aurRdZpjAqn6yX3FPqTA9ngHCc4hJxMAMgGfve85w==", + "dependencies": [ + "balanced-match" + ] + }, + "braces@3.0.3": { + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dependencies": [ + "fill-range" + ] + }, + "browser-stdout@1.3.1": { + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==" + }, + "camelcase@6.3.0": { + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==" + }, + "chai@4.5.0": { + "integrity": "sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw==", + "dependencies": [ + "assertion-error", + "check-error", + "deep-eql", + "get-func-name", + "loupe", + "pathval", + "type-detect" + ] + }, + "chalk@4.1.2": { + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": [ + "ansi-styles", + "supports-color@7.2.0" + ] + }, + "check-error@1.0.3": { + "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", + "dependencies": [ + "get-func-name" + ] + }, + "chokidar@3.6.0": { + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dependencies": [ + "anymatch", + "braces", + "glob-parent", + "is-binary-path", + "is-glob", + "normalize-path", + "readdirp" + ], + "optionalDependencies": [ + "fsevents" + ] + }, + "cliui@7.0.4": { + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dependencies": [ + "string-width", + "strip-ansi", + "wrap-ansi" + ] + }, + "color-convert@2.0.1": { + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": [ + "color-name" + ] + }, + "color-name@1.1.4": { + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "debug@4.4.3": { + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dependencies": [ + "ms" + ] + }, + "decamelize@4.0.0": { + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==" + }, + "deep-eql@4.1.4": { + "integrity": "sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg==", + "dependencies": [ + "type-detect" + ] + }, + "diff@5.2.2": { + "integrity": "sha512-vtcDfH3TOjP8UekytvnHH1o1P4FcUdt4eQ1Y+Abap1tk/OB2MWQvcwS2ClCd1zuIhc3JKOx6p3kod8Vfys3E+A==" + }, + "emoji-regex@8.0.0": { + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "escalade@3.2.0": { + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==" + }, + "escape-string-regexp@4.0.0": { + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==" + }, + "fill-range@7.1.1": { + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dependencies": [ + "to-regex-range" + ] + }, + "find-up@5.0.0": { + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dependencies": [ + "locate-path", + "path-exists" + ] + }, + "flat@5.0.2": { + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "bin": true + }, + "fs.realpath@1.0.0": { + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, + "fsevents@2.3.3": { + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "os": ["darwin"], + "scripts": true + }, + "get-caller-file@2.0.5": { + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" + }, + "get-func-name@2.0.2": { + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==" + }, + "glob-parent@5.1.2": { + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": [ + "is-glob" + ] + }, + "glob@8.1.0": { + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dependencies": [ + "fs.realpath", + "inflight", + "inherits", + "minimatch", + "once" + ], + "deprecated": true + }, + "has-flag@4.0.0": { + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "he@1.2.0": { + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "bin": true + }, + "inflight@1.0.6": { + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dependencies": [ + "once", + "wrappy" + ], + "deprecated": true + }, + "inherits@2.0.4": { + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "is-binary-path@2.1.0": { + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dependencies": [ + "binary-extensions" + ] + }, + "is-extglob@2.1.1": { + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==" + }, + "is-fullwidth-code-point@3.0.0": { + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "is-glob@4.0.3": { + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dependencies": [ + "is-extglob" + ] + }, + "is-number@7.0.0": { + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" + }, + "is-plain-obj@2.1.0": { + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==" + }, + "is-unicode-supported@0.1.0": { + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==" + }, + "js-yaml@4.3.0": { + "integrity": "sha512-1td788aAnnZ5qs7V2QIRl1owjtYpbKt749Y3xauqQgwIIGF/xXWz1wMTEBx5O3LK3lXLVuqXPdPxj2BoFHaW9Q==", + "dependencies": [ + "argparse" + ], + "bin": true + }, + "locate-path@6.0.0": { + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dependencies": [ + "p-locate" + ] + }, + "log-symbols@4.1.0": { + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dependencies": [ + "chalk", + "is-unicode-supported" + ] + }, + "loupe@2.3.7": { + "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", + "dependencies": [ + "get-func-name" + ] + }, + "minimatch@5.1.9": { + "integrity": "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==", + "dependencies": [ + "brace-expansion" + ] + }, + "mocha@10.8.2": { + "integrity": "sha512-VZlYo/WE8t1tstuRmqgeyBgCbJc/lEdopaa+axcKzTBJ+UIdlAB9XnmvTCAH4pwR4ElNInaedhEBmZD8iCSVEg==", + "dependencies": [ + "ansi-colors", + "browser-stdout", + "chokidar", + "debug", + "diff", + "escape-string-regexp", + "find-up", + "glob", + "he", + "js-yaml", + "log-symbols", + "minimatch", + "ms", + "serialize-javascript", + "strip-json-comments", + "supports-color@8.1.1", + "workerpool", + "yargs", + "yargs-parser", + "yargs-unparser" + ], + "bin": true + }, + "ms@2.1.3": { + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "normalize-path@3.0.0": { + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" + }, + "once@1.4.0": { + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dependencies": [ + "wrappy" + ] + }, + "p-limit@3.1.0": { + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dependencies": [ + "yocto-queue" + ] + }, + "p-locate@5.0.0": { + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dependencies": [ + "p-limit" + ] + }, + "path-exists@4.0.0": { + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" + }, + "pathval@1.1.1": { + "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==" + }, + "picomatch@2.3.2": { + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==" + }, + "readdirp@3.6.0": { + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dependencies": [ + "picomatch" + ] + }, + "require-directory@2.1.1": { + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==" + }, + "serialize-javascript@7.0.5": { + "integrity": "sha512-F4LcB0UqUl1zErq+1nYEEzSHJnIwb3AF2XWB94b+afhrekOUijwooAYqFyRbjYkm2PAKBabx6oYv/xDxNi8IBw==" + }, + "should-equal@0.3.1": { + "integrity": "sha512-/Q/o9EL9CJlCsy817ZkcQVlyUzyeWUxS9HkXUrqv4tTg+aOXEwvOpR1odT0K9DwcMA0gCy452K71YJA1E6K1mQ==", + "dependencies": [ + "should-type" + ] + }, + "should-format@0.0.7": { + "integrity": "sha512-8oNurKotJEQy+HboLxAHkgKQ+dRfV9TmVAvcY3He1RdnE994M39JTmkCt67cWaygVLKUfBcLRITkpHy2Hsgwcg==", + "dependencies": [ + "should-type" + ] + }, + "should-type@0.0.4": { + "integrity": "sha512-ve9tkv/i29COtupPlu2g4SXGefgSTjDTBI8d5UgSmT52T9T5VBpZY9/Ygn5Pb3dcCaiMyEzBAxBkpUGxEbbMDw==" + }, + "should@5.2.0": { + "integrity": "sha512-pArsssKt6iXvJ1aB1SPmw6Ca1X18DdA4WlfppPcvGypSgXe3EsMeS3wR0H9x/85bbclzEzpqWhaDTIlc4AoEpw==", + "dependencies": [ + "should-equal", + "should-format", + "should-type" + ] + }, + "string-width@4.2.3": { + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": [ + "emoji-regex", + "is-fullwidth-code-point", + "strip-ansi" + ] + }, + "strip-ansi@6.0.1": { + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": [ + "ansi-regex" + ] + }, + "strip-json-comments@3.1.1": { + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" + }, + "supports-color@7.2.0": { + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": [ + "has-flag" + ] + }, + "supports-color@8.1.1": { + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dependencies": [ + "has-flag" + ] + }, + "to-regex-range@5.0.1": { + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dependencies": [ + "is-number" + ] + }, + "type-detect@4.1.0": { + "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==" + }, + "workerpool@6.5.1": { + "integrity": "sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==" + }, + "wrap-ansi@7.0.0": { + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dependencies": [ + "ansi-styles", + "string-width", + "strip-ansi" + ] + }, + "wrappy@1.0.2": { + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, + "y18n@5.0.8": { + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==" + }, + "yargs-parser@20.2.9": { + "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==" + }, + "yargs-unparser@2.0.0": { + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", + "dependencies": [ + "camelcase", + "decamelize", + "flat", + "is-plain-obj" + ] + }, + "yargs@16.2.0": { + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dependencies": [ + "cliui", + "escalade", + "get-caller-file", + "require-directory", + "string-width", + "y18n", + "yargs-parser" + ] + }, + "yocto-queue@0.1.0": { + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" + } + }, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:chai@^4.0.2", + "npm:mocha@^10.2.0", + "npm:should@5" + ], + "overrides": { + "serialize-javascript": "^7.0.5" + } + } + } +} diff --git a/index.js b/index.js index 367cc52..3c29505 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -module.exports = function(md, options) { +export default function removeMarkdown(md, options) { options = options || {}; options.listUnicodeChar = options.hasOwnProperty('listUnicodeChar') ? options.listUnicodeChar : false; options.stripListLeaders = options.hasOwnProperty('stripListLeaders') ? options.stripListLeaders : true; @@ -94,4 +94,4 @@ module.exports = function(md, options) { return md; } return output; -}; +} diff --git a/test/remove-markdown.js b/test/remove-markdown.test.js similarity index 82% rename from test/remove-markdown.js rename to test/remove-markdown.test.js index 812b749..0c4de1b 100644 --- a/test/remove-markdown.js +++ b/test/remove-markdown.test.js @@ -1,138 +1,139 @@ 'use strict'; -const expect = require('chai').expect; -const removeMd = require('../'); +import { describe, it } from "jsr:@std/testing/bdd" +import { expect } from "jsr:@std/expect" +import removeMd from '../index.js' describe('remove Markdown', function () { describe('removeMd', function () { it('should leave a string alone without markdown', function () { const string = 'Javascript Developers are the best.'; - expect(removeMd(string)).to.equal(string); + expect(removeMd(string)).toEqual(string); }); it('should strip out remaining markdown', function () { const string = '*Javascript* developers are the _best_.'; const expected = 'Javascript developers are the best.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should leave non-matching markdown markdown', function () { const string = '*Javascript* developers* are the _best_.'; const expected = 'Javascript developers* are the best.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should leave non-matching markdown, but strip empty anchors', function () { const string = '*Javascript* [developers]()* are the _best_.'; const expected = 'Javascript developers* are the best.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip HTML', function () { const string = '

Hello World

'; const expected = 'Hello World'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip anchors', function () { const string = '*Javascript* [developers](https://engineering.condenast.io/)* are the _best_.'; const expected = 'Javascript developers* are the best.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip img tags', function () { const string = '![](https://placebear.com/640/480)*Javascript* developers are the _best_.'; const expected = 'Javascript developers are the best.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should use the alt-text of an image, if it is provided', function () { const string = '![This is the alt-text](https://www.example.com/images/logo.png)'; const expected = 'This is the alt-text'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip code tags', function () { const string = 'In `Getting Started` we set up `something` foo.'; const expected = 'In Getting Started we set up something foo.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip simple multiline code tags', function () { const string = '```\ncode\n```'; const expected = 'code'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip complex multiline code blocks with language specified', function () { const string = '```javascript\nconst x = 1;\nconst y = 2;\nconsole.log(x + y);\n```'; const expected = 'const x = 1;\nconst y = 2;\nconsole.log(x + y);'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip multiline code blocks with multiple paragraphs', function () { const string = 'Text before\n\n```\ncode line 1\n\ncode line 2\n```\n\nText after'; const expected = 'Text before\n\ncode line 1\n\ncode line 2\n\nText after'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should leave hashtags in headings', function () { const string = '## This #heading contains #hashtags'; const expected = 'This #heading contains #hashtags'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove emphasis', function () { const string = 'I italicized an *I* and it _made_ me *sad*.'; const expected = 'I italicized an I and it made me sad.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove emphasis only if there is no space between word and emphasis characters.', function () { const string = 'There should be no _space_, *before* *closing * _ephasis character _.'; const expected = 'There should be no space, before *closing * _ephasis character _.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove "_" emphasis only if there is space before opening and after closing emphasis characters.', function () { const string = '._Spaces_ _ before_ and _after _ emphasised character results in no emphasis.'; const expected = '.Spaces _ before_ and _after _ emphasised character results in no emphasis.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove double emphasis', function () { const string = '**this sentence has __double styling__**'; const expected = 'this sentence has double styling'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should not mistake a horizontal rule when symbols are mixed ', function () { const string = 'Some text on a line\n\n--*\n\nA line below'; const expected = 'Some text on a line\n\n--*\n\nA line below'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove horizontal rules', function () { const string = 'Some text on a line\n\n---\n\nA line below'; const expected = 'Some text on a line\n\nA line below'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove horizontal rules with space-separated asterisks', function () { const string = 'Some text on a line\n\n* * *\n\nA line below'; const expected = 'Some text on a line\n\nA line below'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove blockquotes', function () { const string = '>I am a blockquote'; const expected = 'I am a blockquote'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove blockquotes with spaces', function () { const string = '> I am a blockquote'; const expected = 'I am a blockquote'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove indented blockquotes', function () { @@ -142,21 +143,21 @@ describe('remove Markdown', function () { { string: ' > I am a blockquote', expected: 'I am a blockquote' }, ]; tests.forEach(function (test) { - expect(removeMd(test.string)).to.equal(test.expected); + expect(removeMd(test.string)).toEqual(test.expected); }); }); it('should remove blockquotes over multiple lines', function () { const string = '> I am a blockquote firstline \n>I am a blockquote secondline'; const expected = 'I am a blockquote firstline \nI am a blockquote secondline'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove blockquotes following other content', function () { const string = '## A headline\n\nA paragraph of text\n\n> I am a blockquote'; const expected = 'A headline\n\nA paragraph of text\n\nI am a blockquote'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should not remove greater than signs', function () { @@ -169,56 +170,56 @@ describe('remove Markdown', function () { { string: '1 <= 100', expected: '1 <= 100' }, ]; tests.forEach(function (test) { - expect(removeMd(test.string)).to.equal(test.expected); + expect(removeMd(test.string)).toEqual(test.expected); }); }); it('should strip unordered list leaders', function () { const string = 'Some text on a line\n\n* A list Item\n* Another list item'; const expected = 'Some text on a line\n\nA list Item\nAnother list item'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip ordered list leaders', function () { const string = 'Some text on a line\n\n9. A list Item\n10. Another list item'; const expected = 'Some text on a line\n\nA list Item\nAnother list item'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should strip list items with bold word in the beginning', function () { const string = 'Some text on a line\n\n- **A** list Item\n- **Another** list item'; const expected = 'Some text on a line\n\nA list Item\nAnother list item'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should handle paragraphs with markdown', function () { const paragraph = '\n## This is a heading ##\n\nThis is a paragraph with [a link](http://www.disney.com/).\n\n### This is another heading\n\nIn `Getting Started` we set up `something` foo.\n\n * Some list\n * With items\n * Even indented'; const expected = '\nThis is a heading\n\nThis is a paragraph with a link.\n\nThis is another heading\n\nIn Getting Started we set up something foo.\n\n Some list\n With items\n Even indented'; - expect(removeMd(paragraph)).to.equal(expected); + expect(removeMd(paragraph)).toEqual(expected); }); it('should remove links', function () { const string = 'This is a [link](http://www.disney.com/).'; const expected = 'This is a link.'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should remove links with square brackets', function () { const string = 'This is a [link [with brackets]](http://www.disney.com/).'; const expected = 'This is a link [with brackets].'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should keep url instead of text when replaceLinksWithURL is enabled', function () { const string = 'This is a [link](http://www.disney.com/).'; const expected = 'This is a http://www.disney.com/.'; - expect(removeMd(string, { replaceLinksWithURL: true })).to.equal(expected); + expect(removeMd(string, { replaceLinksWithURL: true })).toEqual(expected); }); it('should not strip paragraphs without content', function() { const paragraph = '\n#This paragraph\n##This paragraph#'; const expected = paragraph; - expect(removeMd(paragraph)).to.equal(expected); + expect(removeMd(paragraph)).toEqual(expected); }); it('should not trigger ReDoS with atx-headers', function () { @@ -226,31 +227,31 @@ describe('remove Markdown', function () { const paragraph = '\n## This is a long "'+' '.repeat(200)+'" heading ##\n'; const expected = /\nThis is a long " {200}" heading\n/; - expect(removeMd(paragraph)).to.match(expected); + expect(removeMd(paragraph)).toMatch(expected); const duration = Date.now()-start; - expect(duration).to.be.lt(1000); + expect(duration).toBeLessThan(1000); }); it('should work fast even with lots of whitespace', function () { const string = 'Some text with lots of whitespace'; const expected = 'Some text with lots of whitespace'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should still remove escaped markdown syntax', function () { const string = '\# Heading in _italic_'; const expected = 'Heading in italic'; - expect(removeMd(string)).to.equal(expected); + expect(removeMd(string)).toEqual(expected); }); it('should skip specified HTML tags when htmlTagsToSkip option is provided', () => { const markdown = '
HTML content Superscript span text
' const result = removeMd(markdown, {htmlTagsToSkip: ['sub']}) - expect(result).to.equal('HTML content Superscript span text') + expect(result).toEqual('HTML content Superscript span text') const result2 = removeMd(markdown, {htmlTagsToSkip: ['sub', 'span']}) - expect(result2).to.equal( + expect(result2).toEqual( 'HTML content Superscript span text', ) }) @@ -258,7 +259,7 @@ describe('remove Markdown', function () { it('should replace inline link with text and link, with separator', function () { const string = 'some [inline link](http://www.disney.com/).'; const expected = 'some inline link: http://www.disney.com/.'; - expect(removeMd(string, {separateLinksAndTexts: ': '})).to.equal(expected); + expect(removeMd(string, {separateLinksAndTexts: ': '})).toEqual(expected); }); }); });