• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

jerolimov/react-showdown: Render React components within markdown and markdown a ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

jerolimov/react-showdown

开源软件地址(OpenSource Url):

https://github.com/jerolimov/react-showdown

开源编程语言(OpenSource Language):

TypeScript 98.6%

开源软件介绍(OpenSource Introduction):

react-showdown Build status Test coverage Dependency Status

Render React components within markdown and markdown as React components!

Features

  • Render markdown as React components.
  • Render React components within the markdown!
  • Full TypeScript Support.
  • Fully tested.
  • Supports all Showdown extensions, like the Twitter Extension and the Youtube Extension.
  • New in 2.0: Supports Showdown Flavors!
  • New in 2.1:
    • Fixes #54: Missing content after a self-closing component. This was fixed by setting the default value of showdown config recognizeSelfClosing to true. Thanks @n1ru4l
    • New feature: add new optional sanitizeHtml prop for sanitizing html before it was rendered. Thanks @n1ru4l aswell.

Installation

npm install --save react-showdown

or

yarn add react-showdown

Use as React component

Example with ES6/JSX:

import React from 'react';
import MarkdownView from 'react-showdown';

export default function App() {
  const markdown = `
# Welcome to React Showdown :+1:

To get started, edit the markdown in \`example/src/App.tsx\`.

| Column 1 | Column 2 |
|----------|----------|
| A1       | B1       |
| A2       | B2       |
`;

  return (
    <MarkdownView
      markdown={markdown}
      options={{ tables: true, emoji: true }}
    />
  );
};

Use a React component and use it within the markdown with ES6 / TypeScript:

import MarkdownView from 'react-showdown';

function CustomComponent({ name }: { name: string }) {
  return <span>Hello {name}!</span>;
}

const markdown = `
# A custom component:

<CustomComponent name="world" />`;

<MarkdownView markdown={markdown} components={{ CustomComponent }} />

Available props

  • markdown, string, required
  • flavor, Flavor, optional
  • options, ConverterOptions, optional
  • extensions, showdown extensions, optional
  • components, components, optional

Converter options will be pushed forward to the showdown converter, please checkout the valid options section.

Credits

Project is based on the markdown parser Showdown and the html parser htmlparser2.

Alternatives




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap