Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102402794
PhabricatorInlineKaTeXRemarkupRule.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
Thu, Feb 20, 08:50
Size
1 KB
Mime Type
text/x-php
Expires
Sat, Feb 22, 08:50 (2 d)
Engine
blob
Format
Raw Data
Handle
24271652
Attached To
rPH Phabricator
PhabricatorInlineKaTeXRemarkupRule.php
View Options
<?php
final
class
PhabricatorInlineKaTeXRemarkupRule
extends
PhabricatorRemarkupCustomInlineRule
{
public
function
getPriority
()
{
return
300.0
;
}
public
function
apply
(
$text
)
{
return
preg_replace_callback
(
'@{tex
\b
([^{}]*({[^{}]*?([^{}]|(?R))*[^{}]*?}[^{}]*)*[^{}]*)}@m'
,
array
(
$this
,
'markupNavigation'
),
$text
);
}
public
function
markupNavigation
(
array
$matches
)
{
$future
=
id
(
new
ExecFuture
(
'node /opt/render2katex/index.js i'
))
->
setTimeout
(
15
)
->
write
(
trim
(
$matches
[
1
]));
list
(
$err
,
$stdout
,
$stderr
)
=
$future
->
resolve
();
if
(
$err
)
{
return
pht
(
'Execution of `%s` failed (#%d), check your syntax: %s'
,
'render2katex'
,
$err
,
$stderr
);
}
$result
=
$stdout
;
$engine
=
$this
->
getEngine
();
if
(
$engine
->
isTextMode
())
{
return
$matches
[
1
];
}
if
(
$engine
->
isHTMLMailMode
())
{
return
phutil_safe_html
(
$result
);
}
return
$this
->
getEngine
()->
storeText
(
phutil_safe_html
(
$result
));
}
}
Event Timeline
Log In to Comment