nl_tokens: Main function that looks for a tabstops in provided <code > text< / code > and returns a processed version of <code > text< / code > with expanded placeholders and list of tabstops found . @param { String } text Text to process @param { Object } options List of processor options : <br >
pl_tokens: function ( text , options ) { // prepare defaults var utils = require ( 'utils' ) ; var placeholders = { carets : '' } ; var marks = [ ] ; options = _ . extend ( { } , defaultOptions , options , { tabstop : function ( data ) { var token = data . token ; var ret = '' ; if ( data . placeholder == 'cursor' ) { marks . push ( { start : data . start , end : data . start + token . length , group : 'carets' , value : '' } ) ; } else { // unify placeholder value for single group if ( 'placeholder' in data ) placeholders [ data . group ] = data . placeholder ; if ( data . group in placeholders ) ret = placeholders [ data . group ] ; marks . push ( { start : data . start , end : data . start + token . length , group : data . group , value : ret } ) ; } return token ; } } ) ; if ( options . replaceCarets ) { text = text . replace ( new RegExp ( utils . escapeForRegexp ( utils . getCaretPlaceholder ( ) ) , 'g' ) , '${0:cursor}' ) ; } // locate tabstops and unify group's placeholders text = this . processText ( text , options ) ; // now, replace all tabstops with placeholders var buf = utils . stringBuilder ( ) , lastIx = 0 ; var tabStops = _ . map ( marks , function ( mark ) { buf . append ( text . substring ( lastIx , mark . start ) ) ; var pos = buf . length ; var ph = placeholders [ mark . group ] || '' ; buf . append ( ph ) ; lastIx = mark . end ; return { group : mark . group , start : pos , end : <mask> + ph . length } ; } ) ; buf . append ( text . substring ( lastIx ) ) ; return { text : buf . toString ( ) , tabstops : _ . sortBy ( tabStops , 'start' ) } ; }