forked from obvious-inc/frontend-monorepo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(camp): correctly apply and remove markdown blockquotes
We previously didn’t handle all line boundaries, e.g. U+2028, which prevented some reposts from matching. This unfortunately won’t fix already broken ones. We are in your debt Benjamin.
- Loading branch information
Showing
7 changed files
with
436 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { expect, test } from "vitest"; | ||
import { createRepostExtractor } from "./votes-and-feedbacks.js"; | ||
|
||
const sourceReasons = [ | ||
"foo", | ||
"bar", | ||
`baz | ||
+1 | ||
> foo`, | ||
"foo\u2028bar", | ||
]; | ||
|
||
test("repost extraction", () => { | ||
const extract = createRepostExtractor( | ||
sourceReasons.map((reason) => ({ reason })), | ||
); | ||
|
||
const tests = [ | ||
{ reason: "+1\n\n> foo", expectedMatchIndecies: [0] }, | ||
{ | ||
reason: `comment | ||
+1 | ||
> bar | ||
comment | ||
+1 | ||
>baz | ||
comment`, | ||
expectedMatchIndecies: [1, 2], | ||
}, | ||
{ | ||
reason: `comment | ||
+1 | ||
> baz | ||
> | ||
> +1 | ||
> | ||
> > foo`, | ||
expectedMatchIndecies: [2], | ||
}, | ||
{ reason: "+1\n\n> foo\u2028bar", expectedMatchIndecies: [0] }, | ||
{ reason: "+1\n\n> foo\u2028> bar", expectedMatchIndecies: [3] }, | ||
]; | ||
|
||
for (const { reason, expectedMatchIndecies } of tests) { | ||
const [matchingPosts] = extract(reason); | ||
const matchingReasons = matchingPosts.map((p) => p.reason); | ||
const expectedMatchingReasons = expectedMatchIndecies.map( | ||
(index) => sourceReasons[index], | ||
); | ||
for (const expectedMatchingReason of expectedMatchingReasons) { | ||
expect(matchingReasons).toContain(expectedMatchingReason); | ||
} | ||
for (const matchingReason of matchingReasons) { | ||
expect(expectedMatchingReasons).toContain(matchingReason); | ||
} | ||
expect(matchingPosts.length).toBe(expectedMatchIndecies.length); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect, test } from "vitest"; | ||
import { blockquote, unquote } from "./markdown.js"; | ||
|
||
test("blockquote()", () => { | ||
expect(blockquote("foo")).toBe("> foo"); | ||
expect(blockquote("foo \n bar")).toBe("> foo \n> bar"); | ||
expect(blockquote("foo\n")).toBe("> foo\n"); | ||
expect(blockquote("foo\u2028bar")).toBe("> foo\u2028> bar"); | ||
}); | ||
|
||
test("unquote()", () => { | ||
expect(unquote("> foo")).toBe("foo"); | ||
expect(unquote(">foo")).toBe("foo"); | ||
expect(unquote("> foo")).toBe(" foo"); | ||
expect(unquote("> foo\n> bar")).toBe("foo\nbar"); | ||
expect(() => unquote("> foo\u2028bar")).toThrow(/invalid blockquote/); | ||
expect(unquote("> foo\u2028> bar")).toBe("foo\u2028bar"); | ||
}); |
Oops, something went wrong.