Contents

Parsedown::blockTable( $Line,  $Block = null )

Description

Source

File: bp-help/vendors/parsedown/Parsedown.php

897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
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.