Phosphorum\Markdown\TableExtension::processTable PHP Метод

processTable() публичный Метод

Gfm tables
public processTable ( Ciconia\Common\Text $text, array $options = [] )
$text Ciconia\Common\Text
$options array
    public function processTable(Text $text, array $options = [])
    {
        $lessThanTab = $options['tabWidth'] - 1;
        $text->replace('/
            (?:\\n\\n|\\A)
            (?:[ ]{0,' . $lessThanTab . '}      #  table header
                (?:\\|?)                         #  optional outer pipe
                ([^\\n]*?\\|[^\\n]*?)              #1 table header
                (?:\\|?)                         #  optional outer pipe
            )\\n
            (?:[ ]{0,' . $lessThanTab . '}      #  second line
                (?:\\|?)                         #  optional outer pipe
                ([-:\\| ]+?\\|[-:\\| ]+?)          #2 dashes and pipes
                (?:\\|?)                         #  optional outer pipe
            )\\n
            (.*?)\\n{2,}                         #3 table body
            /smx', function (Text $w, Text $header, Text $rule, Text $body) use($options) {
            // Escape pipe to hash, so you can include pipe in cells by escaping it like this: `\\|`
            $this->escapePipes($header);
            $this->escapePipes($rule);
            $this->escapePipes($body);
            try {
                $baseTags = $this->createBaseTags($rule->split('/\\|/'));
                $headerCells = $this->parseHeader($header, $baseTags);
                $bodyRows = $this->parseBody($body, $baseTags);
            } catch (SyntaxError $e) {
                if ($options['strict']) {
                    throw $e;
                }
                return $w;
            }
            $html = $this->createView($headerCells, $bodyRows);
            $this->unescapePipes($html);
            return "\n\n" . $html . "\n\n";
        });
    }