|
| 1 | +// get current page URL |
| 2 | +url = table.baseURI; |
| 3 | +// make root URL, i.e. only up to CMSSW_* |
| 4 | +var pattern = /CMSSW_[0-9]_[0-9]_[0-9]_[A-Za-z0-9]*/; |
| 5 | +cmssw = pattern.exec(url)[0]; // gives us the CMSSW name |
| 6 | +rootURL = url.substr(0, url.search(pattern)+cmssw.length+1); |
| 7 | +// console.log("URL: " + rootURL); |
| 8 | + |
| 9 | +// pattern to do #include matching |
| 10 | +cpp_pattern = /#include/; |
| 11 | +cpp_header_pattern = /[<\"].*[>\"]/; |
| 12 | + |
| 13 | +// the lines of code are stored in a table |
| 14 | +table = document.getElementsByClassName("js-file-line-container")[0]; |
| 15 | + |
| 16 | +// loop through all rows <tr> |
| 17 | +var rows = document.getElementsByTagName("tr"); |
| 18 | +for (var i = 0; i < rows.length; i++) { |
| 19 | + for (var j = 0; j < rows[i].childNodes.length; j++) { |
| 20 | + |
| 21 | + // check it's a line of the file, not anything else |
| 22 | + var file_line_pattern = /js-file-line/; |
| 23 | + var cell = rows[i].childNodes[j]; |
| 24 | + if (file_line_pattern.test(cell.className)) { |
| 25 | + var line = cell.textContent; |
| 26 | + |
| 27 | + // check line has a C++ #include, if so pull the header path |
| 28 | + // TODO: check it's not a STL include, like iostream |
| 29 | + if (cpp_pattern.test(line)) { |
| 30 | + var path = cpp_header_pattern.exec(line)[0]; |
| 31 | + path = path.replace(/[<>\"]/g,""); //g inmportant - global so replaces all instances |
| 32 | + var link = rootURL.concat(path); |
| 33 | + |
| 34 | + // let's replace the text with a link |
| 35 | + // TODO keep same styling as before |
| 36 | + for (var k = 0; k < cell.childNodes.length; k++) { |
| 37 | + if (cell.childNodes[k].textContent.indexOf(path) != -1) { |
| 38 | + var cell_html = cell.childNodes[k].innerHTML; |
| 39 | + cell.childNodes[k].innerHTML = cell_html.replace(path, "<a href=\""+link+"\">"+path+"</a>"); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + // TODO test for python |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments