Page MenuHomePhorge

D25540.1737345078.diff
No OneTemporary

D25540.1737345078.diff

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/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,37 @@
+<?php
+
+final class PhutilRemarkupHexColorCodeRule
+ extends PhabricatorRemarkupCustomInlineRule {
+
+ public function getPriority() {
+ return 1000.0;
+ }
+
+ public function apply($text) {
+ if ($this->getEngine()->isTextMode()) {
+ return $text;
+ }
+ return preg_replace_callback(
+ '@\B{(#[0-9a-fA-F]{6,})}\B@',
+ array($this, 'markupHexColorCodedText'),
+ $text);
+ }
+
+ protected function markupHexColorCodedText(array $matches) {
+ if ($this->getEngine()->isTextMode()) {
+ $result = $matches[1];
+ } else {
+ $match = $matches[1];
+ $result = phutil_tag(
+ 'tt',
+ array(
+ 'class' => 'remarkup-monospaced',
+ 'style' => "background-color: $match;",
+ ),
+ $match);
+ }
+
+ return $this->getEngine()->storeText($result);
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Jan 20 2025, 03:51 (4 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1135613
Default Alt Text
D25540.1737345078.diff (2 KB)

Event Timeline