@@ -518,6 +518,16 @@ Renderer.prototype._buildTreeForAllChildren = function(node) {
518518 this . _buildTree ( children [ ci ] ) ;
519519} ;
520520
521+ // The comment nodes at the beginning of blockNode are comments for controls
522+ // Thus they should be rendered out of block
523+ Renderer . prototype . _buildCommentsFromBlock = function ( blockNode ) {
524+ var children = blockNode . children ;
525+ while ( children . length > 0 && children [ 0 ] . type === 'comment' ) {
526+ var commentNode = children . shift ( ) ;
527+ this . _buildTree ( commentNode ) ;
528+ }
529+ }
530+
521531Renderer . prototype . _buildTree = function ( node ) {
522532 var ci , child , textNode ;
523533 switch ( node . type ) {
@@ -590,6 +600,7 @@ Renderer.prototype._buildTree = function(node) {
590600 this . _buildTree ( textNode ) ;
591601 this . _typeText ( ')' ) ;
592602
603+ this . _buildCommentsFromBlock ( blockNode ) ;
593604 this . _buildTree ( blockNode ) ;
594605
595606 if ( ! this . _options . noEnd ) {
@@ -612,6 +623,7 @@ Renderer.prototype._buildTree = function(node) {
612623 this . _typeKeyword ( ' then' ) ;
613624 // <block>
614625 var ifBlock = node . children [ 1 ] ;
626+ this . _buildCommentsFromBlock ( ifBlock ) ;
615627 this . _buildTree ( ifBlock ) ;
616628
617629 // ( \ELIF {<cond>} <block> )[0..n]
@@ -632,6 +644,7 @@ Renderer.prototype._buildTree = function(node) {
632644
633645 // <block>
634646 var elifBlock = node . children [ 2 + 2 * ei + 1 ] ;
647+ this . _buildCommentsFromBlock ( elifBlock ) ;
635648 this . _buildTree ( elifBlock ) ;
636649 }
637650
@@ -648,6 +661,7 @@ Renderer.prototype._buildTree = function(node) {
648661
649662 // <block>
650663 var elseBlock = node . children [ node . children . length - 1 ] ;
664+ this . _buildCommentsFromBlock ( elseBlock ) ;
651665 this . _buildTree ( elseBlock ) ;
652666 }
653667
@@ -679,6 +693,7 @@ Renderer.prototype._buildTree = function(node) {
679693
680694 // <block>
681695 var block = node . children [ 1 ] ;
696+ this . _buildCommentsFromBlock ( block ) ;
682697 this . _buildTree ( block ) ;
683698
684699 if ( ! this . _options . noEnd ) {
0 commit comments