@@ -89,6 +89,8 @@ import { parseAssistantCitationHref } from "@t3tools/shared/assistantCitations";
8989import { parseComposerContextHref } from "@t3tools/shared/composerContextReferences" ;
9090import { AssistantCitationChip } from "./chat/AssistantCitationChip" ;
9191import remarkGfm from "remark-gfm" ;
92+ import type { Processor } from "unified" ;
93+ import { isWindowsAbsolutePath } from "@t3tools/shared/path" ;
9294import { remarkGithubAlerts } from "../markdown-github-alerts" ;
9395import {
9496 artifactTemplateFromHastProperties ,
@@ -490,6 +492,7 @@ const CHAT_MARKDOWN_SANITIZE_SCHEMA = {
490492
491493const CHAT_MARKDOWN_REMARK_PLUGINS = [
492494 remarkGfm ,
495+ remarkKeepWindowsPathDestinations ,
493496 remarkGithubAlerts ,
494497 remarkNormalizeListItemIndentation ,
495498 remarkCodexDirectives ,
@@ -499,6 +502,7 @@ const CHAT_MARKDOWN_REMARK_PLUGINS = [
499502
500503const CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS = [
501504 remarkGfm ,
505+ remarkKeepWindowsPathDestinations ,
502506 remarkGithubAlerts ,
503507 remarkNormalizeListItemIndentation ,
504508 remarkCodexDirectives ,
@@ -633,6 +637,36 @@ function remarkPreserveCodeMeta() {
633637 } ;
634638}
635639
640+ interface DestinationCompileContext {
641+ readonly stack : ReadonlyArray < { readonly type : string ; url ?: string } > ;
642+ resume ( ) : string ;
643+ sliceSerialize ( token : unknown ) : string ;
644+ }
645+
646+ function keepWindowsPathDestination ( this : DestinationCompileContext , token : unknown ) {
647+ const decoded = this . resume ( ) ;
648+ const authored = this . sliceSerialize ( token ) ;
649+ const node = this . stack . at ( - 1 ) ;
650+ // Character references still need decoding, so those destinations keep the parsed URL.
651+ if ( node )
652+ node . url = isWindowsAbsolutePath ( authored ) && ! authored . includes ( "&" ) ? authored : decoded ;
653+ }
654+
655+ /**
656+ * CommonMark reads the `\.` in `C:\me\.t3\shot.png` as an escape, even in a link
657+ * destination. Every backslash in a Windows path is a separator, so link, image, and
658+ * definition destinations that are Windows paths keep the text as written.
659+ */
660+ function remarkKeepWindowsPathDestinations ( this : Processor ) {
661+ const data = this . data ( ) ;
662+ ( data . fromMarkdownExtensions ??= [ ] ) . push ( {
663+ exit : {
664+ resourceDestinationString : keepWindowsPathDestination ,
665+ definitionDestinationString : keepWindowsPathDestination ,
666+ } ,
667+ } ) ;
668+ }
669+
636670/**
637671 * Preserve Windows drive links as allowed `file:` URLs before sanitization.
638672 * The same traversal tags inline code while it can still be distinguished
0 commit comments