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 @@ -2688,6 +2688,7 @@ 'PhabricatorIconSetEditField' => 'applications/transactions/editfield/PhabricatorIconSetEditField.php', 'PhabricatorIconSetIcon' => 'applications/files/iconset/PhabricatorIconSetIcon.php', 'PhabricatorImageMacroRemarkupRule' => 'applications/macro/markup/PhabricatorImageMacroRemarkupRule.php', + 'PhabricatorImageRemarkupRule' => 'applications/files/markup/PhabricatorImageRemarkupRule.php', 'PhabricatorImageTransformer' => 'applications/files/PhabricatorImageTransformer.php', 'PhabricatorImagemagickSetupCheck' => 'applications/config/check/PhabricatorImagemagickSetupCheck.php', 'PhabricatorInFlightErrorView' => 'applications/config/view/PhabricatorInFlightErrorView.php', @@ -7523,6 +7524,7 @@ 'PhabricatorIconSetEditField' => 'PhabricatorEditField', 'PhabricatorIconSetIcon' => 'Phobject', 'PhabricatorImageMacroRemarkupRule' => 'PhutilRemarkupRule', + 'PhabricatorImageRemarkupRule' => 'PhutilRemarkupRule', 'PhabricatorImageTransformer' => 'Phobject', 'PhabricatorImagemagickSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorInFlightErrorView' => 'AphrontView', diff --git a/src/applications/files/application/PhabricatorFilesApplication.php b/src/applications/files/application/PhabricatorFilesApplication.php --- a/src/applications/files/application/PhabricatorFilesApplication.php +++ b/src/applications/files/application/PhabricatorFilesApplication.php @@ -37,6 +37,7 @@ public function getRemarkupRules() { return array( new PhabricatorEmbedFileRemarkupRule(), + new PhabricatorImageRemarkupRule(), ); } diff --git a/src/applications/files/markup/PhabricatorImageRemarkupRule.php b/src/applications/files/markup/PhabricatorImageRemarkupRule.php new file mode 100644 --- /dev/null +++ b/src/applications/files/markup/PhabricatorImageRemarkupRule.php @@ -0,0 +1,47 @@ +isURI($matches[2])) { + $uri = new PhutilURI($matches[2]); + $img = $this->newTag( + 'img', + array('src' => $uri)); + return $this->getEngine()->storeText($img); + } else { + $parser = new PhutilSimpleOptions(); + $keys = $parser->parse($matches[2]); + // Create tag using keys + } + return $matches[2]; + } + + // This can probably be simplified a ton. Even if kept as-is, this probably + // isn't the right place to put it + private function isURI($uri_string) { + $regex = '(https?\:\/\/)?'; // protocol + // username and password. Can maybe just remove this piece. + $regex .= '([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?'; + $regex .= '([a-z0-9-.]*)\.([a-z]{2,3})'; // Host or IP + $regex .= '(\:[0-9]{2,5})?'; // Port + $regex .= '(\/([a-z0-9+\$_-]\.?)+)*\/?'; // Path + $regex .= '(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?'; // Query string + $regex .= '(#[a-z_.-][a-z0-9+\$_.-]*)?'; // Anchor + + return preg_match("~^$regex$~i", $uri_string); + } +}