Tristan Yu commited on
Commit
b2e992a
·
1 Parent(s): fa00d98

Week 6: allow links in brief and source text (Markdown [label](url) and plain URLs); no other changes

Browse files
Files changed (1) hide show
  1. client/src/pages/TutorialTasks.tsx +4 -0
client/src/pages/TutorialTasks.tsx CHANGED
@@ -116,6 +116,10 @@ const TutorialTasks: React.FC = () => {
116
  const renderFormatted = (text: string) => {
117
  const escape = (s: string) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
118
  const html = escape(text)
 
 
 
 
119
  .replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
120
  .replace(/\*(.+?)\*/g, '<em>$1</em>')
121
  .replace(/\n/g, '<br/>');
 
116
  const renderFormatted = (text: string) => {
117
  const escape = (s: string) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
118
  const html = escape(text)
119
+ // Markdown-style links: [label](https://example.com)
120
+ .replace(/\[([^\]]+?)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>')
121
+ // Plain URLs: https://example.com
122
+ .replace(/(https?:\/\/[^\s<]+[^\s<\.)])/g, '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>')
123
  .replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
124
  .replace(/\*(.+?)\*/g, '<em>$1</em>')
125
  .replace(/\n/g, '<br/>');