53 lines
2.1 KiB
PHP
Executable File
53 lines
2.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace WMarkDown\Modules;
|
|
|
|
class FontFormats extends \WMarkDown\Abstracts\Modules{
|
|
|
|
private $scape = false;
|
|
|
|
public function get_next_position($string){
|
|
if(!$this->more || $this->from >= 0)
|
|
return;
|
|
$this->more = false;
|
|
|
|
$last = null;
|
|
$item = null;
|
|
|
|
if(preg_match('/\\\\([_\*\'"\\\\])/', $string, $matches, PREG_OFFSET_CAPTURE)){
|
|
$this->more = true;
|
|
$this->scape = true;
|
|
$this->from = $matches[0][1];
|
|
$this->matches = $matches;
|
|
};
|
|
|
|
foreach([
|
|
'/(\*)([^\*\\\\]+|\\\\.)\*/', '/(_)([^_\\\\]+|\\\\.)_/',
|
|
'/(\*{2})(([^\*\\\\]+|\*[^\*]|\\\\.)+)\*{2}(\*)?/', '/(__)(([^_\\\\]+|_[^_]|\\\\.)+)__(_)?/',
|
|
'/(\'{3})(([^\'\\\\]+|\'{1,2}[^\']|\\\\.)+)\'{3}(\'{2})?/', '/(""")(([^"\\\\]+|"{1,2}[^"]|\\\\.)+)"""("")?/',
|
|
'/(\'{2})(([^\'\\\\]+|\'[^\']|\\\\.)+)\'{2}/', '/("")(([^"\\\\]+|"[^"]|\\\\.)+)""/'
|
|
] as $pattern)
|
|
if(preg_match($pattern, $string, $matches, PREG_OFFSET_CAPTURE) && ($last === null || $last > $matches[0][1])){
|
|
$this->more = true;
|
|
$this->scape = false;
|
|
$this->from = $matches[0][1];
|
|
$this->matches = $matches;
|
|
};
|
|
|
|
}
|
|
|
|
public function process($string, $modules, $level){
|
|
|
|
$this->length = strlen($this->matches[0][0]);
|
|
$this->to = $this->from + $this->length;
|
|
$this->content = $this->matches[$this->scape ? 1 : 2][0];
|
|
$this->html = $this->scape ? $this->matches[1][0] : (
|
|
'<' . ($tag = strlen($this->matches[1][0]) == 2 ? "b" : "i") . '>' .
|
|
\WMarkDown\Modules::format($this->wmarkdown, $this->matches[2][0] . (isset($this->matches[4]) ? $this->matches[4][0] : ''), ["paragraphs"], $modules)["content"] .
|
|
'</' . $tag . '>'
|
|
);
|
|
|
|
}
|
|
|
|
};
|