diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d22dc78970..17b1e837a6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -5750,6 +5750,7 @@ phutil_register_library_map(array( 'PhutilRemarkupEscapeRemarkupRule' => 'infrastructure/markup/markuprule/PhutilRemarkupEscapeRemarkupRule.php', 'PhutilRemarkupEvalRule' => 'infrastructure/markup/markuprule/PhutilRemarkupEvalRule.php', 'PhutilRemarkupHeaderBlockRule' => 'infrastructure/markup/blockrule/PhutilRemarkupHeaderBlockRule.php', + 'PhutilRemarkupHexColorCodeRule' => 'infrastructure/markup/markuprule/PhutilRemarkupHexColorCodeRule.php', 'PhutilRemarkupHighlightRule' => 'infrastructure/markup/markuprule/PhutilRemarkupHighlightRule.php', 'PhutilRemarkupHorizontalRuleBlockRule' => 'infrastructure/markup/blockrule/PhutilRemarkupHorizontalRuleBlockRule.php', 'PhutilRemarkupHyperlinkEngineExtension' => 'infrastructure/markup/markuprule/PhutilRemarkupHyperlinkEngineExtension.php', @@ -12637,6 +12638,7 @@ phutil_register_library_map(array( 'PhutilRemarkupEscapeRemarkupRule' => 'PhutilRemarkupRule', 'PhutilRemarkupEvalRule' => 'PhutilRemarkupRule', 'PhutilRemarkupHeaderBlockRule' => 'PhutilRemarkupBlockRule', + 'PhutilRemarkupHexColorCodeRule' => 'PhabricatorRemarkupCustomInlineRule', 'PhutilRemarkupHighlightRule' => 'PhutilRemarkupRule', 'PhutilRemarkupHorizontalRuleBlockRule' => 'PhutilRemarkupBlockRule', 'PhutilRemarkupHyperlinkEngineExtension' => 'Phobject', diff --git a/src/infrastructure/markup/PhabricatorMarkupEngine.php b/src/infrastructure/markup/PhabricatorMarkupEngine.php index cedd0398e3..84503048d0 100644 --- a/src/infrastructure/markup/PhabricatorMarkupEngine.php +++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php @@ -526,7 +526,7 @@ final class PhabricatorMarkupEngine extends Phobject { $rules[] = new PhutilRemarkupEscapeRemarkupRule(); $rules[] = new PhutilRemarkupEvalRule(); $rules[] = new PhutilRemarkupMonospaceRule(); - + $rules[] = new PhutilRemarkupHexColorCodeRule(); $rules[] = new PhutilRemarkupDocumentLinkRule(); $rules[] = new PhabricatorNavigationRemarkupRule(); diff --git a/src/infrastructure/markup/markuprule/PhutilRemarkupHexColorCodeRule.php b/src/infrastructure/markup/markuprule/PhutilRemarkupHexColorCodeRule.php new file mode 100644 index 0000000000..4c5a048e13 --- /dev/null +++ b/src/infrastructure/markup/markuprule/PhutilRemarkupHexColorCodeRule.php @@ -0,0 +1,57 @@ +getEngine()->isTextMode()) { + $result = $matches[1]; + } else { + if (count($matches) < 2) { + return $matches[0]; + } else { + $len = strlen($matches[1]); + if (7 !== $len && 4 !== $len) { + return $matches[0]; + } + } + $match = $matches[1]; + $fg = $this->contrastingColor($match); + $result = phutil_tag( + 'tt', + array( + 'class' => 'remarkup-monospaced', + 'style' => "color: {$fg}; background-color: {$match};", + ), + $match); + } + + return $this->getEngine()->storeText($result); + } + +} diff --git a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php index 38831d034a..2f1ac692b9 100644 --- a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php +++ b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php @@ -91,6 +91,7 @@ final class PhutilRemarkupEngineTestCase extends PhutilTestCase { $rules = array(); $rules[] = new PhutilRemarkupEscapeRemarkupRule(); $rules[] = new PhutilRemarkupMonospaceRule(); + $rules[] = new PhutilRemarkupHexColorCodeRule(); $rules[] = new PhutilRemarkupDocumentLinkRule(); $rules[] = new PhutilRemarkupHyperlinkRule(); $rules[] = new PhutilRemarkupBoldRule(); diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/hex-color-code.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/hex-color-code.txt new file mode 100644 index 0000000000..108ce33870 --- /dev/null +++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/hex-color-code.txt @@ -0,0 +1,5 @@ +some red, grey and white for you: {#ff0000} {#999999} {#ffffff} Also green: {#0F0} but not this: {#0000000} or this: {#0000} +~~~~~~~~~~ +
some red, grey and white for you: #ff0000 #999999 #ffffff Also green: #0F0 but not this: {#0000000} or this: {#0000}
+~~~~~~~~~~ +some red, grey and white for you: #ff0000 #999999 #ffffff Also green: #0F0 but not this: {#0000000} or this: {#0000}