Highlight parts of a text.

@param string $fulltext the whole text
@param string $highlight The text to be highlighted

@return string
357019
public function highlightedMarkup($fulltext, $highlight)
    {
        if (!$highlight) {
            return $fulltext;
        }

        $this->hText = $fulltext;
        $this->hHighlight = $highlight;
        $this->hText = @preg_replace('#' . preg_quote($this->hHighlight, '#') . '#ui', '<span style="background-color:' . $this->hColor . ';">$0</span>', $this->hText);

        return $this->hText;
    }
671837
def highlighted_fulltext(self):
        """"""
        terms = self.fields.get('fulltext', [])
        if not terms:
            return None
        arguments = {'id': self['id'],
                     'query': ' & '.join(terms),
                     }
        with db_connect() as db_connection:
            with db_connection.cursor() as cursor:
                cursor.execute(_read_sql_file('highlighted-fulltext'),
                               arguments)
                hl_fulltext = cursor.fetchone()[0]
        return hl_fulltext
984017
public static function color($text, $foreground, $background = null)
    {
        $foreground = self::$colors[$foreground];
        $code = "\x03".$foreground;
        
        if ($background !== null) {
            $background = self::$colors[$background];
            $code .= ','.$background;
        }
        
        return $code.$text."\x03";
    }
1042558
protected static function highlightWord($value)
    {
        if (self::is_cli()) {
            return self::$cli_word . $value . "\x1b[0m";
        } else {
            return '<span ' . self::$word_attributes . '>' . $value . '</span>';
        }
    }
1336517
private function highlight($str, $start, $length) {
        $parts = array(
            substr($str, 0, $start),
            substr($str, $start, $length),
            substr($str, $start + $length)
        );

        $parts = array_map('htmlentities', $parts);

        $highlighted  = $parts[0] . '<span class="' . $this->highlightClassName . '">';
        $highlighted .= $parts[1] . '</span>' . $parts[2];

        return $highlighted;
    }
435069
def _highlight(string, color):
	''''''
	if CONFIG['color']:
		if color < 8:
			return '\033[{color}m{string}\033[0m'.format(string = string, color = color+30)
		else:
			return '\033[{color}m{string}\033[0m'.format(string = string, color = color+82)
	else:
		return string
913995
public static function highlight($file)
    {
        $highlightFileFunc = new \ReflectionFunction('highlight_file');
        if (!$highlightFileFunc->isDisabled()) {
            highlight_file($file);
        } else {
            echo '<pre>' . htmlspecialchars(file_get_contents($file)) . '</pre>';
        }
    }
166832
private function getHighlight()
    {
        if (Utils::findKey($this->options, 'highlight', false))
        {
            foreach ($this->fields as $field)
            {
                $this->payload['highlight']['fields'][$field] = new StdClass();
            }

            if ($tag = Utils::findKey($this->options['highlight'], 'tag', false))
            {
                $this->payload['highlight']['pre_tags'] = [$tag];
                $this->payload['highlight']['post_tags'] = [preg_replace('/\A</', '</', $tag)];
            }
        }
    }
204761
protected void displayText(String text) {
        if (highLight != null && !highLight.isEmpty() && text.contains(highLight)) {
            String highLightedText = text.replaceAll(highLight, ansi().bold().bg(theme.getHighLightBackground()).fg(theme.getHighLightForeground()).a(highLight).boldOff().reset().toString());
            console.out().print(highLightedText);
        } else {
            console.out().print(text);
        }
    }
574183
public function format($text)
    {
        $lines = explode("\n", $text);
        foreach ($lines as &$line) {
            $line = ((string) $this->quote)
                  . str_repeat(' ', $this->indent * $this->indentWidth) 
                  . $line;
        }
        return Colors::colorize(implode("\n", $lines), $this->fgColor, $this->bgColor);
    }
