(line: string)
| 28 | }; |
| 29 | |
| 30 | const processLine = (line: string) => { |
| 31 | const elements = []; |
| 32 | let lastIndex = 0; |
| 33 | let match; |
| 34 | |
| 35 | while ((match = timeCodeRegex.exec(line)) !== null) { |
| 36 | if (match.index > lastIndex) { |
| 37 | elements.push( |
| 38 | <span key={`text-${lastIndex}`}> |
| 39 | {line.substring(lastIndex, match.index)} |
| 40 | </span>, |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | const timeInSeconds = convertToSeconds(match[0]); |
| 45 | elements.push( |
| 46 | <Link |
| 47 | key={`timecode-${match.index}`} |
| 48 | className="text-blue-500 hover:underline" |
| 49 | href={getUpdatedUrl( |
| 50 | `/courses/${contentId}/${possiblePath}`, |
| 51 | searchParams, |
| 52 | { |
| 53 | timestamp: timeInSeconds, |
| 54 | }, |
| 55 | )} |
| 56 | > |
| 57 | {match[0]} |
| 58 | </Link>, |
| 59 | ); |
| 60 | |
| 61 | lastIndex = match.index + match[0].length; |
| 62 | } |
| 63 | |
| 64 | while ((match = urlRegex.exec(line)) !== null) { |
| 65 | if (match.index > lastIndex) { |
| 66 | elements.push( |
| 67 | <span key={`text-${lastIndex}`}> |
| 68 | {line.substring(lastIndex, match.index)} |
| 69 | </span>, |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | elements.push( |
| 74 | <Link |
| 75 | key={`url-${match.index}`} |
| 76 | href={match[0]} |
| 77 | target="_blank" |
| 78 | rel="noopener noreferrer" |
| 79 | className="text-blue-500 hover:underline" |
| 80 | > |
| 81 | {match[0]} |
| 82 | </Link>, |
| 83 | ); |
| 84 | |
| 85 | lastIndex = match.index + match[0].length; |
| 86 | } |
| 87 |
no test coverage detected