UNPKG

1.89 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
17var CiceroMarkTransformer = require('@accordproject/markdown-cicero').CiceroMarkTransformer;
18
19/**
20 * Prepare the text for parsing (normalizes new lines, etc)
21 * @param {string} input - the text
22 * @return {string} - the normalized text
23 */
24function normalizeNLs(input) {
25 // we replace all \r and \n with \n
26 var text = input.replace(/\r/gm, '');
27 return text;
28}
29
30/**
31 * Normalize to markdown cicero text
32 * @param {*} input - the CiceroMark DOM
33 * @return {string} - the normalized markdown cicero text
34 */
35function normalizeToMarkdownCicero(input) {
36 var ciceroMarkTransformer = new CiceroMarkTransformer();
37 var result = ciceroMarkTransformer.toMarkdownCicero(input);
38 return result;
39}
40
41/**
42 * Normalize from markdown cicero text
43 * @param {string} input - the markdown cicero text
44 * @return {object} - the normalized CiceroMark DOM
45 */
46function normalizeFromMarkdownCicero(input) {
47 // Normalizes new lines
48 var inputNLs = normalizeNLs(input);
49 // Roundtrip through the CommonMark parser
50 var ciceroMarkTransformer = new CiceroMarkTransformer();
51 return ciceroMarkTransformer.fromMarkdownCicero(inputNLs);
52}
53module.exports.normalizeNLs = normalizeNLs;
54module.exports.normalizeToMarkdownCicero = normalizeToMarkdownCicero;
55module.exports.normalizeFromMarkdownCicero = normalizeFromMarkdownCicero;
\No newline at end of file