| 
									
										
										
										
											2018-09-27 16:00:11 +05:30
										 |  |  | const unified = require('unified'); | 
					
						
							|  |  |  | const vfile = require('to-vfile'); | 
					
						
							|  |  |  | const markdown = require('remark-parse'); | 
					
						
							|  |  |  | const remark2rehype = require('remark-rehype'); | 
					
						
							|  |  |  | const html = require('rehype-stringify'); | 
					
						
							|  |  |  | const frontmatter = require('remark-frontmatter'); | 
					
						
							|  |  |  | const raw = require('rehype-raw'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const frontmatterToData = require('./frontmatter-to-data'); | 
					
						
							|  |  |  | const textToData = require('./text-to-data'); | 
					
						
							|  |  |  | const testsToData = require('./tests-to-data'); | 
					
						
							| 
									
										
										
										
											2020-06-04 16:52:49 +02:00
										 |  |  | const { challengeSeedToData } = require('./challengeSeed-to-data'); | 
					
						
							| 
									
										
										
										
											2018-10-23 16:21:53 +03:00
										 |  |  | const solutionsToData = require('./solution-to-data'); | 
					
						
							| 
									
										
										
										
											2018-09-27 16:00:11 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | const processor = unified() | 
					
						
							|  |  |  |   .use(markdown) | 
					
						
							|  |  |  |   .use(frontmatter, ['yaml']) | 
					
						
							|  |  |  |   .use(frontmatterToData) | 
					
						
							|  |  |  |   .use(testsToData) | 
					
						
							|  |  |  |   .use(remark2rehype, { allowDangerousHTML: true }) | 
					
						
							|  |  |  |   .use(raw) | 
					
						
							| 
									
										
										
										
											2018-10-23 16:21:53 +03:00
										 |  |  |   .use(solutionsToData) | 
					
						
							| 
									
										
										
										
											2018-09-27 16:00:11 +05:30
										 |  |  |   .use(textToData, ['description', 'instructions']) | 
					
						
							| 
									
										
										
										
											2018-09-30 20:13:52 +01:00
										 |  |  |   .use(challengeSeedToData) | 
					
						
							| 
									
										
										
										
											2018-09-27 16:00:11 +05:30
										 |  |  |   // the plugins below are just to stop the processor from throwing
 | 
					
						
							|  |  |  |   // we need to write a compiler that can create graphql nodes
 | 
					
						
							|  |  |  |   .use(html); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-01 18:19:25 +02:00
										 |  |  | exports.parseMarkdown = function parseMarkdown(filename) { | 
					
						
							| 
									
										
										
										
											2018-10-04 14:37:37 +01:00
										 |  |  |   return new Promise((resolve, reject) => | 
					
						
							| 
									
										
										
										
											2019-04-01 18:19:25 +02:00
										 |  |  |     processor.process(vfile.readSync(filename), function(err, file) { | 
					
						
							| 
									
										
										
										
											2018-10-04 14:37:37 +01:00
										 |  |  |       if (err) { | 
					
						
							| 
									
										
										
										
											2019-04-01 18:19:25 +02:00
										 |  |  |         err.message += ' in file ' + filename; | 
					
						
							| 
									
										
										
										
											2018-10-04 14:37:37 +01:00
										 |  |  |         reject(err); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       delete file.contents; | 
					
						
							|  |  |  |       return resolve(file.data); | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; |