diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -5770,6 +5770,7 @@ 'PhutilRemarkupEngine' => 'infrastructure/markup/remarkup/PhutilRemarkupEngine.php', 'PhutilRemarkupEngineTestCase' => 'infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php', 'PhutilRemarkupEscapeRemarkupRule' => 'infrastructure/markup/markuprule/PhutilRemarkupEscapeRemarkupRule.php', + 'PhutilRemarkupEvalRule' => 'infrastructure/markup/markuprule/PhutilRemarkupEvalRule.php', 'PhutilRemarkupHeaderBlockRule' => 'infrastructure/markup/blockrule/PhutilRemarkupHeaderBlockRule.php', 'PhutilRemarkupHighlightRule' => 'infrastructure/markup/markuprule/PhutilRemarkupHighlightRule.php', 'PhutilRemarkupHorizontalRuleBlockRule' => 'infrastructure/markup/blockrule/PhutilRemarkupHorizontalRuleBlockRule.php', @@ -12770,6 +12771,7 @@ 'PhutilRemarkupEngine' => 'PhutilMarkupEngine', 'PhutilRemarkupEngineTestCase' => 'PhutilTestCase', 'PhutilRemarkupEscapeRemarkupRule' => 'PhutilRemarkupRule', + 'PhutilRemarkupEvalRule' => 'PhutilRemarkupRule', 'PhutilRemarkupHeaderBlockRule' => 'PhutilRemarkupBlockRule', 'PhutilRemarkupHighlightRule' => 'PhutilRemarkupRule', 'PhutilRemarkupHorizontalRuleBlockRule' => 'PhutilRemarkupBlockRule', diff --git a/src/infrastructure/markup/PhabricatorMarkupEngine.php b/src/infrastructure/markup/PhabricatorMarkupEngine.php --- a/src/infrastructure/markup/PhabricatorMarkupEngine.php +++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php @@ -504,6 +504,7 @@ $rules = array(); $rules[] = new PhutilRemarkupEscapeRemarkupRule(); + $rules[] = new PhutilRemarkupEvalRule(); $rules[] = new PhutilRemarkupMonospaceRule(); diff --git a/src/infrastructure/markup/markuprule/PhutilRemarkupEvalRule.php b/src/infrastructure/markup/markuprule/PhutilRemarkupEvalRule.php new file mode 100644 --- /dev/null +++ b/src/infrastructure/markup/markuprule/PhutilRemarkupEvalRule.php @@ -0,0 +1,97 @@ +isFlatText($expression)) { + return $matches[0]; + } + + $engine = $this->getEngine(); + $token = $engine->storeText($expression); + + $list_key = self::KEY_EVAL; + $expression_list = $engine->getTextMetadata($list_key, array()); + + $expression_list[] = array( + 'token' => $token, + 'expression' => $expression, + ); + + $engine->setTextMetadata($list_key, $expression_list); + + return $token; + } + + public function didMarkupText() { + $engine = $this->getEngine(); + + $list_key = self::KEY_EVAL; + $expression_list = $engine->getTextMetadata($list_key, array()); + + foreach ($expression_list as $expression_item) { + $token = $expression_item['token']; + $expression = $expression_item['expression']; + + $result = $this->evaluateExpression($expression); + + $engine->overwriteStoredText($token, $result); + } + } + + private function evaluateExpression($expression) { + static $string_map; + + if ($string_map === null) { + $string_map = array( + 'strings' => array( + 'platform' => array( + 'server' => array( + 'name' => pht('Phabricator'), + 'path' => pht('phabricator/'), + ), + 'client' => array( + 'name' => pht('Arcanist'), + 'path' => pht('arcanist/'), + ), + ), + ), + ); + } + + $parts = explode('.', $expression); + + $cursor = $string_map; + foreach ($parts as $part) { + if (isset($cursor[$part])) { + $cursor = $cursor[$part]; + } else { + break; + } + } + + if (is_string($cursor)) { + return $cursor; + } + + return pht( + '', + $expression); + } + +}