OK, I think I got trapped into some JS's regex voodoo or new security settings.
Anyway this seems to work in Chrome and FF , copy it into your Free Nodelet Settings and after clicking the link all modules after use or require are underlined and have an onclick event to call CPAN in a _blank window.
This is beta-code, no guaranties whatsover! =)
<!-- =================================================================
+=====================
Auto-Linkify Modules in Code Sections
Version 0.31.03
2022-07-23
https://perlmonks.org/?node_id=11145662
-->
<script>
// <!--
function show_module(module) {
let url = 'https://perldoc.perl.org/' + module;
window.open(url,'_blank');
}
function link_modules() {
let codes = document.getElementsByClassName('codetext');
let replacer = function (match, p1, p2, p3) {
return p1 + '<u><span onclick="show_module(\'' + p3 +' \')">'
++ p3 + '</span></u>';
};
for (var i in codes) {
if (!codes.hasOwnProperty(i)) continue;
let text = codes[i];
let inner = text.innerHTML;
inner = inner.replace(/((use|require)\s+)((\w+)(::\w+)*)/g, re
+placer);
// console.log(inner);
text.innerHTML = inner;
}
}
/* Automatic linking */
link_modules(); // comment out if you prefer button only
// -->
</script>
<!-- Explict button in the Free Nodelet ... remove if automatic linkin
+g is enough -->
<button onclick='link_modules()'>link_modules() [id://11145662|v0.31.3
+]</button>
<!-- END Auto-Linkify Modules in Code Sections -----------------------
+------------------ -->
to do
- better identifier parsing then just \w+
-
delay link_CPAN to window.onload or similar for automatic linking
- make target window configurable
- hide functions in own namespace / object
- make it easily importable like the wikisyntax hack
-
detect core modules and link to perldoc instead(?) °,²
- exclude embedded package names (?)
changes
- updated to v0.3, transformation happens now automatically
- ²) 2022-07-23 v0.31 https://perldoc.perl.org/MODUL is already redirecting to MetaCPAN so no need to check corelist
updates
- °) here the output from corelist for v5.32.0