Added support for rendering style tagged strings
This commit is contained in:
parent
e3272e8449
commit
5dae42e9c5
4 changed files with 60 additions and 0 deletions
32
readme.md
32
readme.md
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue