@@ -40,6 +40,31 @@ interface InternalDataLink {
4040 arraySize ?: number [ ] ;
4141}
4242
43+ const transformJsonForDisplay = ( obj : any ) : any => {
44+ if ( typeof obj !== "object" || obj === null ) return obj ;
45+
46+ const transformed : any = Array . isArray ( obj ) ? [ ] : { } ;
47+
48+ for ( const key in obj ) {
49+ if ( ! Object . prototype . hasOwnProperty . call ( obj , key ) ) continue ;
50+
51+ const value = obj [ key ] ;
52+
53+ // Match README, CHANGES, or file extensions
54+ const isLongTextKey = / ^ ( R E A D M E | C H A N G E S ) $ | \. m d $ | \. t x t $ | \. m $ / i. test ( key ) ;
55+
56+ if ( typeof value === "string" && isLongTextKey ) {
57+ transformed [ key ] = `<code class="puretext">${ value } </code>` ;
58+ } else if ( typeof value === "object" ) {
59+ transformed [ key ] = transformJsonForDisplay ( value ) ;
60+ } else {
61+ transformed [ key ] = value ;
62+ }
63+ }
64+
65+ return transformed ;
66+ } ;
67+
4368const DatasetDetailPage : React . FC = ( ) => {
4469 const { dbName, docId } = useParams < { dbName : string ; docId : string } > ( ) ;
4570 const navigate = useNavigate ( ) ;
@@ -208,7 +233,20 @@ const DatasetDetailPage: React.FC = () => {
208233 element . classList . remove ( "highlighted" ) ;
209234 } ) ;
210235 } ;
211- } , [ searchTerm , datasetDocument ] ) ;
236+ } , [ searchTerm , datasetDocument ] ) ;
237+
238+ useEffect ( ( ) => {
239+ if ( ! transformedDataset ) return ;
240+
241+ const spans = document . querySelectorAll ( ".string-value" ) ;
242+
243+ spans . forEach ( ( el ) => {
244+ if ( el . textContent ?. includes ( "<code class=\"puretext\">" ) ) {
245+ // Inject as HTML so it renders code block correctly
246+ el . innerHTML = el . textContent ?? "" ;
247+ }
248+ } ) ;
249+ } , [ transformedDataset ] ) ;
212250
213251 const handleDownloadDataset = ( ) => {
214252 if ( ! datasetDocument ) return ;
@@ -402,6 +440,32 @@ const DatasetDetailPage: React.FC = () => {
402440 }
403441
404442 return (
443+ < >
444+ { /* 🔧 Inline CSS for string formatting */ }
445+ < style >
446+ { `
447+ code.puretext {
448+ white-space: pre-wrap;
449+ display: -webkit-box;
450+ -webkit-box-orient: vertical;
451+ -webkit-line-clamp: 4;
452+ overflow: hidden;
453+ text-overflow: ellipsis;
454+ font-family: monospace;
455+ color: #d14;
456+ font-size: 14px;
457+ background-color: transparent;
458+ cursor: pointer;
459+ transition: all 0.2s ease;
460+ }
461+
462+ code.puretext:hover, code.puretext:focus {
463+ -webkit-line-clamp: unset;
464+ overflow: visible;
465+ background-color: #f0f0f0;
466+ }` }
467+
468+ </ style >
405469 < Box sx = { { padding : 4 } } >
406470 < Button
407471 variant = "contained"
@@ -413,12 +477,12 @@ const DatasetDetailPage: React.FC = () => {
413477
414478 < Box
415479 sx = { {
416- position : "sticky" , // ✅ Keeps title & search bar fixed
417- top : 0 , // ✅ Sticks to the top
418- backgroundColor : "white" , // ✅ Ensures smooth UI
419- zIndex : 10 , // ✅ Keeps it above scrollable content
420- paddingBottom : 2 , // ✅ Adds space for clarity
421- borderBottom : `1px solid ${ Colors . lightGray } ` , // ✅ Adds subtle separator
480+ position : "sticky" ,
481+ top : 0 ,
482+ backgroundColor : "white" ,
483+ zIndex : 10 ,
484+ paddingBottom : 2 ,
485+ borderBottom : `1px solid ${ Colors . lightGray } ` ,
422486 } } >
423487
424488 { /* ✅ Dataset Title (From dataset_description.json) */ }
@@ -542,7 +606,7 @@ const DatasetDetailPage: React.FC = () => {
542606 { /* ✅ JSON Viewer (left panel) */ }
543607 < Box sx = { { flex : 3 , backgroundColor : "#f5f5f5" , padding : 2 , borderRadius : "8px" , overflowX : "auto" } } >
544608 < ReactJson
545- src = { datasetDocument }
609+ src = { transformedDataset || datasetDocument }
546610 name = { false }
547611 enableClipboard = { true }
548612 displayDataTypes = { false }
@@ -761,7 +825,8 @@ const DatasetDetailPage: React.FC = () => {
761825 isInternal = { previewIsInternal }
762826 onClose = { handleClosePreview }
763827 />
764- </ Box >
828+ </ Box >
829+ </ >
765830 ) } ;
766831
767832export default DatasetDetailPage ;
0 commit comments