Coder Social home page Coder Social logo

msgdown's Introduction

msgdown

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

msgdown

logo

Installation

yarn add msgdown

Usage

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:

<strong>Attention:</strong> <em>msgdown</em><sup>TM</sup> is great<sub>1</sub>. <u>Use it</u> or <del>don\'t</del> it is <code>console.log('up to you!')</code>

Custom tokens

By default msgdown will use these tokens:

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:

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

The above html will contain <b>I am bold with a b</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 [email protected]

msgdown's People

Contributors

coyotte508 avatar mattmezza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

coyotte508

msgdown's Issues

Escape token

In some cases we should be able to scape a token, as the default tokens are fairly common chars like '/', so we should be able to make something like '\ /' for it to render '/'.

(fun fact: I had to edit this text because Github has scape the '\ ')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.