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 @@ -5750,6 +5750,7 @@ '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 @@ '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 --- a/src/infrastructure/markup/PhabricatorMarkupEngine.php +++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php @@ -526,7 +526,7 @@ $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 --- /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 --- a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php +++ b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php @@ -91,6 +91,7 @@ $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 --- /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}