Parsedown::blockTable( $Line, $Block = null )
Description
Source
File: bp-help/vendors/parsedown/Parsedown.php
protected function blockTable($Line, array $Block = null) { if ( ! isset($Block) or $Block['type'] !== 'Paragraph' or isset($Block['interrupted'])) { return; } if ( strpos($Block['element']['handler']['argument'], '|') === false and strpos($Line['text'], '|') === false and strpos($Line['text'], ':') === false or strpos($Block['element']['handler']['argument'], "\n") !== false ) { return; } if (chop($Line['text'], ' -:|') !== '') { return; } $alignments = array(); $divider = $Line['text']; $divider = trim($divider); $divider = trim($divider, '|'); $dividerCells = explode('|', $divider); foreach ($dividerCells as $dividerCell) { $dividerCell = trim($dividerCell); if ($dividerCell === '') { return; } $alignment = null; if ($dividerCell[0] === ':') { $alignment = 'left'; } if (substr($dividerCell, - 1) === ':') { $alignment = $alignment === 'left' ? 'center' : 'right'; } $alignments []= $alignment; } # ~ $HeaderElements = array(); $header = $Block['element']['handler']['argument']; $header = trim($header); $header = trim($header, '|'); $headerCells = explode('|', $header); if (count($headerCells) !== count($alignments)) { return; } foreach ($headerCells as $index => $headerCell) { $headerCell = trim($headerCell); $HeaderElement = array( 'name' => 'th', 'handler' => array( 'function' => 'lineElements', 'argument' => $headerCell, 'destination' => 'elements', ) ); if (isset($alignments[$index])) { $alignment = $alignments[$index]; $HeaderElement['attributes'] = array( 'style' => "text-align: $alignment;", ); } $HeaderElements []= $HeaderElement; } # ~ $Block = array( 'alignments' => $alignments, 'identified' => true, 'element' => array( 'name' => 'table', 'elements' => array(), ), ); $Block['element']['elements'] []= array( 'name' => 'thead', ); $Block['element']['elements'] []= array( 'name' => 'tbody', 'elements' => array(), ); $Block['element']['elements'][0]['elements'] []= array( 'name' => 'tr', 'elements' => $HeaderElements, ); return $Block; }
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.