| 
									
										
										
										
											2015-09-15 23:21:55 -07:00
										 |  |  | var _ = require('lodash'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @dgProcessor checkUnbalancedBackTicks | 
					
						
							|  |  |  |  * @description | 
					
						
							|  |  |  |  * Searches the rendered content for an odd number of (```) backticks,
 | 
					
						
							|  |  |  |  * which would indicate an unbalanced pair and potentially a typo in the | 
					
						
							|  |  |  |  * source content. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | module.exports = function checkUnbalancedBackTicks(log, createDocMessage) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var BACKTICK_REGEX = /^ *```/gm; | 
					
						
							| 
									
										
										
										
											2015-10-16 09:03:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-15 23:21:55 -07:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2015-10-16 09:03:54 -07:00
										 |  |  |     // $runAfter: ['checkAnchorLinksProcessor'],
 | 
					
						
							|  |  |  |     $runAfter: ['inlineTagProcessor'], | 
					
						
							|  |  |  |     $runBefore: ['writeFilesProcessor'], | 
					
						
							| 
									
										
										
										
											2015-09-15 23:21:55 -07:00
										 |  |  |     $process: function(docs) { | 
					
						
							|  |  |  |       _.forEach(docs, function(doc) { | 
					
						
							|  |  |  |         if ( doc.renderedContent ) { | 
					
						
							|  |  |  |           var matches = doc.renderedContent.match(BACKTICK_REGEX); | 
					
						
							|  |  |  |           if (matches && matches.length % 2 !== 0) { | 
					
						
							| 
									
										
										
										
											2015-10-17 08:45:56 +01:00
										 |  |  |             doc.unbalancedBackTicks = true; | 
					
						
							| 
									
										
										
										
											2015-09-15 23:21:55 -07:00
										 |  |  |             log.warn(createDocMessage('checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content', doc)); | 
					
						
							| 
									
										
										
										
											2015-10-17 08:45:56 +01:00
										 |  |  |             log.warn(doc.renderedContent); | 
					
						
							| 
									
										
										
										
											2015-09-15 23:21:55 -07:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; |