765772
def highlight_text(text, lexer_name='python', **kwargs):
    
    """
    # Resolve extensions to languages
    lexer_name = {
        'py': 'python',
        'h': 'cpp',
        'cpp': 'cpp',
        'c': 'cpp',
    }.get(lexer_name.replace('.', ''), lexer_name)
    if lexer_name in ['red', 'yellow', 'blue', 'green']:
        # hack for coloring
        return color_text(text, lexer_name)
    import utool as ut
    if ENABLE_COLORS:
        try:
            import pygments
            import pygments.lexers
            import pygments.formatters
            #from pygments import highlight
            #from pygments.lexers import get_lexer_by_name
            #from pygments.formatters import TerminalFormatter
            #if ut.WIN32:
            #    assert False
            #    #formater = pygments.formatters.terminal256.Terminal256Formatter()
            #    import pygments.formatters.terminal256
            #    formater = pygments.formatters.terminal256.Terminal256Formatter()
            #else:
            import pygments.formatters.terminal
            formater = pygments.formatters.terminal.TerminalFormatter(bg='dark')
            lexer = pygments.lexers.get_lexer_by_name(lexer_name, **kwargs)
            return pygments.highlight(text, lexer, formater)
        except Exception:
            if ut.SUPER_STRICT:
                raise
            return text
    return text
820968
def highlightBlock(self, text):
        

        # I need to know where in the document we are,
        # because our formatting info is global to
        # the document
        cb = self.currentBlock()
        p = cb.position()

        # The \n is not really needed, but sometimes
        # you are in an empty last block, so your position is
        # **after** the end of the document.
        text = str(self.document().toPlainText()) + '\n'

        # Yes, re-highlight the whole document.
        # There **must** be some optimizacion possibilities
        # but it seems fast enough.
        highlight(text, self.lexer, self.formatter)

        # Just apply the formatting to this block.
        # For titles, it may be necessary to backtrack
        # and format a couple of blocks **earlier**.
        for i in range(len(str(text))):
            try:
                self.setFormat(i, 1, self.formatter.data[p + i])
            except IndexError:
                pass

        # I may need to do something about this being called
        # too quickly.
        self.tstamp = time.time()
853049
def highlight_block(self, text):
        """"""
        text = to_text_string(text)
        if text.startswith("+++"):
            self.setFormat(0, len(text), self.formats["keyword"])
        elif text.startswith("---"):
            self.setFormat(0, len(text), self.formats["keyword"])
        elif text.startswith("+"):
            self.setFormat(0, len(text), self.formats["string"])
        elif text.startswith("-"):
            self.setFormat(0, len(text), self.formats["number"])
        elif text.startswith("@"):
            self.setFormat(0, len(text), self.formats["builtin"])
        
        self.highlight_spaces(text)
239816
public function highlight($text, array $options = []) {
		$options += $this->_config;

		$text = $this->_prepare($text);

		if ($options['escape'] !== false) {
			$text = h($text);
		}

		$attr = ['class' => $options['prefix'] . $options['lang']];

		$options['attr'] = $this->templater()->formatAttributes($attr);
		$options['content'] = $text;

		return $this->templater()->format('code', $options);
	}
803526
public function highlightSearch($value, $searchString)
    {
        if (strlen($value) < 1 || strlen($searchString) < 1) {
            return $value;
        }
        preg_match_all("/$searchString+/i", $value, $matches);
        if (is_array($matches[0]) && count($matches[0]) > 0) {
            return str_replace($matches[0][0], '<em class="ccm-highlight-search">' . $matches[0][0] . '</em>', $value);
        }

        return $value;
    }
952475
protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
    {
        $words = array();

        $docBody = $highlighter->getDocument()->getFieldUtf8Value('body');
        include_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
        $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($docBody, 'UTF-8');

        $lowerTermText = ($this->_lowerTerm !== null)? $this->_lowerTerm->text : null;
        $upperTermText = ($this->_upperTerm !== null)? $this->_upperTerm->text : null;

        if ($this->_inclusive) {
            foreach ($tokens as $token) {
                $termText = $token->getTermText();
                if (($lowerTermText == null  ||  $lowerTermText <= $termText)  
                    && ($upperTermText == null  ||  $termText <= $upperTermText)
                ) {
                    $words[] = $termText;
                }
            }
        } else {
            foreach ($tokens as $token) {
                $termText = $token->getTermText();
                if (($lowerTermText == null  ||  $lowerTermText < $termText)  
                    && ($upperTermText == null  ||  $termText < $upperTermText)
                ) {
                    $words[] = $termText;
                }
            }
        }

        $highlighter->highlight($words);
    }
300336
def get_partial_text(fulltext):
    
    def _get_index(x):
        return int(float(x) / 100 * len(fulltext))

    partial_text = [
        fulltext[_get_index(start):_get_index(end)]
        for start, end in current_app.config[
            "CLASSIFIER_PARTIAL_TEXT_PERCENTAGES"
        ]
    ]

    return "\n".join(partial_text)