Giter Club home page Giter Club logo

jsx-markdown's Introduction

Seamlessly embed markdown into JSX

This library provides React component for embeding markdown into JSX using tagged template literals ES6 feature.

Usage

import React from 'react'
import Markdown from 'jsx-markdown'

class MyComponent extends React.Component {
  constructor (props) {
    super(props)
    this.state = { counter: 0 }
  }

  render () {
    return Markdown`
      # Hello world

      This is markdown paragraph. You can 
      inline JavaScript variables as shown below.

      Counter is equal ${this.state.counter}
      
      You can even render React components:
      ${<button onClick={() => this.increment()}>
        +1
      </button>}
    `
  }

  increment () {
    this.setState({ 
      counter: this.state.counter + 1 
    })
  }
} 

Remarks

  1. HTML tags are not supported in markdown. If you need to render HTML use the following syntax:
Markdown`
  This is markdown. ${<div> This is custom HTML</div>}
`
  1. Indentation is removed automatically. It means the following two are equivalent:
Markdown`
First line
Anothe line
`
Markdown`
      First line
      Anothe line
`
  1. Because backtick character has to be escaped in template literals the component introduces some special syntax for convenience. Two quotation marks in a row are replaced with single backtick and three quotatiom marks in a row are repaced with three backticks.
Markdown`
  ''variable'' is equivalent to \`variable\`.
`
Markdown`
  '''js
    console.log(1)
  '''

  is equivalent to

  \`\`\`js
    console.log(1)
  \`\`\`
`

Project status

This component is used as a convenient markdown formatting in my another project. Functionalities are added as needed. It means at the current stage this component doesn't handle some basic markdown formatting.

If you miss some functionality feel free to raise an issue or create a pull request.

License

https://opensource.org/licenses/MIT

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.