Skip to content

Commit

Permalink
Simplify spoiler regex (#125)
Browse files Browse the repository at this point in the history
This fixes an issue where trailing characters after the spoiler would
severely effect performance.

Fixes #123
  • Loading branch information
spenserblack authored Mar 18, 2023
1 parent 621c3bf commit a67f422
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
5 changes: 0 additions & 5 deletions packages/steamdown/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ describe("formatting", () => {
test("exclamation outside of spoiler", () => {
expect(parse("!!!spoiler text!!!\\!")).toBe("[spoiler]spoiler text[/spoiler]!");
});
test("spoiler with newlines", () => {
expect(parse("!!!spoiler\nthis\ntext!!!")).toBe(
"[spoiler]spoiler\nthis\ntext[/spoiler]",
);
});
});

describe("Literal text", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/steamdown/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const spoiler: Extension = {
return src.match(/!!!/)?.index as number;
},
tokenizer(src: string): SpoilerToken | void {
const match = src.match(/^!!!((?:.+\n|.*)*[^\n])!!!/);
const match = src.match(/^!!!([^\n]*)!!!/);
if (match) {
return {
type: "spoiler",
Expand Down

1 comment on commit a67f422

@vercel
Copy link

@vercel vercel bot commented on a67f422 Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

steamdown – ./

steamdown.vercel.app
steamdown-git-main-spenserblack.vercel.app
steamdown-spenserblack.vercel.app

Please sign in to comment.