@@ -6,13 +6,11 @@ require("highlightjs-line-numbers.js/dist/highlightjs-line-numbers.min.js");
66const kLoadingMessage = "Loading ..." ;
77
88function removeTags ( str ) {
9- if ( ( str === null ) || ( str === "" ) ) {
9+ if ( str === null || str === "" ) {
1010 return false ;
1111 }
12- // eslint-disable-next-line no-param-reassign
13- str = str . toString ( ) ;
1412
15- return str . replace ( / < \/ ? [ ^ > ] + ( > | $ ) / ig, "" ) ;
13+ return str . toString ( ) . replace ( / ( < ( [ ^ > ] + ) > ) / ig, "" ) ;
1614}
1715
1816export class CodeFetcher {
@@ -96,20 +94,21 @@ export class CodeFetcher {
9694 if ( withoutTags === false ) {
9795 return line ;
9896 }
99- const incriminedCodeSingleLine = code . split ( "\n" ) . slice ( location [ 0 ] [ 0 ] - 1 , location [ 0 ] [ 0 ] ) ;
100- const isMultiLine = location [ 0 ] [ 0 ] < location [ 1 ] [ 0 ] ;
101- const [ [ startLine ] ] = location ;
97+ const [ [ startLine ] , [ endLine , endColumn ] ] = location ;
98+ const isMultiLine = startLine < endLine ;
10299 const lineIndex = startLine >= 10 ? 9 : startLine - 1 ;
103- const isRelevantLine = isMultiLine ?
104- lineIndex <= index && index <= location [ 1 ] [ 0 ] - 1 :
105- // eslint-disable-next-line max-len
106- incriminedCodeSingleLine . includes ( value ) || ( ! isMultiLine && lineIndex === index && withoutTags . includes ( value ) ) || ( ! value && lineIndex === index ) ;
100+ const startFrom = startLine >= 10 ? startLine - 9 : 1 ;
107101
108- if ( isRelevantLine ) {
109- if ( ! isMultiLine && value && line . includes ( value ) ) {
110- return line . replace ( value , `<span class="relevant-line">${ value } </span>` ) ;
111- }
102+ if ( isMultiLine && lineIndex <= index && endLine >= startFrom + index ) {
103+ return `<span class="relevant-line">${ line } </span>` ;
104+ }
105+ else if ( ! isMultiLine && value && line . includes ( value ) ) {
106+ const indexStart = line . indexOf ( value ) ;
112107
108+ // eslint-disable-next-line max-len
109+ return `${ line . slice ( 0 , indexStart ) } <span class="relevant-line">${ line . slice ( indexStart , indexStart + endColumn ) } </span>${ line . slice ( indexStart + endColumn ) } ` ;
110+ }
111+ else if ( ! isMultiLine && startFrom + index === startLine ) {
113112 return `<span class="relevant-line">${ line } </span>` ;
114113 }
115114
0 commit comments