1- import React , { Component } from ' react' ;
2- import { StyleSheet , Text , View , ScrollView , Picker } from ' react-native' ;
1+ import React , { Component } from " react" ;
2+ import { StyleSheet , Text , View , ScrollView , Picker } from " react-native" ;
33import Markdown , {
4- AstRenderer ,
5- styles ,
6- renderRules ,
7- getUniqueID , PluginContainer ,
8- } from 'react-native-markdown-renderer' ;
9- import markdownItCheckbox from 'markdown-it-checkbox' ;
10- import copyAll from './src/copyAll' ;
11- import customMarkdownStyle from './src/customMarkdownStyle' ;
4+ AstRenderer ,
5+ styles ,
6+ renderRules ,
7+ getUniqueID ,
8+ PluginContainer
9+ } from "./react-native-markdown-renderer" ;
10+
11+ import markdownItCheckbox from "markdown-it-checkbox" ;
12+ import copyAll from "./src/copyAll" ;
13+ import customMarkdownStyle from "./src/customMarkdownStyle" ;
1214import copyAllCheckboxPlugin from "./src/copyAllCheckboxPlugin" ;
1315import pluginRules from "./src/pluginRules" ;
1416
1517const rules = {
16- h1 : ( node , children , parents ) => {
17- return < Text key = { getUniqueID ( ) } style = { { backgroundColor : 'red' } } > { children } </ Text > ;
18+ header1 : ( node , children , parents , style ) => {
19+ return (
20+ < Text key = { getUniqueID ( ) } style = { { backgroundColor : "red" } } >
21+ { children }
22+ </ Text >
23+ ) ;
1824 } ,
1925 // added custom block element defined by plugin
20- block : ( node , children , parents ) => {
21- return < Text key = { getUniqueID ( ) } style = { { backgroundColor : 'green' } } > { children } </ Text > ;
26+ block : ( node , children , parents , style ) => {
27+ return (
28+ < Text key = { getUniqueID ( ) } style = { { backgroundColor : "green" } } >
29+ { children }
30+ </ Text >
31+ ) ;
2232 } ,
33+
34+ checkbox : ( node , children , parents , style ) => {
35+ return (
36+ < Text key = { getUniqueID ( ) } style = { { backgroundColor : "green" } } >
37+ { children }
38+ </ Text >
39+ ) ;
40+ }
2341} ;
2442
2543/**
@@ -28,23 +46,23 @@ const rules = {
2846const renderer = new AstRenderer (
2947 {
3048 ...renderRules ,
31- ...rules ,
49+ ...rules
3250 } ,
3351 styles
3452) ;
3553
3654export default class App extends Component {
3755 state = {
38- view : 5 ,
56+ view : 5
3957 } ;
4058
4159 list = [
42- { description : ' default' } ,
43- { description : ' custom renderer' } ,
44- { description : ' custom style sheet' } ,
45- { description : ' custom rules' } ,
46- { description : ' custom rules & styles' } ,
47- { description : ' plugins (checkbox)' } ,
60+ { description : " default" } ,
61+ { description : " custom renderer" } ,
62+ { description : " custom style sheet" } ,
63+ { description : " custom rules" } ,
64+ { description : " custom rules & styles" } ,
65+ { description : " plugins (checkbox)" }
4866 ] ;
4967
5068 getView ( value ) {
@@ -62,10 +80,25 @@ export default class App extends Component {
6280 return < Markdown rules = { rules } children = { copyAll } /> ;
6381 }
6482 case 4 : {
65- return < Markdown rules = { rules } style = { customMarkdownStyle } children = { copyAll } /> ;
83+ return (
84+ < Markdown
85+ rules = { rules }
86+ style = { customMarkdownStyle }
87+ children = { copyAll }
88+ />
89+ ) ;
6690 }
6791 case 5 : {
68- return < Markdown rules = { pluginRules } plugins = { [ new PluginContainer ( markdownItCheckbox , { divWrap : true } ) ] } style = { customMarkdownStyle } children = { copyAllCheckboxPlugin } /> ;
92+ return (
93+ < Markdown
94+ rules = { pluginRules }
95+ plugins = { [
96+ new PluginContainer ( markdownItCheckbox , { divWrap : true } )
97+ ] }
98+ style = { customMarkdownStyle }
99+ children = { copyAllCheckboxPlugin }
100+ />
101+ ) ;
69102 }
70103 default : {
71104 return < Markdown > # Text</ Markdown > ;
@@ -78,16 +111,20 @@ export default class App extends Component {
78111 < View style = { styleSheet . container } >
79112 < Picker
80113 selectedValue = { this . state . view }
81- onValueChange = { ( itemValue , itemIndex ) => this . setState ( { view : itemIndex } ) }
114+ onValueChange = { ( itemValue , itemIndex ) =>
115+ this . setState ( { view : itemIndex } )
116+ }
82117 >
83- { this . list . map ( ( val , index ) =>
84- < Picker . Item key = { val . description } label = { val . description } value = { index } />
85- ) }
118+ { this . list . map ( ( val , index ) => (
119+ < Picker . Item
120+ key = { val . description }
121+ label = { val . description }
122+ value = { index }
123+ />
124+ ) ) }
86125 </ Picker >
87126
88- < ScrollView >
89- { this . getView ( this . state . view ) }
90- </ ScrollView >
127+ < ScrollView > { this . getView ( this . state . view ) } </ ScrollView >
91128 </ View >
92129 ) ;
93130 }
@@ -96,6 +133,6 @@ export default class App extends Component {
96133const styleSheet = StyleSheet . create ( {
97134 container : {
98135 flex : 1 ,
99- marginTop : 20 ,
100- } ,
136+ marginTop : 20
137+ }
101138} ) ;
0 commit comments