Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const removeMarkdown = (
// Remove reference-style links?
.replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, "")
// Remove atx-style headers
// FIXME this can be slow
.replace(
/^(\n)?\s{0,}#{1,6}\s+| {0,}(\n)?\s{0,}#{0,} {0,}(\n)?\s{0,}$/gm,
"$1$2$3"
Expand Down
14 changes: 14 additions & 0 deletions test/removeMarkdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,19 @@ describe("Remove Markdown", () => {

expect(removeMarkdown(paragraph, { listUnicodeChar: false, preserveLinks: true })).to.equal(expected);
});

it("should handle weird string fast", () => {
const string =
" .";
const expected =
" .";

const start = performance.now();
const removedMarkdown = removeMarkdown(string);
const end = performance.now();
expect(end - start).to.below(1000);

expect(removedMarkdown).to.equal(expected);
});
});
});