@@ -11,7 +11,10 @@ import {
1111import { videoMimeType } from "@t3tools/shared/video" ;
1212import { createContext , useContext , useMemo , useState } from "react" ;
1313import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown" ;
14- import type { ReferenceAutolink } from "@t3tools/client-runtime/source-control-clients" ;
14+ import {
15+ sourceControlClients ,
16+ type ReferenceAutolink ,
17+ } from "@t3tools/client-runtime/source-control-clients" ;
1518import { linkReferenceAutolinks } from "./pullRequestAutolinks" ;
1619
1720import { useOpenPullRequest } from "../../native/useOpenPullRequest" ;
@@ -31,6 +34,7 @@ import type { MarkdownImageRenderer } from "../../native/SelectableMarkdownText"
3134const AutolinksContext = createContext < ( ( text : string ) => ReadonlyArray < ReferenceAutolink > ) | null > (
3235 null ,
3336) ;
37+ const LineBreaksContext = createContext ( false ) ;
3438
3539export function PullRequestMarkdownRepository ( props : {
3640 /** The change request the markdown belongs to, whose host decides what its text links. */
@@ -44,6 +48,7 @@ export function PullRequestMarkdownRepository(props: {
4448 provider === undefined || url === undefined
4549 ? null
4650 : changeRequestReferenceAutolinker ( { provider, url } ) ;
51+ const lineBreaks = sourceControlClients . find ( provider ?? "" ) ?. hardLineBreaks ?? false ;
4752 const target = pullRequestTarget ( props . params ) ;
4853 const project = useProject ( {
4954 environmentId : target . environmentId ,
@@ -53,7 +58,9 @@ export function PullRequestMarkdownRepository(props: {
5358 const media = cwd ? { environmentId : target . environmentId , cwd } : null ;
5459 return (
5560 < AutolinksContext value = { autolinks } >
56- < PullRequestMediaContext value = { media } > { props . children } </ PullRequestMediaContext >
61+ < LineBreaksContext value = { lineBreaks } >
62+ < PullRequestMediaContext value = { media } > { props . children } </ PullRequestMediaContext >
63+ </ LineBreaksContext >
5764 </ AutolinksContext >
5865 ) ;
5966}
@@ -88,6 +95,7 @@ function MarkdownImage(props: {
8895export function PullRequestMarkdown ( props : {
8996 readonly markdown : string ;
9097 readonly imageGroupMarkdown ?: string ;
98+ readonly lineBreaks ?: boolean ;
9199} ) {
92100 const segments = useMemo ( ( ) => splitPullRequestBody ( props . markdown ) , [ props . markdown ] ) ;
93101 return (
@@ -98,6 +106,7 @@ export function PullRequestMarkdown(props: {
98106 key = { segment . id }
99107 markdown = { segment . text }
100108 imageGroupMarkdown = { props . imageGroupMarkdown ?? props . markdown }
109+ lineBreaks = { props . lineBreaks }
101110 />
102111 ) : (
103112 < PullRequestMedia key = { segment . id } url = { segment . url } kind = { segment . media } />
@@ -110,7 +119,9 @@ export function PullRequestMarkdown(props: {
110119function PullRequestMarkdownContent ( props : {
111120 readonly markdown : string ;
112121 readonly imageGroupMarkdown ?: string ;
122+ readonly lineBreaks : boolean | undefined ;
113123} ) {
124+ const hostLineBreaks = useContext ( LineBreaksContext ) ;
114125 const autolinks = useContext ( AutolinksContext ) ;
115126 const mediaContext = useContext ( PullRequestMediaContext ) ;
116127 const markdown = linkReferenceAutolinks ( props . markdown , autolinks ) ;
@@ -136,6 +147,7 @@ function PullRequestMarkdownContent(props: {
136147 < FilePreviewGallery value = { gallery } >
137148 < SelectableMarkdownText
138149 markdown = { markdown }
150+ preserveSoftBreaks = { props . lineBreaks ?? hostLineBreaks }
139151 textStyle = { styles . nativeTextStyle }
140152 onLinkPress = { openLink }
141153 renderImage = { renderImage }
0 commit comments