62 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
<?php
 | 
						|
 | 
						|
    namespace WMarkDown\Modules;
 | 
						|
 | 
						|
    class Tables extends \WMarkDown\Abstracts\Modules{
 | 
						|
 | 
						|
        public function get_next_position($string){
 | 
						|
 | 
						|
            if(
 | 
						|
                $this->more &&
 | 
						|
                $this->from < 0 &&
 | 
						|
                $this->more = preg_match('/\[\!([^\r\n]+)?(([\r\n]+([^\!\n\r]+|\![^\]])*?)*)[\r\n]+\!\]/', $string, $this->matches, PREG_OFFSET_CAPTURE)
 | 
						|
            )
 | 
						|
                $this->from = $this->matches[0][1];
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        public function process($string, $modules, $level){
 | 
						|
 | 
						|
            $formatted = \WMarkDown\Modules::format($this->wmarkdown, $data = $this->wmarkdown->load_file($this->matches[1][0]), [], $modules, $modules->menu_level);
 | 
						|
 | 
						|
            $head = '';
 | 
						|
            $body = '';
 | 
						|
            $foot = '';
 | 
						|
            $wmarkdown = $this->wmarkdown;
 | 
						|
 | 
						|
            preg_replace_callback('/^\|([\^_\-\#])?([^\r\n]+)/m', function($values) use(&$head, &$body, &$foot, $wmarkdown, $modules){
 | 
						|
 | 
						|
                $html = '';
 | 
						|
                $block = in_array($values[1], ["^", "-"]) ? "head" : (in_array($values[1], ["_"]) ? "foot" : (in_array($values[1], ["#"]) ? "both" : "body"));
 | 
						|
                $tag = $block == "body" ? "d" : "h";
 | 
						|
 | 
						|
                preg_replace_callback('/(\|(\|+)?)?([^\|]+)/', function($cell) use(&$html, $tag, $wmarkdown, $modules){
 | 
						|
                    $html .= '<t' . $tag . ($cell[2] ? ' colspan="' . strlen($cell[1]) . '"' : '') . '>' . \WMarkDown\Modules::format($wmarkdown, trim($cell[3]), ["paragraphs"], $modules)["content"] . '</t' . $tag . '>';
 | 
						|
                }, $values[2]);
 | 
						|
                $html = '<tr>' . $html . '</tr>';
 | 
						|
 | 
						|
                if($block == "head")
 | 
						|
                    $head .= $html;
 | 
						|
                elseif($block == "foot")
 | 
						|
                    $foot .= $html;
 | 
						|
                elseif($block == "both"){
 | 
						|
                    $head .= $html;
 | 
						|
                    $foot .= $html;
 | 
						|
                }else
 | 
						|
                    $body .= $html;
 | 
						|
 | 
						|
            }, trim($this->matches[2][0]));
 | 
						|
 | 
						|
            $this->html = '<table' . (strpos($attributes = $this->matches[1][0] ?? '', " class=\"") !== false ? preg_replace('/( class=\"[^"]+)/', "$1 wmd-table", $attributes) : $attributes . ' class="wmd-table"') . '>' . (
 | 
						|
                ($head ? '<thead>' . $head . '</thead>' : '') .
 | 
						|
                ($body ? '<tbody>' . $body . '</tbody>' : '') .
 | 
						|
                ($foot ? '<tfoot>' . $foot . '</tfoot>' : '')
 | 
						|
            ) . '</table>';
 | 
						|
            $this->length = strlen($this->matches[0][0]);
 | 
						|
            $this->to = $this->from + $this->length;
 | 
						|
            $this->content = $this->matches[1][0];
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
    };
 |