Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F35400949
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
5 KB
Subscribers
None
View Options
diff --git a/src/markup/engine/__tests__/remarkup/interpreter-test.txt b/src/markup/engine/__tests__/remarkup/interpreter-test.txt
index b1c3002..7ba1fe7 100644
--- a/src/markup/engine/__tests__/remarkup/interpreter-test.txt
+++ b/src/markup/engine/__tests__/remarkup/interpreter-test.txt
@@ -1,46 +1,46 @@
phutil_test_block_interpreter (foo=bar) {{{
content
}}}
-
+
phutil_test_block_interpreter {{{ content
content }}}
phutil_test_block_interpreter {{{ content }}}
phutil_fake_test_block_interpreter {{{ content }}}
~~~~~~~~~~
-Content: content
-Argv: foo=bar
+Content: (content)
+Argv: (foo=bar)
-Content: content
-content
-Argv:
+Content: ( content
+content )
+Argv: ()
-Content: content
-Argv:
+Content: ( content )
+Argv: ()
-<div style="color: red;">No interpreter found: phutil_fake_test_block_interpreter</div>
+<div class="remarkup-interpreter-error">No interpreter found: phutil_fake_test_block_interpreter</div>
~~~~~~~~~~
-Content: content
-Argv: foo=bar
+Content: (content)
+Argv: (foo=bar)
-Content: content
-content
-Argv:
+Content: ( content
+content )
+Argv: ()
-Content: content
-Argv:
+Content: ( content )
+Argv: ()
(No interpreter found: phutil_fake_test_block_interpreter)
diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupBlockInterpreter.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupBlockInterpreter.php
index e3e8bef..2461c80 100644
--- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupBlockInterpreter.php
+++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupBlockInterpreter.php
@@ -1,16 +1,40 @@
<?php
/**
* @group markup
* @stable
*/
abstract class PhutilRemarkupBlockInterpreter {
+ private $engine;
+
+ final public function setEngine($engine) {
+ $this->engine = $engine;
+ return $this;
+ }
+
+ final public function getEngine() {
+ return $this->engine;
+ }
+
/**
* @return string
*/
abstract public function getInterpreterName();
abstract public function markupContent($content, array $argv);
+ protected function markupError($string) {
+ if ($this->getEngine()->isTextMode()) {
+ return '('.$string.')';
+ } else {
+ return phutil_tag(
+ 'div',
+ array(
+ 'class' => 'remarkup-interpreter-error',
+ ),
+ $string);
+ }
+ }
+
}
diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupInterpreterRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupInterpreterRule.php
index 1ce2b9d..912e009 100644
--- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupInterpreterRule.php
+++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupInterpreterRule.php
@@ -1,85 +1,94 @@
<?php
/**
* @group markup
*/
final class PhutilRemarkupEngineRemarkupInterpreterRule
extends PhutilRemarkupEngineBlockRule {
const START_BLOCK_PATTERN = '/^([\w]+)\s(?:\(([^)]+)\)\s)?{{{/';
const END_BLOCK_PATTERN = '/}}}\s*$/';
public function getMatchingLineCount(array $lines, $cursor) {
$num_lines = 0;
if (preg_match(self::START_BLOCK_PATTERN, $lines[$cursor])) {
$num_lines++;
while (isset($lines[$cursor])) {
if (preg_match(self::END_BLOCK_PATTERN, $lines[$cursor])) {
break;
}
$num_lines++;
$cursor++;
}
}
return $num_lines;
}
public function markupText($text) {
$lines = explode("\n", $text);
$first_key = head_key($lines);
$last_key = last_key($lines);
while (trim($lines[$last_key]) === '') {
unset($lines[$last_key]);
$last_key = last_key($lines);
}
$matches = null;
preg_match(self::START_BLOCK_PATTERN, head($lines), $matches);
$argv = array();
if (isset($matches[2])) {
$argv = id(new PhutilSimpleOptions())->parse($matches[2]);
}
$interpreters = id(new PhutilSymbolLoader())
->setAncestorClass('PhutilRemarkupBlockInterpreter')
->loadObjects();
+ foreach ($interpreters as $interpreter) {
+ $interpreter->setEngine($this->getEngine());
+ }
+
$lines[$first_key] = preg_replace(
self::START_BLOCK_PATTERN,
"",
$lines[$first_key]);
$lines[$last_key] = preg_replace(
self::END_BLOCK_PATTERN,
"",
$lines[$last_key]);
if (trim($lines[$first_key]) === '') {
unset($lines[$first_key]);
}
if (trim($lines[$last_key]) === '') {
unset($lines[$last_key]);
}
$content = implode("\n", $lines);
$interpreters = mpull($interpreters, null, 'getInterpreterName');
if (isset($interpreters[$matches[1]])) {
return $interpreters[$matches[1]]->markupContent($content, $argv);
}
- $message = sprintf('No interpreter found: %s', $matches[1]);
+ $message = pht('No interpreter found: %s', $matches[1]);
if ($this->getEngine()->isTextMode()) {
return '('.$message.')';
}
- return hsprintf('<div style="color: red;">%s</div>', $message);
+ return phutil_tag(
+ 'div',
+ array(
+ 'class' => 'remarkup-interpreter-error',
+ ),
+ $message);
}
}
diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupTestInterpreterRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupTestInterpreterRule.php
index 11a8fa1..6b1e66f 100644
--- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupTestInterpreterRule.php
+++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupTestInterpreterRule.php
@@ -1,20 +1,20 @@
<?php
/**
* @group markup
*/
final class PhutilRemarkupEngineRemarkupTestInterpreterRule
extends PhutilRemarkupBlockInterpreter {
public function getInterpreterName() {
return "phutil_test_block_interpreter";
}
public function markupContent($content, array $argv) {
return sprintf(
- "Content: %s\nArgv: %s",
+ "Content: (%s)\nArgv: (%s)",
$content,
http_build_query($argv));
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Feb 7, 5:27 PM (6 h, 18 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a5/0f/5c6df8c265eec16289a7100aeb28
Attached To
rPHUTIL libphutil
Event Timeline
Log In to Comment