-
-
Notifications
You must be signed in to change notification settings - Fork 109
Add workaround for CSS HEX colors in markdown. #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ludeeus
wants to merge
3
commits into
main
Choose a base branch
from
workaround-for-css
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,119 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { markdownWithRepositoryContext } from "../src/tools/markdown.js"; | ||
import type { RepositoryInfo } from "../src/data/repository.js"; | ||
|
||
const mockRepository: RepositoryInfo = { | ||
id: "123", | ||
full_name: "awesome/repo", | ||
default_branch: "main", | ||
available_version: "v1.0.0", | ||
} as RepositoryInfo; | ||
|
||
describe("markdownWithRepositoryContext", () => { | ||
it("should convert GitHub issue references to links", () => { | ||
const input = "See issue #123 for details"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe("See issue [#123](https://github.com/awesome/repo/issues/123) for details"); | ||
}); | ||
|
||
it("should NOT convert CSS color codes", () => { | ||
const input = "Set color: #123456 in your CSS"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe("Set color: #123456 in your CSS"); | ||
}); | ||
|
||
it("should NOT convert CSS shorthand colors", () => { | ||
const input = "Use background:#123; border:#abc;"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe("Use background:#123; border:#abc;"); | ||
}); | ||
|
||
it("should handle mixed scenarios correctly", () => { | ||
const input = "Fix issue #42 but keep color:#333 and border:#456 styles intact"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe( | ||
"Fix issue [#42](https://github.com/awesome/repo/issues/42) but keep color:#333 and border:#456 styles intact", | ||
); | ||
}); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
it("should convert legitimate issue numbers but not hex colors", () => { | ||
const input = "Issue #123 was fixed, but color: #456789 remains unchanged"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe( | ||
"Issue [#123](https://github.com/awesome/repo/issues/123) was fixed, but color: #456789 remains unchanged", | ||
); | ||
}); | ||
|
||
it("should work without repository context", () => { | ||
const input = "Some text with #123 reference"; | ||
const result = markdownWithRepositoryContext(input); | ||
expect(result).toBe("Some text with #123 reference"); | ||
}); | ||
|
||
it("should NOT convert CSS hex colors in code examples", () => { | ||
const input = "Example CSS: div { color:#ff0000; background:#123456; }"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe("Example CSS: div { color:#ff0000; background:#123456; }"); | ||
}); | ||
|
||
it("should handle repository/issue references correctly", () => { | ||
const input = "Check out awesome/other-repo#456 for more info"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe( | ||
"Check out [awesome/other-repo#456](https://github.com/awesome/other-repo/issues/456) for more info", | ||
); | ||
}); | ||
|
||
it("should handle issue numbers with 8 and 9 (non-hex digits)", () => { | ||
const input = "See issues #789 and #98 for details"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe( | ||
"See issues [#789](https://github.com/awesome/repo/issues/789) and [#98](https://github.com/awesome/repo/issues/98) for details", | ||
); | ||
}); | ||
|
||
it("should NOT convert 6-digit hex colors in CSS context", () => { | ||
const input = "Apply color:#ffffff and background-color:#000000 styles"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe("Apply color:#ffffff and background-color:#000000 styles"); | ||
}); | ||
|
||
it("should convert valid issue numbers that contain non-hex digits", () => { | ||
const input = "Fixed in #987 and resolved in #1289"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe( | ||
"Fixed in [#987](https://github.com/awesome/repo/issues/987) and resolved in [#1289](https://github.com/awesome/repo/issues/1289)", | ||
); | ||
}); | ||
|
||
it("should handle mixed CSS and issue references in same text", () => { | ||
const input = "Issue #789 fixed. Use border:#123; and see #890 too"; | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
expect(result).toBe( | ||
"Issue [#789](https://github.com/awesome/repo/issues/789) fixed. Use border:#123; and see [#890](https://github.com/awesome/repo/issues/890) too", | ||
); | ||
}); | ||
it("should handle large text efficiently", () => { | ||
// Create a large string with mixed content to test performance | ||
const parts: string[] = []; | ||
for (let i = 0; i < 25_000; i++) { | ||
parts.push(`Issue #${i + 1} was fixed. Use color:#${String(i).padStart(3, "0")}; in CSS.`); | ||
} | ||
const input = parts.join(" "); | ||
|
||
const start = performance.now(); | ||
const result = markdownWithRepositoryContext(input, mockRepository); | ||
const end = performance.now(); | ||
|
||
// Should complete in reasonable time (< 100ms for this test) | ||
expect(end - start).toBeLessThan(100); | ||
|
||
// Should have converted all issue references | ||
expect(result).toContain("[#1](https://github.com/awesome/repo/issues/1)"); | ||
expect(result).toContain("[#25000](https://github.com/awesome/repo/issues/25000)"); | ||
|
||
// Should not have converted CSS colors | ||
expect(result).toContain("color:#001;"); | ||
expect(result).toContain("color:#099;"); | ||
}); | ||
}); |
This file contains hidden or 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,8 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
environment: "node", | ||
include: ["tests/**/*.test.{js,ts}"], | ||
}, | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.