Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63896131
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
Thu, May 23, 05:36
Size
1 KB
Mime Type
text/x-php
Expires
Sat, May 25, 05:36 (2 d)
Engine
blob
Format
Raw Data
Handle
17832047
Attached To
rPHU libphutil
PhutilRemarkupEngineRemarkupSimpleTableBlockRule.php
View Options
<?php
final
class
PhutilRemarkupEngineRemarkupSimpleTableBlockRule
extends
PhutilRemarkupEngineBlockRule
{
public
function
getMatchingLineCount
(
array
$lines
,
$cursor
)
{
$num_lines
=
0
;
while
(
isset
(
$lines
[
$cursor
]))
{
if
(
preg_match
(
'/^(
\|
.*+
\n
?)+$/'
,
$lines
[
$cursor
]))
{
$num_lines
++;
$cursor
++;
}
else
{
break
;
}
}
return
$num_lines
;
}
public
function
markupText
(
$text
,
$children
)
{
$matches
=
array
();
$rows
=
array
();
foreach
(
explode
(
"
\n
"
,
$text
)
as
$line
)
{
// Ignore ending delimiters.
$line
=
rtrim
(
$line
,
'|'
);
// NOTE: The complexity in this regular expression allows us to match
// a table like "| a | [[ href | b ]] | c |".
preg_match_all
(
'/
\|
'
.
'('
.
'(?:'
.
'(?:
\\
[
\\
[.*?
\\
]
\\
])'
.
// [[ ... | ... ]], a link
'|'
.
'(?:[^|[]+)'
.
// Anything but "|" or "[".
'|'
.
'(?:
\\
[[^
\\
|[])'
.
// "[" followed by anything but "[" or "|"
')*'
.
')/'
,
$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'
=>
$this
->
applyRules
(
$cell
));
}
if
(!
$headings
)
{
$rows
[]
=
array
(
'type'
=>
'tr'
,
'content'
=>
$cells
);
}
else
if
(
$rows
)
{
// Mark previous row with headings.
foreach
(
$cells
as
$i
=>
$cell
)
{
if
(
$cell
[
'content'
])
{
$rows
[
last_key
(
$rows
)][
'content'
][
$i
][
'type'
]
=
'th'
;
}
}
}
}
if
(!
$rows
)
{
return
$this
->
applyRules
(
$text
);
}
return
$this
->
renderRemarkupTable
(
$rows
);
}
}
Event Timeline
Log In to Comment