From 171fba320f8b8e4a3fea1e548d6ad9538b406e54 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 24 Feb 2023 14:26:05 -0500
Subject: [PATCH] wikiheaders: Fix wikilinks inside code sections a little. Not
perfect yet.
(cherry picked from commit 5b0351a672701e28c3bfb17d44a458b82e8a4175)
---
build-scripts/wikiheaders.pl | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index bb6dfa198a98..31cac704af19 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -260,9 +260,11 @@ sub wikify_chunk {
$str .= "<syntaxhighlight lang='$codelang'>$code<\/syntaxhighlight>";
}
} elsif ($wikitype eq 'md') {
- # Convert obvious API things to wikilinks.
+ # Convert obvious API things to wikilinks. You can't make links
+ # inside code blocks, but you _can_ make sure that single identifiers
+ # wrapped in backticks encode correctly.
if (defined $apiprefixregex) {
- $str =~ s/\b($apiprefixregex[a-zA-Z0-9_]+)/[$1]($1)/gms;
+ $str =~ s/(?<LEFT>\b|\`?)(?<SYM>$apiprefixregex[a-zA-Z0-9_]+)(?<RIGHT>\`?)/[$+{"LEFT"}$+{"SYM"}$+{"RIGHT"}]($+{"SYM"})/gms;
}
if (defined $code) {
$str .= "```$codelang$code```";
@@ -333,7 +335,7 @@ sub dewikify_chunk {
} elsif ($wikitype eq 'md') {
# Dump obvious wikilinks. The rest can just passthrough.
if (defined $apiprefixregex) {
- $str =~ s/\[($apiprefixregex[a-zA-Z0-9_]+)\]\(($apiprefixregex[a-zA-Z0-9_]+)\)/$1/gms;
+ $str =~ s/\[(?<LEFT>\`?)(?<SYM>$apiprefixregex[a-zA-Z0-9_]+)(?<RIGHT>\`?)\]\(($apiprefixregex[a-zA-Z0-9_]+)\)/$+{"LEFT"}$+{"SYM"}$+{"RIGHT"}/gms;
}
}
@@ -368,7 +370,7 @@ sub dewikify_chunk {
} elsif ($wikitype eq 'md') {
# Dump obvious wikilinks.
if (defined $apiprefixregex) {
- $str =~ s/\[($apiprefixregex[a-zA-Z0-9_]+)\]\(($apiprefixregex[a-zA-Z0-9_]+)\)/\n.BR $1\n/gms;
+ $str =~ s/\[(?<LEFT>\`?)(?<SYM>$apiprefixregex[a-zA-Z0-9_]+)(?<RIGHT>\`?)\]\(($apiprefixregex[a-zA-Z0-9_]+)\)/\n.BR $+{"SYM"}\n/gms;
}
# links