Page MenuHomePhorge

D25415.1737654639.diff
No OneTemporary

D25415.1737654639.diff

diff --git a/src/infrastructure/markup/blockrule/PhutilRemarkupInterpreterBlockRule.php b/src/infrastructure/markup/blockrule/PhutilRemarkupInterpreterBlockRule.php
--- a/src/infrastructure/markup/blockrule/PhutilRemarkupInterpreterBlockRule.php
+++ b/src/infrastructure/markup/blockrule/PhutilRemarkupInterpreterBlockRule.php
@@ -2,13 +2,41 @@
final class PhutilRemarkupInterpreterBlockRule extends PhutilRemarkupBlockRule {
- const START_BLOCK_PATTERN = '/^([\w]+)\s*(?:\(([^)]+)\)\s*)?{{{/';
+ /**
+ * Second part of the regex to find stuff like:
+ * interpreterName {{{ stuff }}}
+ * interpreterName (options) {{{ stuff }}}
+ * You have found the kernel of cowsay and figlet.
+ */
const END_BLOCK_PATTERN = '/}}}\s*$/';
+ /**
+ * Constructs the first part of the regex to find stuff like:
+ * interpreterName {{{ stuff }}}
+ * interpreterName (options) {{{ stuff }}}
+ * The exact regex is constructed from the available interpreters.
+ * @return string First part of interpreters regex
+ */
+ private function getStartBlockPattern() {
+ $interpreters = id(new PhutilClassMapQuery())
+ ->setAncestorClass('PhutilRemarkupBlockInterpreter')
+ ->execute();
+
+ $interpreter_names_regex = '';
+ foreach ($interpreters as $interpreter) {
+ if ($interpreter !== end($interpreters)) {
+ $interpreter_names_regex .= $interpreter->getInterpreterName().'|';
+ } else {
+ $interpreter_names_regex .= $interpreter->getInterpreterName();
+ }
+ }
+ return "/^($interpreter_names_regex)\s*(?:\(([^)]+)\)\s*)?{{{/";
+ }
+
public function getMatchingLineCount(array $lines, $cursor) {
$num_lines = 0;
- if (preg_match(self::START_BLOCK_PATTERN, $lines[$cursor])) {
+ if (preg_match(self::getStartBlockPattern(), $lines[$cursor])) {
$num_lines++;
while (isset($lines[$cursor])) {
@@ -33,7 +61,7 @@
}
$matches = null;
- preg_match(self::START_BLOCK_PATTERN, head($lines), $matches);
+ preg_match(self::getStartBlockPattern(), head($lines), $matches);
$argv = array();
if (isset($matches[2])) {
@@ -49,7 +77,7 @@
}
$lines[$first_key] = preg_replace(
- self::START_BLOCK_PATTERN,
+ self::getStartBlockPattern(),
'',
$lines[$first_key]);
$lines[$last_key] = preg_replace(

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 23, 17:50 (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1146076
Default Alt Text
D25415.1737654639.diff (2 KB)

Event Timeline