@@ -182,20 +182,29 @@ export const LabReportTemplate = React.forwardRef<HTMLDivElement, LabReportTempl
182182 ) ;
183183 }
184184
185- // Handle Chemical Sketcher
186- const sketchMatch = part . match ( / \[ \[ s k e t c h e r : ( [ \s \S ] * ? ) # # # S K E T C H _ S E P # # # ( [ \s \S ] * ? ) \] \] / ) ;
185+ // Handle Chemical Sketcher (Base64 version)
186+ const sketchMatch = part . match ( / \[ \[ s k e t c h e r : ( [ A - Z a - z 0 - 9 + / = ] + ) \] \] / ) ;
187187 if ( sketchMatch ) {
188- const svgContent = sketchMatch [ 2 ] ;
189- return (
190- < div
191- key = { i }
192- className = "my-4 p-4 border border-gray-100 rounded-xl bg-gray-50/50"
193- style = { { width : '100%' , display : 'flex' , justifyContent : 'center' } }
194- dangerouslySetInnerHTML = { {
195- __html : svgContent . replace ( '<svg' , '<svg style="width:100%; height:auto; max-height:280px" preserveAspectRatio="xMidYMid meet"' )
196- } }
197- />
198- ) ;
188+ try {
189+ const base64 = sketchMatch [ 1 ] ;
190+ const decoded = decodeURIComponent ( escape ( atob ( base64 ) ) ) ;
191+ const payload = JSON . parse ( decoded ) ;
192+ const svgContent = payload . svg ;
193+
194+ return (
195+ < div
196+ key = { i }
197+ className = "my-4 p-4 border border-gray-100 rounded-xl bg-gray-50/50"
198+ style = { { width : '100%' , display : 'flex' , justifyContent : 'center' } }
199+ dangerouslySetInnerHTML = { {
200+ __html : svgContent . replace ( '<svg' , '<svg style="width:100%; height:auto; max-height:280px" preserveAspectRatio="xMidYMid meet"' )
201+ } }
202+ />
203+ ) ;
204+ } catch ( err ) {
205+ console . error ( "PDF Sketcher Decode Error:" , err ) ;
206+ return < span className = "text-red-400 text-[10px]" > Error rendering structure</ span > ;
207+ }
199208 }
200209
201210 return part ;
0 commit comments