fix(web): make Windows file links clickable #6237
Closedpeculiarnewbie(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/6237/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
peculiarnewbie(GitHub profile, opens in a new tab) reopened this
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -110 +110,21 @@110110111+interface MarkdownLinkNode {112+ type?: string;113+ url?: unknown;114+ children?: MarkdownLinkNode[];115+}116+117+/**118+ * rehype-sanitize reads the drive letter in `C:/path` as a URL scheme and119+ * removes the href before react-markdown's URL transform can normalize it.120+ * Convert only Windows drive-path destinations into the already-allowed file121+ * URI form while the document is still mdast.122+ */123+export function remarkRewriteWindowsFileLinks() {124+ return (tree: MarkdownLinkNode) => {125+ const visit = (node: MarkdownLinkNode) => {126+ if ((node.type === "link" || node.type === "definition") && typeof node.url === "string") {127+ const normalizedUrl = normalizeMarkdownLinkDestination(node.url);128+ if (WINDOWS_DRIVE_PATH_PATTERN.test(normalizedUrl)) {129+ node.url = `file:///${normalizedUrl.replaceAll("\\", "/")}`;130+ }
- @@ -109,2 +112,21 @@109112 }110113114+interface MarkdownLinkNode {115+ type?: string;116+ url?: unknown;117+ children?: MarkdownLinkNode[];118+}119+120+/**121+ * rehype-sanitize reads the drive letter in `C:/path` as a URL scheme and122+ * removes the href before react-markdown's URL transform can normalize it.123+ * Convert only Windows drive-path destinations into the already-allowed file124+ * URI form while the document is still mdast.125+ */126+export function remarkRewriteWindowsFileLinks() {127+ return (tree: MarkdownLinkNode) => {128+ const visit = (node: MarkdownLinkNode) => {129+ if ((node.type === "link" || node.type === "definition") && typeof node.url === "string") {130+ const normalizedUrl = normalizeMarkdownLinkDestination(node.url);131+ if (WINDOWS_DRIVE_PATH_PATTERN.test(normalizedUrl)) {132+ node.url = `file:///${normalizedUrl}`;
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.




Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
8c280e0d-dd44-4bf0-9dab-3c58ad0bb2c3You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share