Repository URL to install this package:
|
Version:
1.2.13 ▾
|
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tokenize_1 = __importDefault(require("./tokenize"));
const input_1 = __importDefault(require("./input"));
const HIGHLIGHT_THEME = {
brackets: [36, 39],
string: [31, 39],
'at-word': [31, 39],
comment: [90, 39],
'{': [32, 39],
'}': [32, 39],
':': [1, 22],
';': [1, 22],
'(': [1, 22],
')': [1, 22],
};
function code(color) {
return '\u001b[' + color + 'm';
}
function terminalHighlight(css) {
const tokens = tokenize_1.default(new input_1.default(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('');
}
exports.default = terminalHighlight;
//# sourceMappingURL=terminal-highlight.js.map