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 | ;
|
16 |
|
17 | const CommonMarkUtils = require('@accordproject/markdown-common').CommonMarkUtils;
|
18 | const FromCommonMarkVisitor = require('@accordproject/markdown-common').FromCommonMarkVisitor;
|
19 | const fromcommonmarkrules = require('@accordproject/markdown-common').fromcommonmarkrules;
|
20 | const fromciceromarkrules = require('./fromciceromarkrules');
|
21 |
|
22 | /**
|
23 | * Converts a CiceroMark DOM to a cicero markdown string.
|
24 | */
|
25 | class ToMarkdownCiceroVisitor extends FromCommonMarkVisitor {
|
26 | /**
|
27 | * Construct the visitor.
|
28 | * @param {object} [options] configuration options
|
29 | * @param {*} resultSeq how to sequentially combine results
|
30 | * @param {object} rules how to process each node type
|
31 | */
|
32 | constructor(options) {
|
33 | const resultString = (result) => {
|
34 | return result;
|
35 | };
|
36 | const resultSeq = (parameters,result) => {
|
37 | result.forEach((next) => {
|
38 | parameters.result += next;
|
39 | });
|
40 | };
|
41 | const setFirst = (thingType) => {
|
42 | return thingType === 'Item' || thingType === 'Clause' ? true : false;
|
43 | };
|
44 | const rules = fromcommonmarkrules;
|
45 | Object.assign(rules,fromciceromarkrules);
|
46 | super(options,resultString,resultSeq,rules,setFirst);
|
47 | }
|
48 |
|
49 | /**
|
50 | * Converts a CiceroMark DOM to a cicero markdown string.
|
51 | * @param {*} input - CiceroMark DOM (JSON)
|
52 | * @returns {string} the cicero markdown string
|
53 | */
|
54 | toMarkdownCicero(input) {
|
55 | const parameters = {};
|
56 | parameters.result = this.resultString('');
|
57 | parameters.stack = CommonMarkUtils.blocksInit();
|
58 | input.accept(this, parameters);
|
59 | return parameters.result.trim();
|
60 | }
|
61 | }
|
62 |
|
63 | module.exports = ToMarkdownCiceroVisitor; |
\ | No newline at end of file |