-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (58 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module.exports = function (form, substitutions) {
return recurse(
form,
substitutions.headings || {},
substitutions.terms || {},
substitutions.blanks || {},
{ value: 0 }
)
}
function recurse (form, headings, terms, blanks, blankCounter) {
var returned = {}
if (form.conspicuous) returned.conspicuous = form.conspicuous
returned.content = form.content.map(function (element) {
if (typeof element === 'string') return element
if (
element.hasOwnProperty('use') &&
terms[element.use]
) {
return {use: terms[element.use]}
} else if (
element.hasOwnProperty('definition') &&
terms[element.definition]
) {
return {definition: terms[element.definition]}
} else if (
element.hasOwnProperty('reference') &&
headings[element.reference]
) {
return {reference: headings[element.reference]}
} else if (element.hasOwnProperty('blank')) {
blankCounter.value++
var value = blanks[blankCounter.value]
if (typeof value === 'string') return value
return element
} else if (element.hasOwnProperty('form')) {
if (element.hasOwnProperty('heading')) {
if (headings[element.heading]) {
return {
heading: headings[element.heading],
form: recurse(element.form, headings, terms, blanks, blankCounter)
}
} else {
return {
heading: element.heading,
form: recurse(element.form, headings, terms, blanks, blankCounter)
}
}
} else {
return {
form: recurse(element.form, headings, terms, blanks, blankCounter)
}
}
} else {
return element
}
})
return returned
}