Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102040838
PhutilRemarkupEngineRemarkupSimpleTableBlockRule.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
Sun, Feb 16, 12:19
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Feb 18, 12:19 (2 d)
Engine
blob
Format
Raw Data
Handle
24268783
Attached To
rPHU libphutil
PhutilRemarkupEngineRemarkupSimpleTableBlockRule.php
View Options
<?php
/**
* @group markup
*/
final
class
PhutilRemarkupEngineRemarkupSimpleTableBlockRule
extends
PhutilRemarkupEngineBlockRule
{
public
function
getBlockPattern
()
{
return
'/^(
\|
.*+
\n
?)+$/'
;
}
public
function
shouldMergeBlocks
()
{
return
false
;
}
public
function
markupText
(
$text
)
{
$matches
=
array
();
$rows
=
array
();
foreach
(
explode
(
"
\n
"
,
$text
)
as
$line
)
{
// Ignore ending delimiters.
$line
=
rtrim
(
$line
,
'|'
);
preg_match_all
(
'/
\|
([^|]*)/'
,
$line
,
$matches
);
$headings
=
true
;
$cells
=
array
();
foreach
(
$matches
[
1
]
as
$cell
)
{
$cell
=
trim
(
$cell
);
// Cell isn't empty and doesn't look like heading.
if
(!
preg_match
(
'/^(|--+)$/'
,
$cell
))
{
$headings
=
false
;
}
$cells
[]
=
array
(
'type'
=>
'td'
,
'content'
=>
$cell
);
}
if
(!
$headings
)
{
$rows
[]
=
$cells
;
}
else
if
(
$rows
)
{
// Mark previous row with headings.
foreach
(
$cells
as
$i
=>
$cell
)
{
if
(
$cell
[
'content'
])
{
$rows
[
last_key
(
$rows
)][
$i
][
'type'
]
=
'th'
;
}
}
}
}
if
(!
$rows
)
{
return
$this
->
applyRules
(
$text
);
}
$out
=
array
();
$out
[]
=
"<table class=
\"
remarkup-table
\"
>
\n
"
;
foreach
(
$rows
as
$cells
)
{
$out
[]
=
'<tr>'
;
foreach
(
$cells
as
$cell
)
{
$out
[]
=
'<'
.
$cell
[
'type'
].
'>'
;
$out
[]
=
$this
->
applyRules
(
$cell
[
'content'
]);
$out
[]
=
'</'
.
$cell
[
'type'
].
'>'
;
}
$out
[]
=
"</tr>
\n
"
;
}
$out
[]
=
"</table>
\n
"
;
return
implode
(
$out
);
}
}
Event Timeline
Log In to Comment