Page MenuHomePhabricator
Paste P1158

<img> support in remarkup
ActivePublic

Authored by swisspol on May 22 2014, 3:36 PM.
Tags
None
Referenced Files
F158909: img_support_in_remarkup
May 22 2014, 3:36 PM
Subscribers
Tokens
"Love" token, awarded by jithinvmohan.
<?php
final class CustomInlineImageRule extends PhabricatorRemarkupCustomInlineRule {
public function getPriority() {
return 200.0; // Must be lower than 300 to over URL detection
}
public function apply($text) {
return preg_replace_callback(
'(<img (.*?)>)s',
array($this, 'markupInlineImageBlock'),
$text);
}
public function markupInlineImageBlock($matches) {
$engine = $this->getEngine();
$text = $matches[1];
$element = new SimpleXMLElement("<element $text />");
$attributes = array();
foreach($element->attributes() as $k => $v) {
$attributes[$k] = $v;
}
$source_body = phutil_tag('img', $attributes);
return $engine->storeText($source_body);
}
}

Event Timeline

swisspol changed the title of this paste from untitled to <img> support in remarkup.
swisspol updated the paste's language from autodetect to autodetect.