|
1 | 1 | # React Native Markdown Display [](https://badge.fury.io/js/react-native-markdown-display) [](https://snyk.io/test/github/iamacup/react-native-markdown-display) |
2 | 2 |
|
3 | | -It a 100% compatible CommonMark renderer, a react-native markdown renderer done right. This is __not__ |
4 | | -a web-view markdown renderer but a renderer that uses native components for all its elements. These components can be overwritten when needed as seen in the examples. |
| 3 | +It a 100% compatible CommonMark renderer, a react-native markdown renderer done right. This is __not__ a web-view markdown renderer but a renderer that uses native components for all its elements. These components can be overwritten and styled as needed. |
5 | 4 |
|
6 | 5 | ### Compatibility with react-native-markdown-renderer |
7 | 6 |
|
8 | | -This is intended to be a drop-in replacement for react-native-markdown-renderer, with a variety of bug fixes and enhancements - **Due to how the new style rules work, there may be some tweaking needed**, [see how to style stuff section below](#How-to-style-stuff) |
| 7 | +This is intended to be a replacement for react-native-markdown-renderer, with a variety of bug fixes and enhancements - **Due to how the new style rules work, there may be some tweaking needed**, [see how to style stuff section below](#How-to-style-stuff) |
9 | 8 |
|
10 | 9 | ### Install |
11 | 10 |
|
@@ -46,9 +45,9 @@ export default class Page extends PureComponent { |
46 | 45 |
|
47 | 46 | Text styles are applied in a way that makes it much more convenient to manage changes to global styles while also allowing fine tuning of individual elements. |
48 | 47 |
|
49 | | -Think of the implementation like applying styles in CSS. changes to the `root` effect everything, but can be overwritten further down the style / component tree. |
| 48 | +Think of the implementation like applying styles in CSS. changes to the `body` effect everything, but can be overwritten further down the style / component tree. |
50 | 49 |
|
51 | | -**Be careful when styling 'text':** the text rule is not applied to all rendered text, most notably list bullet points. If you want to, for instance, color all text, change the `root` style. |
| 50 | +**Be careful when styling 'text':** the text rule is not applied to all rendered text, most notably list bullet points. If you want to, for instance, color all text, change the `body` style. |
52 | 51 |
|
53 | 52 |
|
54 | 53 | <details><summary>Example</summary> |
@@ -173,28 +172,6 @@ And some additional, less used options: |
173 | 172 | </details> |
174 | 173 |
|
175 | 174 |
|
176 | | -<details><summary>Typographic Replacements</summary> |
177 | | -<p> |
178 | | - |
179 | | -``` |
180 | | - Enable typographer option to see result. |
181 | | -
|
182 | | - (c) (C) (r) (R) (tm) (TM) (p) (P) +- |
183 | | -
|
184 | | - test.. test... test..... test?..... test!.... |
185 | | -
|
186 | | - !!!!!! ???? ,, -- --- |
187 | | -
|
188 | | - "Smartypants, double quotes" and 'single quotes' |
189 | | -``` |
190 | | - |
191 | | -| iOS | Android |
192 | | -| --- | --- |
193 | | -| <img src="https://github.com/iamacup/react-native-markdown-display/raw/master/doc/images/ios-3.png"/> | <img src="https://github.com/iamacup/react-native-markdown-display/raw/master/doc/images/android-3.png"/> |
194 | | - |
195 | | -</p> |
196 | | -</details> |
197 | | - |
198 | 175 |
|
199 | 176 | <details><summary>Emphasis</summary> |
200 | 177 | <p> |
@@ -256,14 +233,10 @@ And some additional, less used options: |
256 | 233 | 2. Consectetur adipiscing elit |
257 | 234 | 3. Integer molestie lorem at massa |
258 | 235 |
|
259 | | -
|
260 | | - 1. You can use sequential numbers... |
261 | | - 1. ...or keep all the numbers as `1.` |
262 | | -
|
263 | 236 | Start numbering with offset: |
264 | 237 |
|
265 | 238 | 57. foo |
266 | | - 1. bar |
| 239 | + 58. bar |
267 | 240 | ``` |
268 | 241 |
|
269 | 242 | | iOS | Android |
@@ -380,6 +353,30 @@ And some additional, less used options: |
380 | 353 | </p> |
381 | 354 | </details> |
382 | 355 |
|
| 356 | + |
| 357 | +<details><summary>Typographic Replacements</summary> |
| 358 | +<p> |
| 359 | + |
| 360 | +``` |
| 361 | + Enable typographer option to see result. |
| 362 | +
|
| 363 | + (c) (C) (r) (R) (tm) (TM) (p) (P) +- |
| 364 | +
|
| 365 | + test.. test... test..... test?..... test!.... |
| 366 | +
|
| 367 | + !!!!!! ???? ,, -- --- |
| 368 | +
|
| 369 | + "Smartypants, double quotes" and 'single quotes' |
| 370 | +``` |
| 371 | + |
| 372 | +| iOS | Android |
| 373 | +| --- | --- |
| 374 | +| <img src="https://github.com/iamacup/react-native-markdown-display/raw/master/doc/images/ios-3.png"/> | <img src="https://github.com/iamacup/react-native-markdown-display/raw/master/doc/images/android-3.png"/> |
| 375 | + |
| 376 | +</p> |
| 377 | +</details> |
| 378 | + |
| 379 | + |
383 | 380 | <details><summary>Plugins and Extensions</summary> |
384 | 381 | <p> |
385 | 382 |
|
@@ -417,19 +414,6 @@ Horizontal Rules |
417 | 414 | Some text below |
418 | 415 |
|
419 | 416 |
|
420 | | -Typographic Replacements |
421 | | -
|
422 | | - Enable typographer option to see result. |
423 | | -
|
424 | | - (c) (C) (r) (R) (tm) (TM) (p) (P) +- |
425 | | -
|
426 | | - test.. test... test..... test?..... test!.... |
427 | | -
|
428 | | - !!!!!! ???? ,, -- --- |
429 | | -
|
430 | | - "Smartypants, double quotes" and 'single quotes' |
431 | | -
|
432 | | -
|
433 | 417 | Emphasis |
434 | 418 |
|
435 | 419 | **This is bold text** |
@@ -468,14 +452,10 @@ Lists |
468 | 452 | 2. Consectetur adipiscing elit |
469 | 453 | 3. Integer molestie lorem at massa |
470 | 454 |
|
471 | | -
|
472 | | - 1. You can use sequential numbers... |
473 | | - 1. ...or keep all the numbers as `1.` |
474 | | -
|
475 | 455 | Start numbering with offset: |
476 | 456 |
|
477 | 457 | 57. foo |
478 | | - 1. bar |
| 458 | + 58. bar |
479 | 459 |
|
480 | 460 |
|
481 | 461 | Code |
@@ -545,77 +525,33 @@ Images |
545 | 525 | With a reference later in the document defining the URL location: |
546 | 526 |
|
547 | 527 | [id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat" |
548 | | -``` |
549 | 528 |
|
550 | | -</p> |
551 | | -</details> |
552 | | - |
553 | | - |
554 | | -# Rules |
555 | | - |
556 | | -Rules are used to specify how you want certain elements to be displayed. The existing implementation is [here](https://github.com/iamacup/react-native-markdown-display/blob/master/src/lib/renderRules.js) |
557 | 529 |
|
558 | | -The list of rules that can be overwritten is: |
559 | | - |
560 | | -```["root" "unknown", "textgroup", "inline", "text", "span", "strong", "s", "link", "blocklink", "em", "heading1", "heading2", "heading3", "heading4", "heading5", "heading6", "paragraph", "hardbreak", "blockquote", "code_inline", "code_block", "fence", "pre", "bullet_list", "ordered_list", "list_item", "table", "thead", "tbody", "th", "tr", "td", "hr", "softbreak", "image"]``` |
| 530 | +Typographic Replacements |
561 | 531 |
|
562 | | -<details><summary>Example Implementation</summary> |
563 | | -<p> |
| 532 | + Enable typographer option to see result. |
564 | 533 |
|
565 | | -```jsx |
566 | | -import react from 'react'; |
567 | | -import {View, PureComponent, Text} from 'react-native'; |
568 | | -import Markdown, {getUniqueID} from 'react-native-markdown-display'; |
| 534 | + (c) (C) (r) (R) (tm) (TM) (p) (P) +- |
569 | 535 |
|
570 | | -const rules = { |
571 | | - heading1: (node, children, parent, styles) => |
572 | | - <Text key={getUniqueID()} style={[styles.heading, styles.heading1]}> |
573 | | - [{children}] |
574 | | - </Text>, |
575 | | - heading2: (node, children, parent, styles) => |
576 | | - <Text key={getUniqueID()} style={[styles.heading, styles.heading2]}> |
577 | | - [{children}] |
578 | | - </Text>, |
579 | | - heading3: (node, children, parent, styles) => |
580 | | - <Text key={getUniqueID()} style={[styles.heading, styles.heading3]}> |
581 | | - [{children}] |
582 | | - </Text>, |
583 | | -}; |
| 536 | + test.. test... test..... test?..... test!.... |
584 | 537 |
|
585 | | -const copy = ` |
586 | | -# h1 Heading 8-) |
587 | | -## h2 Heading 8-) |
588 | | -### h3 Heading 8-) |
| 538 | + !!!!!! ???? ,, -- --- |
589 | 539 |
|
590 | | -| Option | Description | |
591 | | -| ------ | ----------- | |
592 | | -| data | path to data files to supply the data that will be passed into templates. | |
593 | | -| engine | engine to be used for processing templates. Handlebars is the default. | |
594 | | -| ext | extension to be used for dest files. | |
595 | | -`; |
| 540 | + "Smartypants, double quotes" and 'single quotes' |
596 | 541 |
|
597 | | -export default class Page extends PureComponent { |
598 | | - render() { |
599 | | - return ( |
600 | | - <Markdown rules={rules}>{copy}</Markdown> |
601 | | - ); |
602 | | - } |
603 | | -} |
604 | 542 | ``` |
605 | 543 |
|
606 | 544 | </p> |
607 | 545 | </details> |
608 | 546 |
|
609 | 547 |
|
610 | | -# Style |
611 | | - |
612 | | -Styles are used to override how certain rules are styled. The existing implementation is [here](https://github.com/iamacup/react-native-markdown-display/blob/master/src/lib/styles.js) |
| 548 | +# Rules and Styles |
613 | 549 |
|
614 | | -The list of styles that can be overwritten is: |
| 550 | +### Styles |
615 | 551 |
|
616 | | -```["root", "codeBlock", "codeInline", "em", "headingContainer", "heading", "heading1", "heading2", "heading3", "heading4", "heading5", "heading6", "hr", "blockquote", "list", "listItem", "listUnordered", "listUnorderedItem", "listUnorderedItemIcon", "listOrdered", "listOrderedItem", "listOrderedItemIcon", "paragraph", "hardbreak", "strong", "table", "tableHeader", "tableHeaderCell", "tableRow", "tableRowCell", "text", "textGroup", "strikethrough", "link", "blocklink", "image"]``` |
| 552 | +Styles are used to override how certain rules are styled. The existing implementation is [here](https://github.com/iamacup/react-native-markdown-display/blob/master/src/lib/styles.js) |
617 | 553 |
|
618 | | -**NOTE:** If you specify a style property, it will completely overwrite existing styles for that property **UNLESS** you specify `mergeStyle` as true, in which case a merge will take place. |
| 554 | +**NOTE:** By default styles are merged with the existing implementation, to change this, see `mergeStyle` |
619 | 555 |
|
620 | 556 | <details><summary>Example Implementation</summary> |
621 | 557 | <p> |
@@ -677,6 +613,97 @@ export default class Page extends PureComponent { |
677 | 613 | </p> |
678 | 614 | </details> |
679 | 615 |
|
| 616 | +### Rules |
| 617 | + |
| 618 | +Rules are used to specify how you want certain elements to be displayed. The existing implementation is [here](https://github.com/iamacup/react-native-markdown-display/blob/master/src/lib/renderRules.js) |
| 619 | + |
| 620 | +<details><summary>Example Implementation</summary> |
| 621 | +<p> |
| 622 | + |
| 623 | +```jsx |
| 624 | +import react from 'react'; |
| 625 | +import {View, PureComponent, Text} from 'react-native'; |
| 626 | +import Markdown, {getUniqueID} from 'react-native-markdown-display'; |
| 627 | + |
| 628 | +const rules = { |
| 629 | + heading1: (node, children, parent, styles) => |
| 630 | + <Text key={getUniqueID()} style={[styles.heading, styles.heading1]}> |
| 631 | + [{children}] |
| 632 | + </Text>, |
| 633 | + heading2: (node, children, parent, styles) => |
| 634 | + <Text key={getUniqueID()} style={[styles.heading, styles.heading2]}> |
| 635 | + [{children}] |
| 636 | + </Text>, |
| 637 | + heading3: (node, children, parent, styles) => |
| 638 | + <Text key={getUniqueID()} style={[styles.heading, styles.heading3]}> |
| 639 | + [{children}] |
| 640 | + </Text>, |
| 641 | +}; |
| 642 | + |
| 643 | +const copy = ` |
| 644 | +# h1 Heading 8-) |
| 645 | +## h2 Heading 8-) |
| 646 | +### h3 Heading 8-) |
| 647 | +
|
| 648 | +| Option | Description | |
| 649 | +| ------ | ----------- | |
| 650 | +| data | path to data files to supply the data that will be passed into templates. | |
| 651 | +| engine | engine to be used for processing templates. Handlebars is the default. | |
| 652 | +| ext | extension to be used for dest files. | |
| 653 | +`; |
| 654 | + |
| 655 | +export default class Page extends PureComponent { |
| 656 | + render() { |
| 657 | + return ( |
| 658 | + <Markdown rules={rules}>{copy}</Markdown> |
| 659 | + ); |
| 660 | + } |
| 661 | +} |
| 662 | +``` |
| 663 | + |
| 664 | +</p> |
| 665 | +</details> |
| 666 | + |
| 667 | + |
| 668 | +### All rules and their associated styles: |
| 669 | + |
| 670 | +| Render Rule | Style(s) | |
| 671 | +| ------ | ----------- | |
| 672 | +| `body` | `body` | |
| 673 | +| `heading1` | `heading1` | |
| 674 | +| `heading2` | `heading2` | |
| 675 | +| `heading3` | `heading3` | |
| 676 | +| `heading4` | `heading4` | |
| 677 | +| `heading5` | `heading5` | |
| 678 | +| `heading6` | `heading6` | |
| 679 | +| `hr` | `hr` | |
| 680 | +| `strong` | `strong` | |
| 681 | +| `em` | `em` | |
| 682 | +| `s` | `s` | |
| 683 | +| `blockquote` | `blockquote` | |
| 684 | +| `bullet_list` | `bullet_list` | |
| 685 | +| `ordered_list` | `ordered_list` | |
| 686 | +| `list_item` | `list_item` - This is a special case that contains a set of pseudo classes that don't align to the render rule: `ordered_list_icon`, `ordered_list_content`, `bullet_list_icon`, `bullet_list_content` | |
| 687 | +| `code_inline` | `code_inline` | |
| 688 | +| `code_block` | `code_block` | |
| 689 | +| `fence` | `fence` | |
| 690 | +| `table` | `table` | |
| 691 | +| `thead` | `thead` | |
| 692 | +| `tbody` | `tbody` | |
| 693 | +| `th` | `th` | |
| 694 | +| `tr` | `tr` | |
| 695 | +| `td` | `td` | |
| 696 | +| `link` | `link` | |
| 697 | +| `blocklink` | `blocklink` | |
| 698 | +| `image` | `image` | |
| 699 | +| `text` | `text` | |
| 700 | +| `textgroup` | `textgroup` | |
| 701 | +| `paragraph` | `paragraph` | |
| 702 | +| `hardbreak` | `hardbreak` | |
| 703 | +| `softbreak` | `softbreak` | |
| 704 | +| `pre` | `pre` | |
| 705 | +| `inline` | `inline` | |
| 706 | +| `span` | `span` | |
680 | 707 |
|
681 | 708 | # Handling Links |
682 | 709 |
|
|
0 commit comments