Parse <ktml:module position="..."></ktml:module> and <ktml:module name="..."> tags

@param string $text Block of text to parse
508372
protected function _parseModuleTags(&$text)
    {
        $matches = array();

        if(preg_match_all('#<ktml:module\s+([^>]*)>(.*)</ktml:module>#siU', $text, $matches))
        {
            foreach($matches[0] as $key => $match)
            {
                //Create attributes array
                $attributes = array(
                    'style'     => 'component',
                    'params'    => '',
                    'title'     => '',
                    'class'     => '',
                    'prepend'   => true,
                );

                $attributes = array_merge($attributes, $this->parseAttributes($matches[1][$key]));
                $content    = trim($matches[2][$key]);

                //Skip empty modules
                if (!empty($content)) {
                    $this->_injectModule('koowa_injector', $attributes, $content);
                }
            }

            //Remove the <khtml:module></khtml:module> tags
            $text = str_replace($matches[0], '', $text);
        }

        if(preg_match_all('#<ktml:module\s+([^>]*)>#siU', $text, $matches))
        {
            foreach($matches[0] as $key => $match)
            {
                //Create attributes array
                $attributes = array(
                    'style'     => 'component',
                    'params'    => '',
                    'title'     => '',
                    'class'     => '',
                    'prepend'   => true,
                );

                $attributes = array_merge($attributes, $this->parseAttributes($matches[1][$key]));

                //Skip unexisting modules
                if(isset($attributes['name']) && ComKoowaModuleHelper::hasModule($attributes['name'])) {
                    $this->_injectModule($attributes['name'], $attributes);
                }
            }

            //Remove the <khtml:module> tags
            $text = str_replace($matches[0], '', $text);
        }
    }
994706
public function read(&$text)
    {
        if (!ini_get('short_open_tag')) {
            /**
         	* We could also convert <%= like the real T_OPEN_TAG_WITH_ECHO
         	* but that's not necessary.
         	*
         	* It might be nice to also convert PHP code blocks <? ?> but
         	* let's quit while we're ahead.  It's probably better to keep
         	* the <?php for larger code blocks but that's your choice.  If
          	* you do go for it, explicitly check for <?xml as this will
         	* probably be the biggest headache.
         	*/

            // convert "<?=" to "<?php echo"
               $find = '/\<\?\s*=\s*(.*?)/';
            $replace = "<?php echo \$1";
            $text = preg_replace($find, $replace, $text);

            // convert "<?" to "<?php"
            $find = '/\<\?(?:php)?\s*(.*?)/';
            $replace = "<?php \$1";
            $text = preg_replace($find, $replace, $text);
        }

        return $this;
    }
711619
static function parse($text)
    {
        $parser = new \Parsedown();

        $text = static::cleanLeadingSpace($text);

        return $parser->text($text);
    }
1025045
public function parseTajweed($text)
    {
        foreach ($this->meta as $meta)
        $text = str_replace(
            $meta['identifier'],
            '<tajweed class="' . $meta['default_css_class']. '" data-type="' . $meta['type'] . '" data-description="' .$meta['description'] . '" data-tajweed="',
            $text);

        return $text;
    }
717085
public function filter(&$text)
    {
        $matches = array();
        if(preg_match_all('#<ktml:markdown>(.*)<\/ktml:markdown>#siU', $text, $matches))
        {
            $engine = $this->getObject('template.engine.factory')
                ->createEngine('markdown', array('template' => $this->getTemplate()));

            foreach($matches[1] as $key => $match)
            {
                $html = $engine->loadString($matches[1][$key])->render();
                $text = str_replace($matches[0][$key], $html, $text);
            }
        }
    }
124890
private function processText($text)
    {
        // verify if content is a string otherwhise just return the original provided content
        if (!is_string($text) || empty($text)) {
            return $text;
        }
        // find all tags based on the REGEX expression
        preg_match_all(static::REGEX, $text, $results, PREG_SET_ORDER);
        // foreach all the results matches the regex
        foreach ($results as $row) {
            // When value is empty (can be caused by using `link[]` we have to skip this item.
            if (empty($row['value'])) {
                continue;
            }
            // extract tag name from regex
            $tag = $row['function'];
            if ($this->hasTag($tag)) {
                $replace = $this->parseTag($tag, $row);
                $text = preg_replace('/'.preg_quote($row[0], '/').'/mi', $replace, $text, 1);
            }
        }
        
        return $text;
    }
