Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
view-container / src / vendor / postcss / terminal-highlight.ts
Size: Mime:
import tokenize from './tokenize'
import Input from './input'

const HIGHLIGHT_THEME = {
  brackets: [36, 39], // cyan
  string: [31, 39], // red
  'at-word': [31, 39], // red
  comment: [90, 39], // gray
  '{': [32, 39], // green
  '}': [32, 39], // green
  ':': [1, 22], // bold
  ';': [1, 22], // bold
  '(': [1, 22], // bold
  ')': [1, 22], // bold
}

function code(color: string | number) {
  return '\u001b[' + color + 'm'
}

function terminalHighlight(css: string | any) {
  const tokens = tokenize(new Input(css), { ignoreErrors: true })
  const result = []
  tokens.forEach(token => {
    const color = HIGHLIGHT_THEME[token[0]]
    if (color) {
      result.push(
        token[1]
          .split(/\r?\n/)
          .map(i => code(color[0]) + i + code(color[1]))
          .join('\n')
      )
    } else {
      result.push(token[1])
    }
  })
  return result.join('')
}

export default terminalHighlight