improve regex

Sun, 19 Jul 2020 11:17:28 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 19 Jul 2020 11:17:28 -0500
changeset 33
55d738116fac
parent 32
cef0a28afae0
child 34
4c7122a505d4

improve regex

markdown_it.js file | annotate | diff | comparison | revisions
--- a/markdown_it.js	Sun Jul 19 11:12:54 2020 -0500
+++ b/markdown_it.js	Sun Jul 19 11:17:28 2020 -0500
@@ -39,7 +39,8 @@
 
     try{
         // Replace local links to .md by .html.
-        var md_to_html=/^((?![a-zA-Z0-9]*:\/\/).*)\.md$/;
+        var re_nonlocal=/^[a-zA-Z0-9]*:\/\//;
+        var re_md_to_html=/^(.*)\.md$/;
         var md = require('markdown-it')({
                 html: true,
                 xhtmlOut: true,
@@ -54,7 +55,11 @@
                     return '';
                 },
                 replaceLink: function (link, env) {
-                    return link.replace(md_to_html, "$1.html")
+                    if(link.match(re_nonlocal)){
+                        return link;
+                    }else{
+                        return link.replace(re_md_to_html, "$1.html");
+                    }
                 }
             })
         var mk = require('@neilsustc/markdown-it-katex');

mercurial