210577
protected function onFormatText(string &$text): void
    {
        $lines = preg_split("/\r\n|\n|\r/", $text);
        $result = [];

        $lastEmptyLinesCount = 0;
        $hasFoundNonEmptyLines = false;

        foreach ($lines as $line) {
            if (($this->textFormatOptions & TextFormatOptions::TRIM) !== 0) {
                $line = trim($line);
            }
            if (($this->textFormatOptions & TextFormatOptions::COMPACT) !== 0) {
                $line = preg_replace('/\s+/', ' ', $line);
            }

            if ($line === '') {
                if (($this->textFormatOptions & TextFormatOptions::COMPACT_LINES) !== 0 && $lastEmptyLinesCount > 0) {
                    continue;
                }
                if (($this->textFormatOptions & TextFormatOptions::TRIM_LINES) !== 0 && !$hasFoundNonEmptyLines) {
                    continue;
                }

                $lastEmptyLinesCount++;
            } else {
                $lastEmptyLinesCount = 0;
                $hasFoundNonEmptyLines = true;
            }

            $result[] = $line;
        }

        if (($this->textFormatOptions & TextFormatOptions::TRIM_LINES) !== 0 && $lastEmptyLinesCount > 0) {
            // Trim the last empty lines (we did not know until now that those were at the end).
            array_splice($result, -$lastEmptyLinesCount);
        }

        $text = implode("\r\n", $result);
    }
420459
public function parse($text, $context = null)
    {
        $parser = $this->getParser($context);

        $this->events->dispatch(new Parsing($parser, $context, $text));

        return $parser->parse($text);
    }
711069
private function setParseB($text, &$currentMode) {
        $tmp = preg_quote($this->keysB, '/');

        $match = array();
        if (preg_match('/[^' . $tmp . ']/', $text, $match) === 1) {
            // We found something not allowed
            throw new CINParseException('code128', 'The text "' . $text . '" can\'t be parsed with the Table B. The character "' . $match[0] . '" is not allowed.');
        } else {
            $latch = ($currentMode === 'B') ? '' : '1';
            $currentMode = 'B';

            return $latch . $this->getSequenceParsed($text, $currentMode);
        }
    }
580921
public function parse(string $text) : bool
    {
        $lower = strtolower($text);
        if (! in_array($lower, array_merge(self::TRUE_VALUES, self::FALSE_VALUES)))
            throw new ParseException($this, $text, 0, self::PARSE_ERROR);
        return in_array($lower, self::TRUE_VALUES);
    }
488143
public function filter(&$text)
    {
        $scripts = $this->_parseTags($text);

        if($this->getTemplate()->decorator() == 'koowa') {
            $text = str_replace('<ktml:script>', $scripts, $text);
        } else  {
            $text = $scripts.$text;
        }
    }
90061
protected function _parseTags(&$text)
    {
        $tags  = '';
        $title =  '';

        $matches = array();
        if(preg_match_all('#<title(.*)>(.*)<\/title>#siU', $text, $matches))
        {
            foreach(array_unique($matches[2]) as $key => $match)
            {
                //Set required attributes
                $attribs = array(
                    'content'   => 'default',
                    'separator' => $this->getConfig()->separator
                );

                $attribs   = array_merge($attribs, $this->parseAttributes( $matches[1][$key]));
                $separator = $attribs['separator'];

                if(!empty($title))
                {
                    switch($attribs['content'])
                    {
                        case 'prepend' : $title = $match.' '.$separator.' '.$title; break;
                        case 'append'  : $title = $title.' '.$separator.' '.$match; break;
                        case 'replace' : $title = $match; break;
                    }
                }
                else $title = $match;
            }

            $text = str_replace($matches[0], '', $text);
            $tags .= $this->_renderTag($attribs, $title);
        }

        return $tags;
    }
1145973
function parse($text) {
		$text=parent::parse($text);
		// Build tree structure
		for ($ptr=0,$w=5,$len=strlen($text),$tree=[],$tmp='';$ptr<$len;)
			if (preg_match('/^(.{0,'.$w.'}?)<(\/?)(?:F3:)?'.
				'('.$this->tags.')\b((?:\s+[\w.:@!-]+'.
				'(?:\h*=\h*(?:"(?:.*?)"|\'(?:.*?)\'))?|'.
				'\h*\{\{.+?\}\})*)\h*(\/?)>/is',
				substr($text,$ptr),$match)) {
				if (strlen($tmp) || $match[1])
					$tree[]=$tmp.$match[1];
				// Element node
				if ($match[2]) {
					// Find matching start tag
					$stack=[];
					for($i=count($tree)-1;$i>=0;$i--) {
						$item=$tree[$i];
						if (is_array($item) &&
							array_key_exists($match[3],$item) &&
							!isset($item[$match[3]][0])) {
							// Start tag found
							$tree[$i][$match[3]]+=array_reverse($stack);
							$tree=array_slice($tree,0,$i+1);
							break;
						}
						else $stack[]=$item;
					}
				}
				else {
					// Start tag
					$node=&$tree[][$match[3]];
					$node=[];
					if ($match[4]) {
						// Process attributes
						preg_match_all(
							'/(?:(\{\{.+?\}\})|([^\s\/"\'=]+))'.
							'\h*(?:=\h*(?:"(.*?)"|\'(.*?)\'))?/s',
							$match[4],$attr,PREG_SET_ORDER);
						foreach ($attr as $kv)
							if (!empty($kv[1]) && !isset($kv[3]) && !isset($kv[4]))
								$node['@attrib'][]=$kv[1];
							else
								$node['@attrib'][$kv[1]?:$kv[2]]=
									(isset($kv[3]) && $kv[3]!==''?
										$kv[3]:
										(isset($kv[4]) && $kv[4]!==''?
											$kv[4]:NULL));
					}
				}
				$tmp='';
				$ptr+=strlen($match[0]);
				$w=5;
			}
			else {
				// Text node
				$tmp.=substr($text,$ptr,$w);
				$ptr+=$w;
				if ($w<50)
					$w++;
			}
		if (strlen($tmp))
			// Append trailing text
			$tree[]=$tmp;
		// Break references
		unset($node);
		return $tree;
	}
488820
private function parseLinks($text)
    {
        $offset = 0;
        $matches = array();
        // Extract all links from the text of the passage (if they exist)
        while (preg_match($this->links_pattern, $text, $matches, 0, $offset)) {
            switch ($matches[2]) {
                case '->':
                    $this->links[] = array('text' => trim($matches[1]), 'link' => trim($matches[3]));
                    $this->raw_links[] = $matches[0];
                    break;
                case '<-':
                case '|':
                    $this->links[] = array('text' => trim($matches[3]), 'link' => trim($matches[1]));
                    $this->raw_links[] = $matches[0];
                    break;
                default:
                    throw new \RuntimeException("Something that looked like a link could not be parsed.");
            }
            $offset = mb_stripos($text, $matches[0]) + mb_strlen($matches[0]);
        }
    }
517727
public function parse(string $text)
    {
        if (! is_numeric($text))
            throw new ParseException($this, $text, 0, self::ERROR);
        return $text + 0;
    }
1327052
private function parseBlock($text, &$lines)
    {
        $lines = explode("\n", $text);
        $this->_blocks = array();
        $this->_current = 'normal';
        $this->_pos = -1;
        $state = array(
            'special'   =>  implode("|", array_keys($this->_specialWhiteList)),
            'empty'     =>  0,
            'html'      =>  false
        );
        // analyze by line
        foreach ($lines as $key => $line) {
            $block = $this->getBlock();
            $args = array($block, $key, $line, &$state, $lines);
            if ($this->_current != 'normal') {
                $pass = call_user_func_array($this->_parsers[$this->_current], $args);
                if (!$pass) {
                    continue;
                }
            }
            foreach ($this->_parsers as $name => $parser) {
                if ($name != $this->_current) {
                    $pass = call_user_func_array($parser, $args);
                    if (!$pass) {
                        break;
                    }
                }
            }
        }
        return $this->optimizeBlocks($this->_blocks, $lines);
    }
269564
public function seeTag($text, &$data, &$root)
    {
        if (preg_match('/^<a href="(.+)">(.+)<\/a>$/', $text, $matches)) {
            $this->_link = $matches[1];
            $text = $matches[2];
        } elseif (preg_match('/^([^ ]+)([ \t](.*))?$/', $text, $matches)) {
            $this->_link = $matches[1];
            if (isset($matches[3])) {
                $text = $matches[3];
            }
        } else {
            $this->_link = NULL;
        }
        parent::tag('@see', $text, $root);
    }