Browse Source

handle more autolinks

In particular a relative link to "Material" or a link to "Material.property"
will get translated into a link to the docs.
Gregg Tavares 7 years ago
parent
commit
b9d095049e
1 changed files with 18 additions and 0 deletions
  1. 18 0
      threejs/lessons/resources/lesson.js

+ 18 - 0
threejs/lessons/resources/lesson.js

@@ -276,6 +276,24 @@ $(document).ready(function($){
     return a;
   });
 
+  const methodPropertyRE = /^(\w+).(\w+)$/;
+  const classRE = /^(\w+)$/;
+  $('a').each(function() {
+    const href = this.getAttribute('href');
+    const m = methodPropertyRE.exec(href);
+    if (m) {
+      const codeKeywordLink = codeKeywordLinks[m[1]];
+      if (codeKeywordLink) {
+        this.setAttribute('href', `${codeKeywordLink}#${m[2]}`);
+      }
+    } else if (classRE.test(href)) {
+      const codeKeywordLink = codeKeywordLinks[href];
+      if (codeKeywordLink) {
+        this.setAttribute('href', codeKeywordLink);
+      }
+    }
+  });
+
   const linkImgs = function(bigHref) {
     return function() {
       const a = document.createElement('a');