1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | 'use strict';
|
16 |
|
17 | var CommonMarkUtils = require('@accordproject/markdown-common').CommonMarkUtils;
|
18 | var FromCommonMarkVisitor = require('@accordproject/markdown-common').FromCommonMarkVisitor;
|
19 | var fromcommonmarkrules = require('@accordproject/markdown-common').fromcommonmarkrules;
|
20 | var fromtemplatemarkrules = require('./fromtemplatemarkrules');
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function fixupRootNode(input) {
|
28 | var rootNode = {
|
29 | '$class': 'org.accordproject.commonmark.Document',
|
30 | 'xmlns': 'http://commonmark.org/xml/1.0',
|
31 | 'nodes': input.nodes[0].nodes
|
32 | };
|
33 | return rootNode;
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | class ToMarkdownTemplateVisitor extends FromCommonMarkVisitor {
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | constructor(options) {
|
47 | var resultString = result => {
|
48 | return result;
|
49 | };
|
50 | var resultSeq = (parameters, result) => {
|
51 | result.forEach(next => {
|
52 | parameters.result += next;
|
53 | });
|
54 | };
|
55 | var setFirst = thingType => {
|
56 | return thingType === 'Item' || thingType === 'ClauseDefinition' || thingType === 'ListBlockDefinition' ? true : false;
|
57 | };
|
58 | var rules = fromcommonmarkrules;
|
59 | Object.assign(rules, fromtemplatemarkrules);
|
60 | super(options, resultString, resultSeq, rules, setFirst);
|
61 | }
|
62 |
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | toMarkdownTemplate(serializer, input) {
|
70 | var parameters = {};
|
71 | var fixedInput = serializer.fromJSON(fixupRootNode(input));
|
72 | parameters.result = this.resultString('');
|
73 | parameters.stack = CommonMarkUtils.blocksInit();
|
74 | fixedInput.accept(this, parameters);
|
75 | return parameters.result.trim();
|
76 | }
|
77 | }
|
78 | module.exports = ToMarkdownTemplateVisitor; |
\ | No newline at end of file |