UNPKG

711 BJavaScriptView Raw
1'use strict'
2module.exports = createMDScope
3
4const runAsync = require('run-async')
5const reserved = require('reserved-words')
6
7function createMDScope (plugins, markdown) {
8 return Promise.all(
9 plugins
10 .map(plugin => runAsync(plugin))
11 .map(plugin => plugin(markdown))
12 )
13 .then(scopes => scopes.reduce(
14 (scope, pluginScope) => {
15 Object.keys(pluginScope).forEach(scopeVar => {
16 if (reserved.check(scopeVar, 'next')) { // TODO: make it strict
17 throw new Error(`Cannot make '${scopeVar}' a scope variable because it is a reserved word`)
18 }
19 scope[scopeVar] = pluginScope[scopeVar]
20 })
21 return scope
22 }, {})
23 )
24}