@@ -30,7 +30,8 @@ function isSolverComment(commentData) {
3030}
3131
3232function formatCommentData ( commentData ) {
33- let changedCommentText = `<span class="comment-author">${ commentData . author_name } :</span> ${ commentData . text } ` ;
33+ const commentText = DOMPurify . sanitize ( marked . parse ( commentData . text ) ) ;
34+ let changedCommentText = `<span class="comment-author">${ commentData . author_name } :</span> ${ commentText } ` ;
3435 if ( window . isUserGrader ( ) || isSolverComment ( commentData ) ) {
3536 const deleteButton = `<i class="fa fa-trash grader-delete" aria-hidden="true" data-commentid="${ commentData . id } " onclick="deleteComment(${ window . fileId } , ${ commentData . id } );"></i>` ;
3637 changedCommentText = `${ deleteButton } ${ changedCommentText } ` ;
@@ -55,10 +56,14 @@ function addCommentToLine(line, commentData) {
5556 boundary : 'viewport' ,
5657 placement : 'auto' ,
5758 } ) ;
59+
60+ commentElement . addEventListener ( 'shown.bs.popover' , function ( ) {
61+ Prism . highlightAllUnder ( existingPopover . tip ) ;
62+ } )
5863 }
5964
6065 commentElement . dataset . comment = 'true' ;
61- if ( commentData . is_auto ) {
66+ if ( ( commentData . is_auto ) && ( commentElement . dataset . marked !== 'true' ) ) {
6267 markLine ( commentElement , FLAKE_COMMENTED_LINE_COLOR ) ;
6368 } else {
6469 const lineColor = window . getLineColorByRole ( commentData . author_role ) ;
@@ -140,6 +145,17 @@ function addLineSpansToPre(items) {
140145 window . dispatchEvent ( new Event ( 'lines-numbered' ) ) ;
141146}
142147
148+ function configureMarkdownParser ( ) {
149+ marked . use ( {
150+ renderer : {
151+ code : ( code , infoString , _ ) => {
152+ const language = infoString || 'plaintext' ;
153+ return `<pre><code class="language-${ language } ">${ code } </code></pre>` ;
154+ }
155+ } ,
156+ } ) ;
157+ }
158+
143159window . markLink = markLine ;
144160window . hoverLine = hoverLine ;
145161window . addCommentToLine = addCommentToLine ;
@@ -152,6 +168,7 @@ window.addEventListener('load', () => {
152168 sessionStorage . setItem ( 'role' , codeElementData . role ) ;
153169 sessionStorage . setItem ( 'solver' , codeElementData . solver ) ;
154170 sessionStorage . setItem ( 'allowedComment' , codeElementData . allowedComment ) ;
171+ configureMarkdownParser ( ) ;
155172 addLineSpansToPre ( document . getElementsByTagName ( 'code' ) ) ;
156173 pullComments ( window . fileId , treatComments ) ;
157174} ) ;
0 commit comments