2.4.3 β€’ Published 1 year ago

@alicloud/rc-markdown v2.4.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@alicloud/rc-markdown

Yet another react wrapper of markdown parse based on micromark.

Plugins built-in:

Other plugins, e.g. micromark-extension-math, you have to install it yourself and put it into props.extraExtensions:

import React from 'react';
import {
  math,
  mathHtml
} from 'micromark-extension-math';

import Markdown, {
  MarkdownExtension
} from '@alicloud/rc-markdown';

const extraExtensions: MarkdownExtension[] = [{
  syntax: math(),
  html: mathHtml()
}];

export default function MyMarkdown(): JSX.Element {
  return <Markdown {...{
    source: __YOUR_MARKDOWN_DOCUMENT_IN_STRING_FORMAT__,
    extraExtensions
  }} />;
}

Why πŸ™ˆ

I used to use react-markdown, however it has these defects:

  1. Its dependency react-markdown β†’ unified β†’ is-plain-obj exports only ES6, which I have to make some changes to my webpack config
  2. The bug https://github.com/remarkjs/react-markdown/issues/460 which lives quite a long time makes it impossible to use HTML...
  3. I tried to use remark-directive plugin, and... it is way too complex...

That's why I have to say goodbye to the world’s most popular Markdown parser and say Hi to the smallest CommonMark compliant markdown parser.

However, micromark has its own problems - the typings are NOT well-defined, I have to do quite a lot of diggings and hacking.

So far so good, cheers πŸŽ‰.

Usage πŸ’₯

Basic

import React from 'react';

import Markdown from '@alicloud/rc-markdown';

export default function MyMarkdown(): JSX.Element {
  return <Markdown {...{
    source: __YOUR_MARKDOWN_DOCUMENT_IN_STRING_FORMAT__
  }} />;
}

Use Directive

import React from 'react';

import Markdown, {
  MicromarkDirective,
  MarkdownExtensionDirectiveHtmlOptions
} from '@alicloud/rc-markdown';

// remember to make it static, do NOT put it inside render
const directiveOptions: MarkdownExtensionDirectiveHtmlOptions = {
  abbr(d: MicromarkDirective) {
    if (d.type !== 'textDirective') {
      return false;
    }
    
    this.tag('<abbr');
    
    if (d.attributes && 'title' in d.attributes) {
      this.tag(` title="${this.encode(d.attributes.title)}"`);
    }
    
    this.tag('>');
    this.raw(d.label || '');
    this.tag('</abbr>');
  }
};

export default function MyMarkdown(): JSX.Element {
  return <Markdown {...{
    source: __YOUR_MARKDOWN_DOCUMENT_IN_STRING_FORMAT__,
    plugins: {
      directive: directiveOptions
    }
  }} />;
}

Styles πŸ”₯

This package ships with no styles at all.

Use @alicloud/console-base-rc-markdown you want to have a beautiful look (with CSS var), or maybe you can wrap with your own styling code.

Useful Links ✨

GFM: https://gith[micromark]ub.github.com/gfm "GitHub Flavored Markdown"

2.4.3

1 year ago

2.4.1

1 year ago

2.4.2

1 year ago

2.4.0

1 year ago

2.3.2

2 years ago

2.3.4

1 year ago

2.3.6

1 year ago

2.3.0

2 years ago

2.2.1

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0-alpha.1

2 years ago

2.0.0-alpha.2

2 years ago

1.2.0

2 years ago

1.1.92

3 years ago

1.1.96

3 years ago

1.1.95

3 years ago

1.1.94

3 years ago

1.1.97

3 years ago

1.1.76

3 years ago

1.1.75

3 years ago

1.1.74

3 years ago

1.1.73

3 years ago

1.1.72

3 years ago

1.1.70

3 years ago

1.1.69

3 years ago

1.1.68

3 years ago

1.1.67

3 years ago

1.1.66

3 years ago

1.1.64

3 years ago

1.1.63

3 years ago

1.1.61

3 years ago

1.1.60

3 years ago

1.1.59

3 years ago

1.1.58

3 years ago

1.1.54

3 years ago

1.1.57

3 years ago

1.1.51

3 years ago

1.1.53

3 years ago

1.1.50

3 years ago

1.1.45

3 years ago

1.1.48

3 years ago

1.1.47

3 years ago

1.1.46

3 years ago

1.1.44

3 years ago

1.1.43

3 years ago

1.1.38

3 years ago

1.1.35

3 years ago

1.1.39

3 years ago

1.1.40

3 years ago

1.1.42

3 years ago

1.1.34

3 years ago

1.1.33

3 years ago

1.1.32

3 years ago

1.1.31

3 years ago

1.1.29

3 years ago

1.1.30

3 years ago

1.1.28

3 years ago

1.1.27

3 years ago

1.1.25

3 years ago

1.1.22

3 years ago

1.1.21

3 years ago

1.1.20

3 years ago

1.1.19

3 years ago

1.1.18

3 years ago

1.1.17

3 years ago

1.1.16

3 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.10

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.7

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago