Skip to content

Commit 755c17b

Browse files
authored
Merge pull request #57 from iamacup/render-rework
Render rework
2 parents f92295a + 72ecfbb commit 755c17b

File tree

87 files changed

+459
-11032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+459
-11032
lines changed

README.md

Lines changed: 131 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# React Native Markdown Display [![npm version](https://badge.fury.io/js/react-native-markdown-display.svg)](https://badge.fury.io/js/react-native-markdown-display) [![Known Vulnerabilities](https://snyk.io/test/github/iamacup/react-native-markdown-display/badge.svg)](https://snyk.io/test/github/iamacup/react-native-markdown-display)
22

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.
54

65
### Compatibility with react-native-markdown-renderer
76

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)
98

109
### Install
1110

@@ -46,9 +45,9 @@ export default class Page extends PureComponent {
4645

4746
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.
4847

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.
5049

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.
5251

5352

5453
<details><summary>Example</summary>
@@ -173,28 +172,6 @@ And some additional, less used options:
173172
</details>
174173

175174

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-
198175

199176
<details><summary>Emphasis</summary>
200177
<p>
@@ -256,14 +233,10 @@ And some additional, less used options:
256233
2. Consectetur adipiscing elit
257234
3. Integer molestie lorem at massa
258235
259-
260-
1. You can use sequential numbers...
261-
1. ...or keep all the numbers as `1.`
262-
263236
Start numbering with offset:
264237
265238
57. foo
266-
1. bar
239+
58. bar
267240
```
268241

269242
| iOS | Android
@@ -380,6 +353,30 @@ And some additional, less used options:
380353
</p>
381354
</details>
382355

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+
383380
<details><summary>Plugins and Extensions</summary>
384381
<p>
385382

@@ -417,19 +414,6 @@ Horizontal Rules
417414
Some text below
418415
419416
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-
433417
Emphasis
434418
435419
**This is bold text**
@@ -468,14 +452,10 @@ Lists
468452
2. Consectetur adipiscing elit
469453
3. Integer molestie lorem at massa
470454
471-
472-
1. You can use sequential numbers...
473-
1. ...or keep all the numbers as `1.`
474-
475455
Start numbering with offset:
476456
477457
57. foo
478-
1. bar
458+
58. bar
479459
480460
481461
Code
@@ -545,77 +525,33 @@ Images
545525
With a reference later in the document defining the URL location:
546526
547527
[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"
548-
```
549528
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)
557529
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
561531
562-
<details><summary>Example Implementation</summary>
563-
<p>
532+
Enable typographer option to see result.
564533
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) +-
569535
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!....
584537
585-
const copy = `
586-
# h1 Heading 8-)
587-
## h2 Heading 8-)
588-
### h3 Heading 8-)
538+
!!!!!! ???? ,, -- ---
589539
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'
596541
597-
export default class Page extends PureComponent {
598-
render() {
599-
return (
600-
<Markdown rules={rules}>{copy}</Markdown>
601-
);
602-
}
603-
}
604542
```
605543

606544
</p>
607545
</details>
608546

609547

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
613549

614-
The list of styles that can be overwritten is:
550+
### Styles
615551

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)
617553

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`
619555

620556
<details><summary>Example Implementation</summary>
621557
<p>
@@ -677,6 +613,97 @@ export default class Page extends PureComponent {
677613
</p>
678614
</details>
679615

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` |
680707

681708
# Handling Links
682709

doc/images/android-6.png

-12.5 KB
Loading

doc/images/ios-6.png

-16.2 KB
Loading

doc/simple-with-custom-renderer.md

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)