Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96502893
PhabricatorRemarkupGraphvizBlockInterpreter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Dec 27, 08:43
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Dec 29, 08:43 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23177960
Attached To
rPH Phabricator
PhabricatorRemarkupGraphvizBlockInterpreter.php
View Options
<?php
final
class
PhabricatorRemarkupGraphvizBlockInterpreter
extends
PhutilRemarkupBlockInterpreter
{
public
function
getInterpreterName
()
{
return
'dot'
;
}
public
function
markupContent
(
$content
,
array
$argv
)
{
if
(!
Filesystem
::
binaryExists
(
'dot'
))
{
return
$this
->
markupError
(
pht
(
'Unable to locate the `%s` binary. Install Graphviz.'
,
'dot'
));
}
$width
=
$this
->
parseDimension
(
idx
(
$argv
,
'width'
));
$future
=
id
(
new
ExecFuture
(
'dot -T%s'
,
'png'
))
->
setTimeout
(
15
)
->
write
(
trim
(
$content
));
list
(
$err
,
$stdout
,
$stderr
)
=
$future
->
resolve
();
if
(
$err
)
{
return
$this
->
markupError
(
pht
(
'Execution of `%s` failed (#%d), check your syntax: %s'
,
'dot'
,
$err
,
$stderr
));
}
$file
=
PhabricatorFile
::
buildFromFileDataOrHash
(
$stdout
,
array
(
'name'
=>
'graphviz.png'
,
));
if
(
$this
->
getEngine
()->
isTextMode
())
{
return
'<'
.
$file
->
getBestURI
().
'>'
;
}
return
phutil_tag
(
'img'
,
array
(
'src'
=>
$file
->
getBestURI
(),
'width'
=>
nonempty
(
$width
,
null
),
));
}
// TODO: This is duplicated from PhabricatorEmbedFileRemarkupRule since they
// do not share a base class.
private
function
parseDimension
(
$string
)
{
$string
=
trim
(
$string
);
if
(
preg_match
(
'/^(?:
\d
*
\\
.)?
\d
+%?$/'
,
$string
))
{
return
$string
;
}
return
null
;
}
}
Event Timeline
Log In to Comment