1414
1515'use strict' ;
1616
17- const { CICERO_NS_PREFIX } = require ( './Models' ) ;
17+ const { COMMON_NS_PREFIX , CICERO_NS_PREFIX } = require ( './Models' ) ;
1818
1919/**
2020 * Converts a commonmark model instance to a markdown string.
@@ -68,10 +68,20 @@ class ToCiceroVisitor {
6868
6969 thing . nodes = parameters . commonMark . fromString ( thing . text ) . nodes ;
7070 ToCiceroVisitor . visitNodes ( this , thing . nodes , parameters ) ;
71- thing . clauseText = thing . text ;
71+
7272 thing . text = null ; // Remove text
73+ thing . clauseText = '' ;
7374 delete thing . tag ;
7475 delete thing . info ;
76+
77+ // Go over the loaded clause to generate the unwrapped text
78+ let clone = parameters . serializer . toJSON ( thing ) ;
79+ clone . $class = COMMON_NS_PREFIX + 'Paragraph' ;
80+ delete clone . clauseid ;
81+ delete clone . src ;
82+ delete clone . clauseText ;
83+ clone = parameters . serializer . fromJSON ( clone ) ;
84+ thing . clauseText = parameters . ciceroMark . toString ( clone , { wrapVariables : false } ) ;
7585 }
7686 else if ( tag . attributes [ 1 ] . name === 'src' &&
7787 tag . attributes [ 0 ] . name === 'clauseid' ) {
@@ -81,10 +91,19 @@ class ToCiceroVisitor {
8191
8292 thing . nodes = parameters . commonMark . fromString ( thing . text ) . nodes ;
8393 ToCiceroVisitor . visitNodes ( this , thing . nodes , parameters ) ;
84- thing . clauseText = thing . text ;
8594 thing . text = null ; // Remove text
95+ thing . clauseText = '' ;
8696 delete thing . tag ;
8797 delete thing . info ;
98+
99+ // Go over the loaded clause to generate the unwrapped text
100+ let clone = parameters . serializer . toJSON ( thing ) ;
101+ clone . $class = COMMON_NS_PREFIX + 'Paragraph' ;
102+ delete clone . clauseid ;
103+ delete clone . src ;
104+ delete clone . clauseText ;
105+ clone = parameters . serializer . fromJSON ( clone ) ;
106+ thing . clauseText = parameters . ciceroMark . toString ( clone , { wrapVariables : false } ) ;
88107 } else {
89108 //console.log('Found Clause but without \'clauseid\' and \'src\' attributes ');
90109 }
0 commit comments