Page MenuHomePhabricator

D14384.id34747.diff
No OneTemporary

D14384.id34747.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
@@ -295,6 +295,7 @@
'PhutilRemarkupEngineTestCase' => 'markup/engine/__tests__/PhutilRemarkupEngineTestCase.php',
'PhutilRemarkupEscapeRemarkupRule' => 'markup/engine/remarkup/markuprule/PhutilRemarkupEscapeRemarkupRule.php',
'PhutilRemarkupHeaderBlockRule' => 'markup/engine/remarkup/blockrule/PhutilRemarkupHeaderBlockRule.php',
+ 'PhutilRemarkupHighlightRule' => 'markup/engine/remarkup/markuprule/PhutilRemarkupHighlightRule.php',
'PhutilRemarkupHorizontalRuleBlockRule' => 'markup/engine/remarkup/blockrule/PhutilRemarkupHorizontalRuleBlockRule.php',
'PhutilRemarkupHyperlinkRule' => 'markup/engine/remarkup/markuprule/PhutilRemarkupHyperlinkRule.php',
'PhutilRemarkupInlineBlockRule' => 'markup/engine/remarkup/blockrule/PhutilRemarkupInlineBlockRule.php',
@@ -815,6 +816,7 @@
'PhutilRemarkupEngineTestCase' => 'PhutilTestCase',
'PhutilRemarkupEscapeRemarkupRule' => 'PhutilRemarkupRule',
'PhutilRemarkupHeaderBlockRule' => 'PhutilRemarkupBlockRule',
+ 'PhutilRemarkupHighlightRule' => 'PhutilRemarkupRule',
'PhutilRemarkupHorizontalRuleBlockRule' => 'PhutilRemarkupBlockRule',
'PhutilRemarkupHyperlinkRule' => 'PhutilRemarkupRule',
'PhutilRemarkupInlineBlockRule' => 'PhutilRemarkupBlockRule',
diff --git a/src/markup/engine/__tests__/remarkup/highlight.txt b/src/markup/engine/__tests__/remarkup/highlight.txt
new file mode 100644
--- /dev/null
+++ b/src/markup/engine/__tests__/remarkup/highlight.txt
@@ -0,0 +1,8 @@
+how about we !!highlight!! some !!text!!!
+~~~~~~~~~~
+<p>how about we
+<span class="remarkup-highlight">highlight</span>
+some
+<span class="remarkup-highlight">text</span>!</p>
+~~~~~~~~~~
+how about we !!highlight!! some !!text!!!
diff --git a/src/markup/engine/remarkup/markuprule/PhutilRemarkupHighlightRule.php b/src/markup/engine/remarkup/markuprule/PhutilRemarkupHighlightRule.php
new file mode 100644
--- /dev/null
+++ b/src/markup/engine/remarkup/markuprule/PhutilRemarkupHighlightRule.php
@@ -0,0 +1,24 @@
+<?php
+
+final class PhutilRemarkupHighlightRule extends PhutilRemarkupRule {
+
+ public function getPriority() {
+ return 1000.0;
+ }
+
+ public function apply($text) {
+ if ($this->getEngine()->isTextMode()) {
+ return $text;
+ }
+
+ return $this->replaceHTML(
+ '@\\!\\!(.+?)\\!\\!@s',
+ array($this, 'applyCallback'),
+ $text);
+ }
+
+ protected function applyCallback(array $matches) {
+ return hsprintf('<span class="remarkup-highlight">%s</span>', $matches[1]);
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 22, 1:02 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7715809
Default Alt Text
D14384.id34747.diff (2 KB)

Event Timeline