@@ -6,22 +6,26 @@ import Markdown, {
66 renderRules ,
77 getUniqueID ,
88} from 'react-native-markdown-renderer' ;
9- import copyAll from "./src/copyAll" ;
10- import customMarkdownStyle from "./src/customMarkdownStyle" ;
9+ import copyAll from './src/copyAll' ;
10+ import customMarkdownStyle from './src/customMarkdownStyle' ;
11+
12+ const rules = {
13+ h1 : ( node , children , parents ) => {
14+ return < Text key = { getUniqueID ( ) } style = { { backgroundColor : 'red' } } > { children } </ Text > ;
15+ } ,
16+ // added custom block element defined by plugin
17+ block : ( node , children , parents ) => {
18+ return < Text key = { getUniqueID ( ) } style = { { backgroundColor : 'green' } } > { children } </ Text > ;
19+ } ,
20+ } ;
1121
1222/**
1323 * i'm overriding the default h1 render function.
1424 */
1525const renderer = new AstRenderer (
1626 {
1727 ...renderRules ,
18- h1 : ( node , children , parents ) => {
19- return < Text key = { getUniqueID ( ) } style = { { backgroundColor : 'red' } } > { children } </ Text > ;
20- } ,
21- // added custom block element defined by plugin
22- block : ( node , children , parents ) => {
23- return < Text key = { getUniqueID ( ) } style = { { backgroundColor : 'green' } } > { children } </ Text > ;
24- } ,
28+ ...rules ,
2529 } ,
2630 styles
2731) ;
@@ -32,13 +36,14 @@ export default class App extends Component {
3236 } ;
3337
3438 list = [
35- { description : 'default' } ,
36- { description : 'custom renderer' } ,
37- { description : 'custom style sheet' }
38- ] ;
39+ { description : 'default' } ,
40+ { description : 'custom renderer' } ,
41+ { description : 'custom style sheet' } ,
42+ { description : 'custom rules' } ,
43+ { description : 'custom rules & style sheet' } ,
44+ ] ;
3945
4046 getView ( value ) {
41-
4247 switch ( value ) {
4348 case 0 : {
4449 return < Markdown children = { copyAll } /> ;
@@ -49,25 +54,28 @@ export default class App extends Component {
4954 case 2 : {
5055 return < Markdown style = { customMarkdownStyle } children = { copyAll } /> ;
5156 }
57+ case 3 : {
58+ return < Markdown rules = { rules } children = { copyAll } /> ;
59+ }
60+ case 4 : {
61+ return < Markdown rules = { rules } style = { customMarkdownStyle } children = { copyAll } /> ;
62+ }
5263 default : {
53- return (
54- < Markdown > # Text</ Markdown >
55- ) ;
64+ return < Markdown > # Text</ Markdown > ;
5665 }
5766 }
5867 }
5968
6069 render ( ) {
61-
62-
63-
6470 return (
6571 < View style = { styleSheet . container } >
6672 < Picker
6773 selectedValue = { this . state . view }
6874 onValueChange = { ( itemValue , itemIndex ) => this . setState ( { view : itemIndex } ) }
6975 >
70- { this . list . map ( ( val , index ) => < Picker . Item key = { val . description } label = { val . description } value = { index } /> ) }
76+ { this . list . map ( ( val , index ) =>
77+ < Picker . Item key = { val . description } label = { val . description } value = { index } />
78+ ) }
7179 </ Picker >
7280
7381 < ScrollView >
0 commit comments