Wrap string with color codes for pretty inspect.
 @param [String] str Contents to colorize.
 @param [Symbol] sev Specify which kind of color to use, valid symbols are defined in {.COLOR_CODE}.
 @return [String] String wrapped with color codes.
354622
def colorize(str, sev: :normal_s)
      return str unless color_enabled?

      cc = COLOR_CODE
      color = cc.key?(sev) ? cc[sev] : ''
      "#{color}#{str.sub(cc[:esc_m], color)}#{cc[:esc_m]}"
    end
544562
def render_to_string(*)
      result = super
      if result.respond_to?(:each)
        string = +""
        result.each { |r| string << r }
        string
      else
        result
      end
    end
638780
function beautifyCode(str) {
    var beautifulStr = str;

    try {
        beautifulStr = (0, _jsBeautify.html)(str, beautifySettings);
    } catch (err) {
        console.error('Beautify error:', err.message);
    }

    return beautifulStr;
}
401106
def color(
            self, text=None, fore=None, back=None, style=None,
            no_closing=False):
        
        has_args = (
            (fore is not None) or
            (back is not None) or
            (style is not None)
        )
        if hasattr(text, '__colr__') and not has_args:
            # Use custom __colr__ method in the absence of arguments.
            return str(self._call_dunder_colr(text))

        # Stringify everything before operating on it.
        text = str(text) if text is not None else ''
        if _disabled:
            return text

        # Considered to have unclosed codes if embedded codes exist and
        # the last code was not a color code.
        embedded_codes = get_codes(text)
        has_end_code = embedded_codes and embedded_codes[-1] == closing_code
        # Add closing code if not already added, there is text, and
        # some kind of color/style was used (whether from args, or
        # color codes were included in the text already).
        # If the last code embedded in the text was a closing code,
        # then it is not added.
        # This can be overriden with `no_closing`.
        needs_closing = (
            text and
            (not no_closing) and
            (not has_end_code) and
            (has_args or embedded_codes)
        )
        if needs_closing:
            end = closing_code
        else:
            end = ''
        return ''.join((
            self.color_code(fore=fore, back=back, style=style),
            text,
            end,
        ))
