I just wanted to hack a free nodelet hack (sic) on the fly, which automatically links any used or required module in code-sections to CPAN.
But I don't know what I'm doing wrong, can't make it work yet.
Not sure if it's a JS problem or related to Chrome and security issues (couldn't test in FF yet).
Before scratching all the efforts, I thought it might be reasonable to ask for help.
paste this into the JS Console
function linkCPAN() { let codes = document.getElementsByClassName('codetext'); // let pattern = '$1<href="http://search.cpan.org/perldoc?$3">$3</ +a>'; let replacer = function (match, p1, p2, p3) { return p1 + '<href="http://search.cpan.org/perldoc?' + p3 + '" +>' + p3 + '</a>'; }; 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; } }
and call linkCPAN()
you should see the properly replaced HTML in the console, but nothing happens in the window.
here some input for testing
use strict; use Data::Dump;
Any ideas?
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
fixed JS has no hashes but objects bug with if (!codes.hasOwnProperty(i)) continue;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Nodelet Hack to auto-linkify modules in code sections (works)
by LanX (Saint) on Jul 22, 2022 at 18:31 UTC |