Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mattmezza/msgdown

*Simple* /messages/, _formatted_.
https://github.com/mattmezza/msgdown

bold chat code emphasis formatter html italic strikethrough sub sup

Last synced: 9 days ago
JSON representation

*Simple* /messages/, _formatted_.

Awesome Lists containing this project

README

        

msgdown
======

A simple message formatter for bold, strikethrough, underline, sub, sup, italic and code.

![msgdown](https://img.shields.io/travis/mattmezza/msgdown.svg?style=for-the-badge)

![logo](https://github.com/mattmezza/msgdown/blob/master/logo.png)

### Installation

`yarn add msgdown`

### Usage

```js
const down = require('msgdown')

const msg = `*Attention:* /msgdown/^TM^ is great¡1¡. _Use it_ or ~don\'t~ it is \`console.log('up to you!')\``
const html = down(msg)
```

`html` will contain exactly this:

```html
Attention: msgdownTM is great1. Use it or don\'t it is console.log('up to you!')
```

#### Custom tokens

By default `msgdown` will use these tokens:

```js
const defaultTokens = {
bold: {delimiter: '*', tag: 'strong'},
italic: {delimiter: '/', tag: 'em'},
underline: {delimiter: '_', tag: 'u'},
strike: {delimiter: '~', tag: 'del'},
code: {delimiter: '`', tag: 'code'},
sup: {delimiter: '^', tag: 'sup'},
sub: {delimiter: '¡', tag: 'sub'}
}
```

You can override every and each of the tokens by passing in your custom token object on every function call:

```js
const html = down('ßI am bold with a bß', {bold: {delmiter: 'ß', tag: 'b'}})
```

The above `html` will contain `I am bold with a b`.

### Testing

There is a test file linked to `yarn test`. Should be enough even though enough is never enough.

### Development

Maybe add more tokens? Maybe add pattern matching instead of plain one char matching? Maybe something else? You name it...

### Author

Matteo Merola