Replace color tags in a string.

@param   string     $text  The original text.
@param   string     $tag   The matched tag.
@param   string     $match The match.
@param   ColorStyle $style The color style to apply.

@return  mixed

@since   2.0
15463
protected function replaceColors($text, $tag, $match, ColorStyle $style)
    {
        $replace = $this->noColors
            ? $match
            : "\033[" . $style . "m" . $match . "\033[0m";

        return str_replace('<' . $tag . '>' . $match . '</' . $tag . '>', $replace, $text);
    }
905173
public Tag getTagForPattern(CharSequence text) {
		for (final Tag tag : Tag.values()) {
			Pattern pattern = this.compiledPatterns.get(tag);
			if (pattern == null) {
				pattern = Pattern.compile("^\\s*" + getPattern(tag), Pattern.DOTALL); //$NON-NLS-1$
				this.compiledPatterns.put(tag, pattern);
			}
			final Matcher matcher = pattern.matcher(text);
			if (matcher.find()) {
				return tag;
			}
		}
		return null;
	}
445726
private function replaceStyle($match)
    {
        if (!$this->isDecorated()) {
            return $match[2];
        }

        if ($this->hasStyle($match[1])) {
            $style = $this->getStyle($match[1]);
        } else {
            return $match[0];
        }

        return $style->apply($match[2]);
    }
1064656
private function createLinkOrSeeTagFromRegexMatch(array $match)
    {
        list($completeMatch, $tagName, $tagContent) = $match;

        return Tag::createInstance('@' . $tagName . ' ' . $tagContent);
    }
234356
protected function assignTextStyle(string $color)
    {
        if (in_array($color, $this->supported_text_styles) === true) {
            $this->text_color = $color;
        }
    }
924536
public static function colorify($text)
    {
        $htmldecoded = htmlspecialchars($text);
        $boldSqBracket = preg_replace('/\[([a-zA-Z]+)\]/', '[<span style="color: #000; font-weight: bold;">${1}</span>]', $htmldecoded);
        $boldBracket = preg_replace('/\{([a-zA-Z_ ]+)\}/', '{<span style="color: #000; font-weight: bold;">${1}</span>}', $boldSqBracket);
        return str_replace(self::$_search, self::$_replace, $boldBracket);
    }
717339
public function addText($text, $styleFont = null, $styleParagraph = null) {
		$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
		$this->_elementCollection[] = $text;
		return $text;
	}
1196622
public static function highlight($text, $phrase, $html = false) {
        if(empty($phrase))
            return $text;

        if(is_string($phrase))
            $phrase = [$phrase];

        foreach($phrase as $idx => $one)
            $phrase[$idx] = self::regex($one);

        $phrase = implode('|', $phrase);
        if($html)
            $phrase = "(?![^<]+>){$phrase}(?![^<]+>)";

        return preg_replace(sprintf(self::$re, $phrase), '<span class="highlight">\1</span>', $text);
    }
818753
public static function colorize($data, $search = null, $color = '#ffff66') {
		if ($search != null) {
			return str_ireplace($search, '<span style="background-color:'.$color.';">'.$search.'</span>', $data);
		} else {
			return '<span style="background-color:'.$color.';">'.$data.'</span>';
		}
	}
963257
public function style($string, $colourOrStyle)
    {
        if (is_array($colourOrStyle)) {
            $this->color->__invoke($string);

            while ($style = array_shift($colourOrStyle)) {
                $this->color->apply($style);
            }
            return $this->color->__toString();
        }

        return $this->color->__invoke($string)->apply($colourOrStyle, $string);
    }
1016828
public void updateStyleElement(Document document, Element style) {
    StringBuilder buf = new StringBuilder();
    serialize(buf);
    Text cont = document.createTextNode(buf.toString());
    while (style.hasChildNodes()) {
      style.removeChild(style.getFirstChild());
    }
    style.appendChild(cont);
  }
604573
public static function replace($text, array $replacements = [], $prefix = '{', $suffix = '}')
    {
        $replacements = static::prepareBinding($replacements, $prefix, $suffix);

        $filter = function ($text) use ($replacements) {
            return strtr($text, $replacements);
        };

        if (is_array($text)) {
            $text = array_map($filter, $text);
        } else {
            $text = $filter($text);
        }

        return $text;
    }
291314
public function clean_asset_tags($tag)
    {
        \preg_match_all(
            "!<link rel='stylesheet'\s?(id='[^']+')?\s+href='(.*)' type='text/css' media='(.*)' />!",
            $tag,
            $matches
        );
       
        if (empty($matches[2])) {
            return $tag;
        }

        $media = $matches[3][0] !== '' && $matches[3][0] !== 'all' ? ' media="' . $matches[3][0] . '"' : '';

        return "\t".'<link rel="stylesheet" href="' . $matches[2][0] . '"' . $media . '>' . "\n";
    }
233364
protected function getStyleCodes(string $tag): array
	{
		if(isset($this->styles[$tag]))
		{
			return [$this->styles[$tag]];
		}
		elseif(isset($this->userStyles[$tag]))
		{
			$codes = [];

			foreach($this->userStyles[$tag] as $tag)
			{
				$codes = array_merge($codes, $this->getStyleCodes($tag));
			}

			return $codes;
		}

		throw new FormatterException(vsprintf('Undefined formatting tag [ %s ] detected.', [$tag]));
	}
294634
public function get($tag)
    {
        if (!isset($this->styles[$tag])) {
            throw new OutOfBoundsException(sprintf(
                'The style tag "%s" does not exist.',
                $tag
            ));
        }

        return $this->styles[$tag];
    }
524068
protected function _replaceTags(&$text)
    {
        if (!empty($this->_stripped_tags)) {
            $text = str_replace($this->_stripped_tags[0], $this->_stripped_tags[1], $text);
        }
    }
1283311
public function filter(&$text)
    {
        $styles = $this->_parseTags($text);

        if($this->getTemplate()->decorator() == 'koowa') {
            $text = str_replace('<ktml:style>', $styles, $text);
        } else  {
            $text = $styles.$text;
        }
    }