summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbscan <10503608+bscan@users.noreply.github.com>2023-10-22 21:02:21 -0400
committerbscan <10503608+bscan@users.noreply.github.com>2023-10-22 21:02:21 -0400
commit75ef9bc0f82ae82a06247f8503bf9893e3a8bd87 (patch)
tree25774f4e2d9d4c344674231b7c1f42a57b446321
parentdf5093cee8e250056aec549c96787e6ea8af8226 (diff)
downloadPerlNavigator-75ef9bc0f82ae82a06247f8503bf9893e3a8bd87.zip
POD: Better handling of backticks
-rw-r--r--server/src/pod.ts13
1 files changed, 11 insertions, 2 deletions
diff --git a/server/src/pod.ts b/server/src/pod.ts
index 0e67d94..02ad259 100644
--- a/server/src/pod.ts
+++ b/server/src/pod.ts
@@ -319,8 +319,13 @@ const processFormatSpecificBlock = (line: string): string => {
return markdown;
};
+// Mapping backticks to the Unicode non-character U+FFFF which is not allowed to appear in text
+const tempPlaceholder = '\uFFFF';
+
const processInlineElements = (line: string): string => {
+ line = line.replace(/`/g, tempPlaceholder);
+
// Handle code (C<code>), while allowing E<> replacements
line = line.replace(/C<((?:[^<>]|[EL]<[^<>]+>)+?)>/g, (match, code) => escapeBackticks(code));
@@ -331,6 +336,9 @@ const processInlineElements = (line: string): string => {
// Handle special characters (E<entity>)
line = line.replace(/E<([^>]+)>/g, (match, entity) => convertE(entity));
+ // Mapping the Unicode non-character U+FFFF back to escaped backticks
+ line = line.replace(new RegExp(tempPlaceholder, 'g'), '\\`');
+
// Handle bold (B<bold>)
line = line.replace(/B<([^>]+)>/g, "**$1**");
@@ -398,13 +406,14 @@ const escapeHTML = (str: string): string => {
};
const escapeBackticks = (str: string): string => {
- let count = (str.match(/`/g) || []).length;
+ let count = (str.match(new RegExp(tempPlaceholder, 'g')) || []).length;
+ str = str.replace(new RegExp(tempPlaceholder, 'g'), '`'); // Backticks inside don't need to be escaped.
let delimiters = "`".repeat(count + 1);
return `${delimiters}${str}${delimiters}`;
};
const convertE = (content: string): string => {
-
+
switch (content) {
case "lt":
return "<";