Added support for rendering style tagged strings

This commit is contained in:
Stefano Azzolini 2015-05-17 00:03:03 +02:00
parent e3272e8449
commit 5dae42e9c5
4 changed files with 60 additions and 0 deletions

View file

@ -81,6 +81,12 @@ console.log(chalk.green('Hello %s'), name);
//=> Hello Sindre
```
You can also render colored text using an HTML-like string with tags.
```js
var chalk = require('chalk');
console.log(chalk.text('<red>Error!</red>'));
```
## API
@ -144,6 +150,32 @@ if (!chalk.supportsColor) {
}
```
### chalk.colorize(string)
Returns color styled text from a tagged string.
Tag names are the same used for accessing colors in `chalk.styles`.
Example:
```js
var chalk = require('chalk');
console.log( chalk.colorize("<magenta>Hello</magenta>, <red>th<green>is</green></red> <b>is</b> a <white><u>test</u></white>!") );
```
You can also use a shorthand for some modifiers :
| Alias | Modifier |
|-------|---------------|
| b | bold |
| u | underline |
| i | italic |
| inv | inverse |
| h | hidden |
| s | strikethrough |
| d | dim |
## Styles