@@ -36,6 +36,7 @@ function compiler(options) {
36
36
var settings = options || { }
37
37
var config = configure (
38
38
{
39
+ transforms : [ ] ,
39
40
canContainEols : [
40
41
'emphasis' ,
41
42
'fragment' ,
@@ -145,7 +146,8 @@ function compiler(options) {
145
146
return compile
146
147
147
148
function compile ( events ) {
148
- var stack = [ { type : 'root' , children : [ ] } ]
149
+ var tree = { type : 'root' , children : [ ] }
150
+ var stack = [ tree ]
149
151
var tokenStack = [ ]
150
152
var listStack = [ ]
151
153
var index = - 1
@@ -207,7 +209,7 @@ function compiler(options) {
207
209
}
208
210
209
211
// Figure out `root` position.
210
- stack [ 0 ] . position = {
212
+ tree . position = {
211
213
start : point (
212
214
events . length ? events [ 0 ] [ 1 ] . start : { line : 1 , column : 1 , offset : 0 }
213
215
) ,
@@ -218,7 +220,12 @@ function compiler(options) {
218
220
)
219
221
}
220
222
221
- return stack [ 0 ]
223
+ index = - 1
224
+ while ( ++ index < config . transforms . length ) {
225
+ tree = config . transforms [ index ] ( tree ) || tree
226
+ }
227
+
228
+ return tree
222
229
}
223
230
224
231
function prepareList ( events , start , length ) {
@@ -803,7 +810,7 @@ function extension(config, extension) {
803
810
for ( key in extension ) {
804
811
left = own . call ( config , key ) ? config [ key ] : ( config [ key ] = { } )
805
812
806
- if ( key === 'canContainEols' ) {
813
+ if ( key === 'canContainEols' || key === 'transforms' ) {
807
814
config [ key ] = [ ] . concat ( left , extension [ key ] )
808
815
} else {
809
816
Object . assign ( left , extension [ key ] )
0 commit comments