833954
def markup(str, remove_para = false)
      return '' unless str

      # Convert leading comment markers to spaces, but only if all non-blank
      # lines have them
      if str =~ /^(?>\s*)[^\#]/ then
        content = str
      else
        content = str.gsub(/^\s*(#+)/) { $1.tr '#', ' ' }
      end

      res = formatter.convert content

      if remove_para then
        res.sub!(/^<p>/, '')
        res.sub!(/<\/p>$/, '')
      end

      res
    end
489246
def highlight_multi_regex(str_, pat_to_color, reflags=0):
    
    #import colorama
    # from colorama import Fore, Style
    #color = Fore.MAGENTA
    # color = Fore.RED
    #match = re.search(pat, str_, flags=reflags)

    colored = str_

    to_replace = []
    for pat, color in pat_to_color.items():
        matches = list(re.finditer(pat, str_, flags=reflags))

        for match in matches:
            start = match.start()
            end = match.end()
            to_replace.append((end, start, color))

    for tup in reversed(sorted(to_replace)):
        end, start, color = tup
        colored_part = color_text(colored[start:end], color)
        colored = colored[:start] + colored_part + colored[end:]

    return colored
1045255
function curlyColors(str) {
  var res = '';
  var esc;
  var match;
  var history = [];
  var lastIndex = 0;

  if (arguments.length >= 2) str = format.apply(null, slice.apply(arguments));

  while ((match = rx.exec(str)) !== null) {
    res += str.slice(lastIndex, match.index);
    if (match[1]) {
      // Opening tag found.
      // Append the starting escape string sequence.
      esc = colors[match[1]];
      history.push(esc);
      res += esc[0];
    } else if (history.length) {
      // Closing tag found.
      // Append the closing escape string sequence of the current color.
      res += history.pop()[1];
      if (history.length) {
        // Continue with previous starting escape string sequence.
        res += history[history.length - 1][0];
      }
    }
    lastIndex = match.index + match[0].length;
  }

  // Append the remaining string to the result string.
  res += str.slice(lastIndex);

  // Close all remaining tags.
  while (history.length) res += history.pop()[1];

  // Delete double occurrences of color sequences.
  res = res.replace(/(\x1b\[\d+m)\1{1,}/g, '$1');

  return res;
}
255992
function showInvisibles(str) {
  let ret = '';
  for (let i = 0; i < str.length; i++) {
    switch (str[i]) {
      case ' ':
        ret += '·'; // Middle Dot, \u00B7
        break;
      case '\n':
        ret += '⏎'; // Return Symbol, \u23ce
        break;
      case '\t':
        ret += '↹'; // Left Arrow To Bar Over Right Arrow To Bar, \u21b9
        break;
      case '\r':
        ret += '␍'; // Carriage Return Symbol, \u240D
        break;
      default:
        ret += str[i];
        break;
    }
  }
  return ret;
}
252688
def uncolored(string = nil) # :yields:
      if block_given?
        yield.gsub(COLORED_REGEXP, '')
      elsif string
        string.gsub(COLORED_REGEXP, '')
      elsif respond_to?(:to_str)
        gsub(COLORED_REGEXP, '')
      else
        ''
      end
    end
368446
def uncolor(string = nil) # :yields:
      if block_given?
        yield.to_str.gsub(COLORED_REGEXP, '')
      elsif string.respond_to?(:to_str)
        string.to_str.gsub(COLORED_REGEXP, '')
      elsif respond_to?(:to_str)
        to_str.gsub(COLORED_REGEXP, '')
      else
        ''
      end.extend(Term::ANSIColor)
    end
1004103
def color_str(self):
        ""
        s = self.s
        for k, v in sorted(self.atts.items()):
            # (self.atts sorted for the sake of always acting the same.)
            if k not in xforms:
                # Unsupported SGR code
                continue
            elif v is False:
                continue
            elif v is True:
                s = xforms[k](s)
            else:
                s = xforms[k](s, v)
        return s
635452
def color_code(cls, color):
        
        if not isinstance(color, tuple):
            color = cls.colors[color]
        return "{:d};{}".format(color[0], str(color[1]) if len(color) == 2 else "")
69229
def print(formatted = nil)
      result = name
      unless version.nil?
        result += ", version #{version}"
      end
      if formatted
        result = "#{FORMATTING_STAR.colorize(:yellow)} #{result}"
      end
      result
    end
295691
def _colorize(token,  # type: str
              weight,  # type: float
              weight_range,  # type: float
              ):
    # type: (...) -> str
    
    token = html_escape(token)
    if np.isclose(weight, 0.):
        return (
            '<span '
            'style="opacity: {opacity}"'
            '>{token}</span>'.format(
                opacity=_weight_opacity(weight, weight_range),
                token=token)
        )
    else:
        return (
            '<span '
            'style="background-color: {color}; opacity: {opacity}" '
            'title="{weight:.3f}"'
            '>{token}</span>'.format(
                color=format_hsl(
                    weight_color_hsl(weight, weight_range, min_lightness=0.6)),
                opacity=_weight_opacity(weight, weight_range),
                weight=weight,
                token=token)
        )
1047078
def cyan(cls, string, auto=False):
        
        return cls.colorize('cyan', string, auto=auto)
1038128
def compile_str(contents):
    
    ctx = SASS_CLIB.sass_new_context()
    ctx.contents.source_string = c_char_p(contents)

    SASS_CLIB.compile(ctx)

    if ctx.contents.error_status:
        print(ctx.contents.error_message)

    return ctx.contents.output_string or ""
82625
function colorize(color, str) {
  return str
      .split('\n')
      .map(part => color(part))
      .join('\n');
}