GithubHelp home page GithubHelp logo

stefnnn / react-native-simple-markdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from charlesmangwa/react-native-simple-markdown

0.0 1.0 0.0 40 KB

React Native Markdown component (iOS & Android)

Home Page: https://www.npmjs.com/package/react-native-simple-markdown

License: MIT License

JavaScript 100.00%

react-native-simple-markdown's Introduction

react-native-simple-markdown

Build Status npm version npm Open Source Love

A component for rendering Markdown in React Native with native components, working with both iOS & Android. Pull requests are welcome ๐Ÿ˜ƒ ๐ŸŽ‰!

Getting started

yarn add react-native-simple-markdown

Usage

All you need to do is import the react-native-simple-markdown and then use the <Markdown /> component.

import React from 'react'
import Markdown from 'react-native-simple-markdown'

const MyAwesomeApp = () => {
  return (
    <Markdown styles={markdownStyles}>
      #Markdown in react-native is so cool! {'\n\n'}

      You can **emphasize** what you want, or just _suggest it_ ๐Ÿ˜โ€ฆ{'\n'}

      You can even [**link your website**](http://carlito.ninja) or if you prefer: [email somebody](mailto:[email protected]){'\n'}

      Spice it up with some GIFs ๐Ÿ’ƒ:

      ![Some GIF](https://media.giphy.com/media/dkGhBWE3SyzXW/giphy.gif){'\n'}

      And even add a cool video ๐Ÿ˜Ž!{'\n'}

      [![A cool video from YT](https://img.youtube.com/vi/dQw4w9WgXcQ/0.jpg)](http://www.youtube.com/watch?v=dQw4w9WgXcQ)

      [![Another one from Vimeo](https://i.vimeocdn.com/video/399486266_640.jpg)](https://vimeo.com/57580368)
    </Markdown>   
  )
}

const markdownStyles = {
  heading1: {
    fontSize: 24,
    color: 'purple',
  },
  link: {
    color: 'pink',
  },
  mailTo: {
    color: 'orange',
  },
  text: {
    color: '#555555',
  },
}

Properties

styles

<Markdown /> will apply its style by default. However you can pass a styles prop to customize it has you wish.

Example:

<Markdown
  styles={{
    heading1: {
      fontSize: 20,
    },
    strong: {
      fontWeight: 'bold',
    }
  }}
>
  #Hello ๐Ÿ‘‹
</Markdown>

rules

Here again, <Markdown /> will apply its rules by default. However you can pass a rules prop to add your own and then customize how the Markdown elements will be displayed!

Example:

<Markdown
  rules={{
    image: {
      react: (node, output, state) => (
        <CustomImageComponent
          key={state.key}
          source={{ uri: node.target }}
        />
      ),
    },
  }}
>
  ![Alt text](/path/to/img.jpg)
</Markdown>

RNSM also allows you to remove easily unwanted styling options without having to pass in rule objects that have their react key implemented/dummied to ignore those styling options.

Example:

<Markdown
  styles={ markdownStyles }
  whitelist={['link', 'url']}
>
  { description }
</Markdown>

whitelist will only apply link and url default styles, while blacklist will do the opposite. You don't need to pass in a rules prop that contained a key for all the styles you don't want and reimplement their styling output anymore.

Styles

Property Type Features
blockQuote <View> Also blockQuoteBar (<View>) and blockQuoteText (<Text>)
br <Text> -
del <Text> -
em <Text> -
hr <View> -
heading <Text> Also heading1 through heading6
image <Image> You can use resizeMode in <Markdown /> styles prop to set a resizeMode
inlineCode <Text> -
link <Text> -
list <View> Also listItem (<View>), listItemBullet (<Text>), listItemBulletType (Unicode character), listItemNumber (<Text>) and listItemText (<Text>)
mailTo <Text> -
paragraph <Text> -
plainText <Text> Used for styling text without any associated styles
strong <Text> -
table <View> -
tableHeader <View> -
tableHeaderCell <View> -
tableRow <View> -
tableRowCell <View> -
tableRowLast <View> Inherits from tableRow
text <Text> -
u <Text> -
url <Text> -
video <Image> Supports YouTube & Vimeo
view <View> This is the View container where the Markdown is rendered

Credits

This project was forked from react-native-markdown by @lwansbrough ๐Ÿ‘

react-native-simple-markdown's People

Contributors

chandlervdw avatar charlesmangwa avatar dvisco avatar leolebras avatar linonetwo avatar matusholec avatar oziks avatar romanlv avatar

Watchers

 avatar

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.