UNPKG

1.6 kBJavaScriptView Raw
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15'use strict';
16
17const CommonMarkUtils = require('@accordproject/markdown-common').CommonMarkUtils;
18
19const rules = {};
20// Inlines
21rules.Formula = (visitor,thing,children,parameters,resultString,resultSeq) => {
22 const result = [resultString('{{%'),resultString(thing.value),resultString('%}}')];
23 resultSeq(parameters,result);
24};
25// Container blocks
26rules.Clause = (visitor,thing,children,parameters,resultString,resultSeq) => {
27 const next1 = CommonMarkUtils.mkPrefix(parameters,2);
28 const srcAttr = thing.src ? ' src="' + thing.src + '"' : '';
29 const next2 = `{{#clause ${thing.name}${srcAttr}}}\n`;
30 const closeParameters = Object.assign({},parameters);
31 closeParameters.stack = Object.assign({},parameters.stack);
32 closeParameters.stack.first = false;
33 const next3 = CommonMarkUtils.mkPrefix(closeParameters,1);
34 const next4 = '{{/clause}}';
35 const result = [resultString(next1),resultString(next2),children,resultString(next3),resultString(next4)];
36 resultSeq(parameters,result);
37};
38
39module.exports = rules;
\No newline at end of file