Improve lexicon.php to handle internal links (#3110)

This commit is contained in:
Al Winfy authored and Vincent Lee committed 2020-01-06 21:58:26 -06:00
1 parent 72a985c8c9
commit 02367bfa08
2 files changed
+27 -9

No files matched your search

@@ -2931,7 +2931,7 @@
"botania.entry.bIntro": "An Introduction to Trinkets",
"botania.tagline.bIntro": "Accessories that provide power",
"botania.page.bIntro0": "$(thing)Trinkets$(0) (also known as $(thing)Curios$(0), $(thing)Baubles$(0), or $(thing)Charms$(0)) are accessories that offer all sorts of different effects when worn.$(p)To equip them, press [$(k:curios.open.desc)$(0)].",
"botania.page.bIntro0": "$(thing)Trinkets$(0) (also known as $(thing)Curios$(0), $(thing)Baubles$(0), or $(thing)Charms$(0)) are accessories that offer all sorts of different effects when worn.$(p)To equip them, press [$(k:curios.open.desc)].",
"botania.page.bIntro1": "The $(thing)Curios Screen$(0)",
"botania.page.bIntro2": "Do note that if any other mod uses the $(thing)Curios$(0) system, equipment slots must be shared with that mod's $(thing)Trinkets$(0) as well.",
@@ -3095,7 +3095,7 @@
"botania.entry.dodgeRing": "Ring of Dexterous Motion",
"botania.tagline.dodgeRing": "Sweep to the side to dodge attacks",
"botania.page.dodgeRing0": "The $(item)Ring of Dexterous Motion$(0) is a handy $(thing)Trinket$(0) for dodging damage during duels. Its wearer can double-tap $(k:left) or $(k:right) to hurl themselves to the side and dodge incoming attacks/mobs.$(p)Dodging has a short cooldown, and burns some of its user's hunger.",
"botania.page.dodgeRing0": "The $(item)Ring of Dexterous Motion$(0) is a handy $(thing)Trinket$(0) for dodging damage during duels. Its wearer can double-tap [$(k:left)] or [$(k:right)] to hurl themselves to the side and dodge incoming attacks/mobs.$(p)Dodging has a short cooldown, and burns some of its user's hunger.",
"botania.page.dodgeRing1": "Dexterity bonus",
"botania.entry.invisibilityCloak": "Invisibility Cloak",
+25 -7
View File
@@ -21,14 +21,14 @@
'right' => 'w',
'sprint' => 'CTRL'
];
$replacements = array_merge(array_combine(array_map("quote_keys", array_keys($default_keys)), array_values($default_keys)), [
$entry_cache = array();
$replacements = [
'/\$\((br|p)\)/' => "<br />",
'/\$\(li\)/' => " &bull; ",
'/\$\(([0-9a-o])\)([^$]+)(?:\$\([0r]?\)|(?=<)|$)/' => "<span class='mc-color-$1'>$2</span>",
'/\$\(([1-9a-o])\)([^$]+)(?:\$\([0r]?\)|(?=<)|$)/' => "<span class='mc-color-$1'>$2</span>",
'/\$\(thing\)([^$]+)(?:\$\([0r]?\)|(?=<)|$)/' => "<span class='mc-color-4'>$1</span>",
'/\$\(item\)([^$]+)(?:\$\([0r]?\)|(?=<)|$)/' => "<span class='mc-color-1'>$1</span>",
'/\$\(l:([^)]+)\)([^$]+)\$\(\/l\)/' => "<a href='$1'>$2</a>"
]);
];
$opened_div = false;
@@ -45,7 +45,11 @@
$opened_div = true;
}
if(sizeof($page_match) > 0) {
$page = preg_replace(array_keys($replacements), array_values($replacements), $value) . '<br />';
$page = preg_replace_callback('/\$\(k:([^)]*)\)/', 'key_resolve',
preg_replace_callback('/\$\(l:([^)]+)\)([^$]+)\$\(\/l\)/', 'link_resolve',
preg_replace(array_keys($replacements), array_values($replacements),
$value))) . '<br />';
$no_control = preg_replace('/\$\(.\)/', '', $value);
if(strlen($no_control) > 50) {
echo($page);
@@ -69,7 +73,21 @@
function match_page($key, $entry_name) {
return match("botania\.page\.$entry_name\d+", $key);
}
function quote_keys($key) {
return "/\\$\\(k:$key\\)/";
function key_resolve($match) {
global $default_keys; // i'm sorry, i don't know php
return (array_key_exists($match[1], $default_keys)
? $default_keys[$match[1]]
: "UNKNOWN KEY");
}
function link_resolve($match) {
$link = $match[1];
$res = [];
if(preg_match('|^\w+/(\w+)$|', $link, $res)) {
$entry_name = preg_replace_callback('/_(\w)/', function($repl) {
return strtoupper($repl[1]);
}, $res[1]);
$link = "#$entry_name-fake";
}
return "<a href='$link'>$match[2]</a>";
}
?>