bug 6977 fixed: ATOMS GUI: In the presentation frame, URLs and emails were not hyperl...
[scilab.git] / scilab / modules / atoms / macros / atoms_gui / cbAtomsGui.sci
index 322ff6a..f916cf8 100644 (file)
@@ -262,6 +262,9 @@ function updateDescFrame()
                "</body>" + ..
                "</html>";
 
+    // Process URLs and Emails
+    htmlcode = processHTMLLinks(htmlcode);
+
     // Update the main description
     set(Desc,"String",htmlcode);
 
@@ -425,3 +428,51 @@ function showWarning(msg)
     set(msgText,"String",str);
 
 endfunction
+
+// =============================================================================
+// processHTMLLinks
+// + Find URLs and emails
+// + Convert them in HTML
+// =============================================================================
+
+function txtout = processHTMLLinks(txtin)
+
+    regexUrl   = "/((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\:\/\/)(www|[a-zA-Z0-9])[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(\/($|[a-zA-Z0-9\.\,\;\?\''\\\+&amp;%\$#\=~_\-\/]+))*/";
+    regexEmail = "/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/";
+    txtout     = "";
+
+    // Process URLs
+
+    [mat_start,mat_end,mat_match] = regexp(txtin,regexUrl);
+
+    if ~isempty(mat_match) then
+        mat_end = [ 0 mat_end ];
+        for i=1:size(mat_match,"*")
+            txtout = txtout + part(txtin,[mat_end(i)+1:mat_start(i)-1]) ..
+                            + "<a href="""+mat_match(i)+""" target=""_blank"">" ..
+                            + mat_match(i) ..
+                            + "</a>";
+        end
+        txtout = txtout + part(txtin,mat_end(size(mat_end,"*"))+1:length(txtin));
+        txtin  = txtout;
+        txtout = "";
+    end
+
+    // Process Emails
+
+    [mat_start,mat_end,mat_match] = regexp(txtin,regexEmail);
+
+    if ~isempty(mat_match) then
+        mat_end = [ 0 mat_end ];
+        for i=1:size(mat_match,"*")
+            txtout = txtout + part(txtin,[mat_end(i)+1:mat_start(i)-1]) ..
+                            + "<a href=""mailto:"+mat_match(i)+""" target=""_blank"">" ..
+                            + mat_match(i) ..
+                            + "</a>";
+        end
+        txtout = txtout + part(txtin,mat_end(size(mat_end,"*"))+1:length(txtin));
+    else
+        txtout = txtin;
+    end
+
+endfunction