@@ -75,18 +75,37 @@ export default class AstRenderer {
75
75
return this . renderNode ( value , parents ) ;
76
76
} ) ;
77
77
78
- // text node type is a special case because it is always the 'last' element in a chain
78
+ // render any special types of nodes that have different renderRule function signatures
79
79
80
- if (
81
- node . type === 'text' ||
82
- node . type === 'list_item' ||
83
- node . type === 'code_inline' ||
84
- node . type === 'code_block' ||
85
- node . type === 'fence'
86
- ) {
87
- // we build up a style object for text types, this effectively grabs the styles from parents and
88
- // applies them in order of priority parent (most) to child (least) priority
89
- // so that if we overwride the text style, it does not overwrite a header1 style, for instance.
80
+ if ( node . type === 'link' || node . type === 'blocklink' ) {
81
+ return renderFunction (
82
+ node ,
83
+ children ,
84
+ parentNodes ,
85
+ this . _style ,
86
+ this . _onLinkPress ,
87
+ ) ;
88
+ }
89
+
90
+ if ( node . type === 'image' ) {
91
+ return renderFunction (
92
+ node ,
93
+ children ,
94
+ parentNodes ,
95
+ this . _style ,
96
+ this . _allowedImageHandlers ,
97
+ this . _defaultImageHandler ,
98
+ ) ;
99
+ }
100
+
101
+ // We are at the bottom of some tree - grab all the parent styles
102
+ // this effectively grabs the styles from parents and
103
+ // applies them in order of priority parent (least) to child (most)
104
+ // to allow styling global, then lower down things individually
105
+
106
+ // we have to handle list_item seperately here because they have some child
107
+ // pseudo classes that need the additional style props from parents passed down to them
108
+ if ( children . length === 0 || node . type === 'list_item' ) {
90
109
const styleObj = { } ;
91
110
92
111
for ( let a = parentNodes . length - 1 ; a > - 1 ; a -- ) {
@@ -107,6 +126,22 @@ export default class AstRenderer {
107
126
...refStyle ,
108
127
...StyleSheet . flatten ( this . _style [ parentNodes [ a ] . type ] ) ,
109
128
} ;
129
+
130
+ // workaround for list_items and their content cascading down the tree
131
+ if ( parentNodes [ a ] . type === 'list_item' ) {
132
+ let contentStyle = { } ;
133
+
134
+ if ( parentNodes [ a + 1 ] . type === 'bullet_list' ) {
135
+ contentStyle = this . _style . bullet_list_content ;
136
+ } else if ( parentNodes [ a + 1 ] . type === 'ordered_list' ) {
137
+ contentStyle = this . _style . ordered_list_content ;
138
+ }
139
+
140
+ refStyle = {
141
+ ...refStyle ,
142
+ ...StyleSheet . flatten ( contentStyle ) ,
143
+ } ;
144
+ }
110
145
}
111
146
112
147
// then work out if any of them are text styles that should be used in the end.
@@ -122,29 +157,6 @@ export default class AstRenderer {
122
157
return renderFunction ( node , children , parentNodes , this . _style , styleObj ) ;
123
158
}
124
159
125
- // render any special types of nodes that have different renderRule function signatures
126
-
127
- if ( node . type === 'link' || node . type === 'blocklink' ) {
128
- return renderFunction (
129
- node ,
130
- children ,
131
- parentNodes ,
132
- this . _style ,
133
- this . _onLinkPress ,
134
- ) ;
135
- }
136
-
137
- if ( node . type === 'image' ) {
138
- return renderFunction (
139
- node ,
140
- children ,
141
- parentNodes ,
142
- this . _style ,
143
- this . _allowedImageHandlers ,
144
- this . _defaultImageHandler ,
145
- ) ;
146
- }
147
-
148
160
// cull top level children
149
161
150
162
if (
@@ -167,7 +179,7 @@ export default class AstRenderer {
167
179
* @return {* }
168
180
*/
169
181
render = nodes => {
170
- const root = { type : 'root ' , key : getUniqueID ( ) , children : nodes } ;
182
+ const root = { type : 'body ' , key : getUniqueID ( ) , children : nodes } ;
171
183
return this . renderNode ( root , [ ] , true ) ;
172
184
} ;
173
185
}
0 commit comments