76 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
<?php
 | 
						|
 | 
						|
    namespace WMarkDown\Modules;
 | 
						|
 | 
						|
    class Links extends \WMarkDown\Abstracts\Modules{
 | 
						|
 | 
						|
        public function get_next_position($string){
 | 
						|
 | 
						|
            if(
 | 
						|
                $this->more &&
 | 
						|
                $this->from < 0 &&
 | 
						|
                $this->more = preg_match('/' .
 | 
						|
                    '\\\\([\[\]])|' .
 | 
						|
                    '(^|\\b)([a-z][a-z\d]{1,8}\:\/\/[^\/<\r\n]+(\/([^ <\r\n]+)?)?)|' . // 1, 2, 3, 4, 5
 | 
						|
                    '\[(([^ \[\]]+)( (([^\[\]\r\n]+(\r\n|[\r\n])?)+))?)\](' . // 6, 7, 8, 9, 10, 11, 12
 | 
						|
                        '\: ?([^\r\n]+)|' . // 13
 | 
						|
                        '\((([^ \(\)]+)( (([^\'"\(\)]+)|\'(([^\'\\\\]+|\\\\.)*)\'|"(([^"\\\\]+|\\\\.)*)"))?)\)|' . // 14, 15, 16, 17, 18, 19, 20, 21, 22
 | 
						|
                        '\[(([^ \[\]]+)( (([^\'"\(\)]+)|\'(([^\'\\\\]+|\\\\.)*)\'|"(([^"\\\\]+|\\\\.)*)"))?)\]' . // 23, 24, 25, 26, 27, 28, 29, 30, 31
 | 
						|
                    ')?' .
 | 
						|
                '/m', $string, $this->matches, PREG_OFFSET_CAPTURE)
 | 
						|
            )
 | 
						|
                $this->from = $this->matches[0][1];
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        public function process($string, $modules, $level){
 | 
						|
 | 
						|
            $this->length = strlen($this->matches[0][0]);
 | 
						|
            $this->to = $this->from + $this->length;
 | 
						|
            $this->content = $this->matches[0][0];
 | 
						|
 | 
						|
            if($this->matches[1][1] != -1){
 | 
						|
                $this->html = $this->matches[1][0];
 | 
						|
                return;
 | 
						|
            };
 | 
						|
 | 
						|
            $link = null;
 | 
						|
            $text = null;
 | 
						|
            $title = null;
 | 
						|
            $index = null;
 | 
						|
            $reference = null;
 | 
						|
 | 
						|
 | 
						|
            if($this->matches[3][1] != -1)
 | 
						|
                $link = $text = $title = $this->matches[3][0];
 | 
						|
            elseif($this->matches[6][1] != -1){
 | 
						|
                $link = $this->matches[7][0];
 | 
						|
                $text = $this->matches[isset($this->matches[9]) && $this->matches[9][1] != -1 ? 9 : 7][0];
 | 
						|
                if(isset($this->matches[12])){
 | 
						|
                    if(isset($this->matches[13]) && $this->matches[13][1] != -1){
 | 
						|
                        $reference = base64_encode($this->matches[6][0]);
 | 
						|
                        $link = $this->matches[13][0];
 | 
						|
                    }else{
 | 
						|
                        $text = $this->matches[6][0];
 | 
						|
                        if($i = isset($this->matches[15]) && $this->matches[15][1] != -1 ? 15 : (isset($this->matches[24]) ? 24 : 0)){
 | 
						|
                            $link = $this->matches[$i][0];
 | 
						|
                            $index = base64_encode($this->matches[$i - 1][0]);
 | 
						|
                            if(isset($this->matches[$i + 2]))
 | 
						|
                                $title = $this->matches[isset($this->matches[$i + 3]) ? $i + 3 : (isset($this->matches[$i + 4]) ? $i + 4 : (isset($this->matches[$i + 6]) ? $i + 6 : 0))][0];
 | 
						|
                        };
 | 
						|
                    };
 | 
						|
                }else
 | 
						|
                    $title = $text;
 | 
						|
            };
 | 
						|
 | 
						|
            $this->html = $reference !== null ? '<input type="hidden" data-index="' . $reference . '" data-link="' . $link . '" />' : '<a ' .
 | 
						|
                'href="' . $link . '" ' .
 | 
						|
                'target="' . ($link && $link[0] == "#" ? "_self" : "_blank") . '"' .
 | 
						|
                ($title ? ' title="' . $title . '"' : '') .
 | 
						|
                ($index ? ' data-index="' . $index . '"' : '') .
 | 
						|
            '>' . ($text && $text != $link ? \WMarkDown\Modules::format($this->wmarkdown, $text, ["paragraphs", "links"], $modules)["content"] : $link) . '</a>';
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
    };
 |