mirror of
https://github.com/outline/outline.git
synced 2026-11-26 15:43:48 +03:00
* fix: Pasting a table from Google Sheets does not create a table Spreadsheet cells containing currency amounts caused isMarkdown to misread the tab-separated plain text flavour of the clipboard as inline LaTeX, so the paste handler discarded the HTML table and reparsed the text as Markdown. Tighten the LaTeX heuristic to require delimiters that hug their content and a closing delimiter not followed by a digit, and always prefer the HTML parser when the clipboard HTML contains a table. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Remove lookbehind in regex --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
98 lines
2.3 KiB
TypeScript
98 lines
2.3 KiB
TypeScript
import isMarkdown from "./isMarkdown";
|
|
|
|
test("returns false for an empty string", () => {
|
|
expect(isMarkdown("")).toBe(false);
|
|
});
|
|
|
|
test("returns false for plain text", () => {
|
|
expect(isMarkdown("plain text")).toBe(false);
|
|
});
|
|
|
|
test("returns true for bullet list", () => {
|
|
expect(
|
|
isMarkdown(`- item one
|
|
- item two
|
|
- nested item`)
|
|
).toBe(true);
|
|
});
|
|
|
|
test("returns true for code fence", () => {
|
|
expect(
|
|
isMarkdown(`\`\`\`javascript
|
|
this is code
|
|
\`\`\``)
|
|
).toBe(true);
|
|
});
|
|
|
|
test("returns true for latex fence", () => {
|
|
expect(isMarkdown(`$i$`)).toBe(true);
|
|
expect(
|
|
isMarkdown(`$0.00
|
|
random content
|
|
$1.00`)
|
|
).toBe(false);
|
|
});
|
|
|
|
it("returns false for currency amounts on a single line", () => {
|
|
expect(isMarkdown(`-$187.55\t-$91.93`)).toBe(false);
|
|
expect(
|
|
isMarkdown(`-$187.55\t-$91.93
|
|
-$2,222.97\t-$4,109.98`)
|
|
).toBe(false);
|
|
expect(isMarkdown(`It costs $10 or $20`)).toBe(false);
|
|
});
|
|
|
|
test("returns false for non-closed fence", () => {
|
|
expect(
|
|
isMarkdown(`\`\`\`
|
|
this is not code
|
|
`)
|
|
).toBe(false);
|
|
});
|
|
|
|
test("returns true for heading", () => {
|
|
expect(isMarkdown(`# Heading 1`)).toBe(true);
|
|
expect(isMarkdown(`## Heading 2`)).toBe(true);
|
|
expect(isMarkdown(`### Heading 3`)).toBe(true);
|
|
});
|
|
|
|
test("returns true for table", () => {
|
|
expect(
|
|
isMarkdown(`
|
|
|NAME|TYPE|CLUSTER-IP|EXTERNAL-IP|PORT(S)|AGE|
|
|
|-|-|-|-|-|-|
|
|
|rancher-webhook|ClusterIP|10.43.198.97|<none>|443/TCP|258d|
|
|
|rancher|ClusterIP|10.43.50.214|<none>|80/TCP,443/TCP|258d|
|
|
`)
|
|
).toBe(true);
|
|
|
|
expect(
|
|
isMarkdown(`
|
|
| Product | Price ($) | Inventory |
|
|
|---------|----------:|----------:|
|
|
| Laptop | 899.99 | 52 |
|
|
| Wireless Mouse | 24.99 | 120 |`)
|
|
).toBe(true);
|
|
});
|
|
|
|
test("returns false for hashtag", () => {
|
|
expect(isMarkdown(`Test #hashtag`)).toBe(false);
|
|
expect(isMarkdown(` #hashtag`)).toBe(false);
|
|
});
|
|
|
|
test("returns true for absolute link", () => {
|
|
expect(isMarkdown(`[title](http://www.google.com)`)).toBe(true);
|
|
});
|
|
|
|
test("returns true for relative link", () => {
|
|
expect(isMarkdown(`[title](/doc/mydoc-234tnes)`)).toBe(true);
|
|
});
|
|
|
|
test("returns true for relative image", () => {
|
|
expect(isMarkdown(``)).toBe(true);
|
|
});
|
|
|
|
test("returns true for absolute image", () => {
|
|
expect(isMarkdown(``)).toBe(true);
|
|
});
|