Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F569896
PhutilRemarkupAnchorRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhutilRemarkupAnchorRule.php
View Options
<?php
final
class
PhutilRemarkupAnchorRule
extends
PhutilRemarkupRule
{
public
function
getPriority
()
{
return
200.0
;
}
public
function
apply
(
$text
)
{
return
preg_replace_callback
(
'/{anchor
\s
+#([^
\s
}]+)}/s'
,
array
(
$this
,
'markupAnchor'
),
$text
);
}
protected
function
markupAnchor
(
array
$matches
)
{
$engine
=
$this
->
getEngine
();
if
(
$engine
->
isTextMode
())
{
return
null
;
}
if
(
$engine
->
isHTMLMailMode
())
{
return
null
;
}
if
(
$engine
->
isAnchorMode
())
{
return
null
;
}
if
(!
$this
->
isFlatText
(
$matches
[
0
]))
{
return
$matches
[
0
];
}
if
(!
self
::
isValidAnchorName
(
$matches
[
1
]))
{
return
$matches
[
0
];
}
$tag_view
=
phutil_tag
(
'a'
,
array
(
'name'
=>
$matches
[
1
],
),
''
);
return
$this
->
getEngine
()->
storeText
(
$tag_view
);
}
public
static
function
isValidAnchorName
(
$anchor_name
)
{
$normal_anchor
=
self
::
normalizeAnchor
(
$anchor_name
);
if
(
$normal_anchor
===
$anchor_name
)
{
return
true
;
}
return
false
;
}
public
static
function
normalizeAnchor
(
$anchor
)
{
// Replace all latin characters which are not "a-z" or "0-9" with "-".
// Preserve other characters, since non-latin letters and emoji work
// fine in anchors.
$anchor
=
preg_replace
(
'/[
\x
00-
\x
2F
\x
3A-
\x
60
\x
7B-
\x
7F]+/'
,
'-'
,
$anchor
);
$anchor
=
trim
(
$anchor
,
'-'
);
return
$anchor
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 13, 3:03 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
124302
Default Alt Text
PhutilRemarkupAnchorRule.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment