File tree Expand file tree Collapse file tree 3 files changed +26
-12
lines changed
Expand file tree Collapse file tree 3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -406,19 +406,21 @@ const description = {
406406 return ` \n <dt>${ this .parser .parseInline (token .dt )} </dt><dd>${ this .parser .parseInline (token .dd )} </dd>` ;
407407 },
408408 childTokens: [' dt' , ' dd' ], // Any child tokens to be visited by walkTokens
409- walkTokens (token ) { // Post-processing on the completed token tree
410- if (token .type === ' strong' ) {
411- token .text += ' walked' ;
412- }
413- }
414409};
415410
416- marked .use ({ extensions: [descriptionlist, description] });
411+ function walkTokens (token ) { // Post-processing on the completed token tree
412+ if (token .type === ' strong' ) {
413+ token .text += ' walked' ;
414+ token .tokens = this .Lexer .lexInline (token .text )
415+ }
416+ }
417+ marked .use ({ extensions: [descriptionlist, description], walkTokens });
417418
418- \\ EQUIVALENT TO :
419+ // EQUIVALENT TO:
419420
420- marked .use ({extensions: [descriptionList] });
421- marked .use ({extensions: [description] });
421+ marked .use ({ extensions: [descriptionList] });
422+ marked .use ({ extensions: [description] });
423+ marked .use ({ walkTokens })
422424
423425console .log (marked (' A Description List:\n '
424426 + ' : Topic 1 : Description 1\n '
Original file line number Diff line number Diff line change @@ -235,10 +235,10 @@ marked.use = function(...args) {
235235 // ==-- Parse WalkTokens extensions --== //
236236 if ( pack . walkTokens ) {
237237 const walkTokens = marked . defaults . walkTokens ;
238- opts . walkTokens = ( token ) => {
238+ opts . walkTokens = function ( token ) {
239239 pack . walkTokens . call ( this , token ) ;
240240 if ( walkTokens ) {
241- walkTokens ( token ) ;
241+ walkTokens . call ( this , token ) ;
242242 }
243243 } ;
244244 }
@@ -257,7 +257,7 @@ marked.use = function(...args) {
257257
258258marked . walkTokens = function ( tokens , callback ) {
259259 for ( const token of tokens ) {
260- callback ( token ) ;
260+ callback . call ( marked , token ) ;
261261 switch ( token . type ) {
262262 case 'table' : {
263263 for ( const cell of token . header ) {
Original file line number Diff line number Diff line change @@ -1046,4 +1046,16 @@ br
10461046 [ 'text' , 'br' ]
10471047 ] ) ;
10481048 } ) ;
1049+
1050+ it ( 'should asign marked to `this`' , ( ) => {
1051+ marked . use ( {
1052+ walkTokens ( token ) {
1053+ if ( token . type === 'em' ) {
1054+ token . text += ' walked' ;
1055+ token . tokens = this . Lexer . lexInline ( token . text ) ;
1056+ }
1057+ }
1058+ } ) ;
1059+ expect ( marked ( '*text*' ) . trim ( ) ) . toBe ( '<p><em>text walked</em></p>' ) ;
1060+ } ) ;
10491061} ) ;
You can’t perform that action at this time.
0 commit comments