Skip to content

Commit

Permalink
fix: use named export to make it compatible with vite
Browse files Browse the repository at this point in the history
  • Loading branch information
ad1992 committed Aug 22, 2023
1 parent 0cd850c commit 1e23a31
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Changelog entries are classified using the following labels _(from [keep-a-chang
- `removed`: for deprecated features removed in this release
- `fixed`: for any bug fixes

## [0.1.2] - 2023-08-22

### Changed

- Make `removeMarkdown` a named export instead of default so its compatible with Vite

## [0.1.1] - 2020-12-13

### Added
Expand Down
10 changes: 6 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const removeMarkdown = (
options.useImgAltText = options.hasOwnProperty("useImgAltText")
? options.useImgAltText
: true;
options.preserveLinks = options.hasOwnProperty("preserveLinks") ? options.preserveLinks : false;
options.preserveLinks = options.hasOwnProperty("preserveLinks")
? options.preserveLinks
: false;

let output = markdown || "";

Expand All @@ -61,9 +63,9 @@ const removeMarkdown = (
// Fenced codeblocks
.replace(/`{3}.*\n/g, "");
}
if(options.preserveLinks) {
if (options.preserveLinks) {
// Remove inline links while preserving the links
output = output.replace(/\[(.*?)\][\[\(](.*?)[\]\)]/g, "$1 ($2)")
output = output.replace(/\[(.*?)\][\[\(](.*?)[\]\)]/g, "$1 ($2)");
}
output = output
// Remove HTML tags
Expand Down Expand Up @@ -104,4 +106,4 @@ const removeMarkdown = (
return output;
};

export default removeMarkdown;
export { removeMarkdown };
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markdown-to-text",
"version": "0.1.1",
"name": "@excalidraw/markdown-to-text",
"version": "0.1.2",
"description": "Parse the markdown and returns a string",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 7 additions & 2 deletions test/removeMarkdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { expect } from "chai";

// Utils
import removeMarkdown from "../";
import { removeMarkdown } from "../";

describe("Remove Markdown", () => {
describe("Remove", () => {
Expand Down Expand Up @@ -185,7 +185,12 @@ describe("Remove Markdown", () => {
const expected =
"\nThis is a heading\n\nThis is a paragraph with a link (http://www.disney.com/).\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(removeMarkdown(paragraph, { listUnicodeChar: false, preserveLinks: true })).to.equal(expected);
expect(
removeMarkdown(paragraph, {
listUnicodeChar: false,
preserveLinks: true,
})
).to.equal(expected);
});
});
});

0 comments on commit 1e23a31

Please sign in to comment.