@@ -20,6 +20,28 @@ export default function SyntaxResult({ content, status }) {
2020 setRows ( content . slice ( page * 10 , page * 10 + 10 ) )
2121 } , [ page , content ] ) ;
2222
23+ function renderMessage ( error_instance , numWhitespace , numHighlight ) {
24+ const beforeHighlight = error_instance . substring ( 0 , numWhitespace ) ;
25+ const highlightedChar = error_instance . substring ( numWhitespace , numWhitespace + numHighlight ) ;
26+ const afterHighlight = error_instance . substring ( numWhitespace + numHighlight ) ;
27+ return (
28+ < React . Fragment >
29+ { beforeHighlight }
30+ < span
31+ style = { {
32+ textDecoration : 'underline' ,
33+ fontWeight : 'bold' ,
34+ backgroundColor : '#ddd' ,
35+ border : 'solid 1px red'
36+ } }
37+ >
38+ { highlightedChar }
39+ </ span >
40+ { afterHighlight }
41+ </ React . Fragment >
42+ ) ;
43+ } ;
44+
2345 return (
2446 < Paper sx = { { overflow : 'hidden' } } >
2547 < TreeView
@@ -51,10 +73,23 @@ export default function SyntaxResult({ content, status }) {
5173 < TreeItem nodeId = "0" label = "Syntax" >
5274 { rows . length
5375 ? rows . map ( item => {
54- const msg_parts = item . msg . split ( '\n' )
55- const whitespaces = msg_parts [ msg_parts . length - 1 ] . match ( / \s * / ) [ 0 ] . length ;
56- const error_instance = msg_parts [ msg_parts . length - 2 ]
57- const modifiedStr = `${ error_instance . substring ( 0 , whitespaces ) } <span style='text-decoration:underline; font-weight:bold; background-color:#ddd;'>${ error_instance [ whitespaces ] } </span>${ error_instance . substring ( whitespaces + 1 ) } ` ;
76+ const msg_parts = item . msg . split ( '\n' ) ;
77+ const [ _ , numWhitespace , numHighlight ] = msg_parts [ msg_parts . length - 1 ] . match ( / ( \s * ) ( \^ + ) / ) . map ( s => s . length ) ;
78+ const error_instance = msg_parts [ msg_parts . length - 2 ] ;
79+
80+ const errorMessage = renderMessage (
81+ error_instance ,
82+ numWhitespace ,
83+ numHighlight
84+ ) ;
85+
86+
87+ // const beforeHighlight = error_instance.substring(0, numWhitespace);
88+ // const highlightedChar = error_instance.substring(numWhitespace, numWhitespace + numHighlight);
89+ // const afterHighlight = error_instance.substring(numWhitespace + numHighlight);
90+
91+
92+ // debugger;
5893
5994 return < TreeView defaultCollapseIcon = { < ExpandMoreIcon /> }
6095 defaultExpandIcon = { < ChevronRightIcon /> } >
@@ -70,7 +105,7 @@ export default function SyntaxResult({ content, status }) {
70105 < td >
71106 < span class = 'pre' > { item . msg . split ( '\n' ) . slice ( 0 , - 2 ) . join ( '\n' ) } </ span >
72107 < br /> { }
73- < span class = 'pre mono' dangerouslySetInnerHTML = { { __html : modifiedStr } } > </ span >
108+ < span class = 'pre mono' > { errorMessage } </ span >
74109 </ td >
75110 </ tr >
76111 </ tbody >
0 commit comments