1 | 'use strict'
|
2 | module.exports = createMDScope
|
3 |
|
4 | const runAsync = require('run-async')
|
5 | const reserved = require('reserved-words')
|
6 |
|
7 | function 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')) {
|
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 | }
|