The parselinks code is four lines of Perl responsible for turning all your [bracketed text] text into hardlinks. It works well, but a little too well, because there's no way to add brackets to your writeup without knowing their HTML escape codes ( [ and ] ).
However, this is a problem for edevdocs and (probably) superdocs that use JavaScript code. Normal writeups have JavaScript code automatically parsed out, so it's not a problem there, and the HTML escape codes (while inconvenient) can be used there.
However, JavaScript uses brackets to specify array elements and, if needed, for describing a regular expression. parselinks interprets these brackets as hardlinks and screws up the JavaScript code utterly. Because this is script, and not HTML text, the HTML escape codes can't be used.
My suggestion would be to modify parselinks to search for an "escaped bracket" and remove it, add hardlinks as usual, then replace the removed "escaped bracket" with a single bracket. The best way to "escape" a bracket would be either using a double-bracket ( [[ ) or a slash-bracket ( \[ ). Since a slash-bracket may be used as a normal part of a regular expression, but a double-bracket shouldn't, I would use a double-bracket.
The new code for parselinks would look like this:
my ($field) = @_;
my $text = $$NODE{$field};
$test =~ s/\[{2}/\&\#91\;/gs; # replace double brackets with HTML escapes
$test =~ s/\]{2}/\&\#93\;/gs;
$text =~ s/\[(.*?)\]/linkNodeTitle ($1, $NODE)/egs;
$test =~ s/\&\#91\;/\[/gs; # replace HTML escapes with single brackets
$test =~ s/\&\#93\;/\]/gs;
unMSify($text); #take out microsoft chars
This has the side-effect of turning any [ and ] entered in the writeup into [ and ] , but since it's displayed the same in a browser, and since the writeup itself is unchanged in the database, this shouldn't matter.
The following test string produced the desired results in using these regular expressions in JavaScript:
[start][start2] [3] [[double]] [[re]][[peat]]
[in[[side] [also]]inside] [ [[] []]] [end]
Which should output like this:
startstart2 3 [double] [re][peat]
in[side also]inside [ ] end
Footnote: I originally tried a solution very similar to JK's below. However, it failed to trap zero-character hardlinks, one-character hardlinks, and unusual combinations of three or more [s or ]s, not to mention hardlinks at the beginning or end of the string. Hence the above solution.