Fix pull request panel markdown on native

This commit is contained in:
Mohamed Boudra
2026-06-12 13:18:01 +07:00
parent f930956e5c
commit 9e9d0ee305
2 changed files with 21 additions and 1 deletions

View File

@@ -242,6 +242,14 @@ describe("splitHtmlishMarkdown", () => {
expect(splitHtmlishMarkdown(source)).toEqual([{ kind: "markdown", text: source }]);
});
it("keeps details inside inline code on native runtimes without copied array sorting", () => {
const source = "Use `<details><summary>Example</summary>Body</details>` as an example.";
expect(withoutArrayToSorted(() => splitHtmlishMarkdown(source))).toEqual([
{ kind: "markdown", text: source },
]);
});
it("keeps details inside inline code as literal markdown", () => {
const source = "Use `<details><summary>Example</summary>Body</details>` as an example.";
@@ -310,3 +318,15 @@ describe("splitHtmlishMarkdown", () => {
]);
});
});
function withoutArrayToSorted<T>(callback: () => T): T {
const descriptor = Object.getOwnPropertyDescriptor(Array.prototype, "toSorted");
Reflect.deleteProperty(Array.prototype, "toSorted");
try {
return callback();
} finally {
if (descriptor) {
Reflect.defineProperty(Array.prototype, "toSorted", descriptor);
}
}
}

View File

@@ -681,7 +681,7 @@ function findClosingBacktickRun(
}
function mergeProtectedRanges(ranges: ProtectedMarkdownRange[]): ProtectedMarkdownRange[] {
const sorted = ranges.toSorted((a, b) => a.start - b.start);
const sorted = [...ranges].sort((a, b) => a.start - b.start);
const merged: ProtectedMarkdownRange[] = [];
for (const range of sorted) {