From 55ae9ac729908beff1020753d4a7fbc36800731f Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Wed, 29 Jan 2020 16:17:38 +0100
Subject: [PATCH] DocxTemplater multiline placeholders

---
 process/DocxTemplater_lib/process.js | 70 ++++++++++++----------------
 1 file changed, 31 insertions(+), 39 deletions(-)

diff --git a/process/DocxTemplater_lib/process.js b/process/DocxTemplater_lib/process.js
index adf217f2b7..e9cd6c748f 100644
--- a/process/DocxTemplater_lib/process.js
+++ b/process/DocxTemplater_lib/process.js
@@ -33,6 +33,7 @@ if (pStartDelimiter)
     docx.delimiters.start = pStartDelimiter;
 if (pEndDelimiter)
     docx.delimiters.end = pEndDelimiter;
+
 docx.attachModule(_getAutoNewLineModule());
 docx = docx.loadZip(zip);
 
@@ -66,33 +67,25 @@ function _getAutoNewLineModule()
     var res = {
         name: moduleName,
         parse: function parse(placeHolderContent) {
-            var type = "placeholder";
-            if (placeHolderContent[0] !== "=")
-            {
-                return null;
-            }
+            if (placeHolderContent[0] === "=")
+                placeHolderContent = placeHolderContent.substr(1);
+
             return {
-                type: type,
-                value: placeHolderContent.substr(1),
+                type: "placeholder",
+                value: placeHolderContent,
                 module: moduleName
             };
-
         },
 
         render: function render(part, options) {
             if (part.module !== moduleName)
-            {
                 return null;
-            }
+
             var value = options.scopeManager.getValue(part.value);
             if (value == null)
-            {
                 value = options.nullGetter(part);
-            }
             else
-            {
-                value = value.replace(/(\r\n)|(\n)|(\r)/g, "<w:br/>");
-            }
+                value = value.replace(/(\r\n)|(\n)|(\r)/g, "\n<w:br/>");
 
             return {
                 value: value
@@ -100,7 +93,6 @@ function _getAutoNewLineModule()
         }
     }
 
-
     return res;
 }
 
@@ -601,7 +593,7 @@ exports.dosPermissions = null;
 var utils = require('./utils');
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.string2binary = function(str) {
@@ -609,7 +601,7 @@ exports.string2binary = function(str) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.string2Uint8Array = function(str) {
@@ -617,7 +609,7 @@ exports.string2Uint8Array = function(str) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.uint8Array2String = function(array) {
@@ -625,7 +617,7 @@ exports.uint8Array2String = function(array) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.string2Blob = function(str) {
@@ -634,7 +626,7 @@ exports.string2Blob = function(str) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.arrayBuffer2Blob = function(buffer) {
@@ -642,7 +634,7 @@ exports.arrayBuffer2Blob = function(buffer) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.transformTo = function(outputType, input) {
@@ -650,7 +642,7 @@ exports.transformTo = function(outputType, input) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.getTypeOf = function(input) {
@@ -658,7 +650,7 @@ exports.getTypeOf = function(input) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.checkSupport = function(type) {
@@ -666,20 +658,20 @@ exports.checkSupport = function(type) {
 };
 
 /**
- * 
+ *
  * This value will be removed in a future version without replacement.
  */
 exports.MAX_VALUE_16BITS = utils.MAX_VALUE_16BITS;
 
 /**
- * 
+ *
  * This value will be removed in a future version without replacement.
  */
 exports.MAX_VALUE_32BITS = utils.MAX_VALUE_32BITS;
 
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.pretty = function(str) {
@@ -687,7 +679,7 @@ exports.pretty = function(str) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.findCompression = function(compressionMethod) {
@@ -695,7 +687,7 @@ exports.findCompression = function(compressionMethod) {
 };
 
 /**
- * 
+ *
  * This function will be removed in a future version without replacement.
  */
 exports.isRegExp = function (object) {
@@ -779,21 +771,21 @@ JSZip.support = require('./support');
 JSZip.defaults = require('./defaults');
 
 /**
- * 
+ *
  * This namespace will be removed in a future version without replacement.
  */
 JSZip.utils = require('./deprecatedPublicUtils');
 
 JSZip.base64 = {
     /**
-     * 
+     *
      * This method will be removed in a future version without replacement.
      */
     encode : function(input) {
         return base64.encode(input);
     },
     /**
-     * 
+     *
      * This method will be removed in a future version without replacement.
      */
     decode : function(input) {
@@ -3294,7 +3286,7 @@ function Deflate(options) {
 
     this._dict_set = true;
   }
-  
+
   return undefined;
 }
 
@@ -9771,7 +9763,7 @@ function initTemplater()
             s(r[o]);
         return s
     })({
-        1: [function (require, module, exports) 
+        1: [function (require, module, exports)
 {
 
 function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -11970,7 +11962,7 @@ copy(NodeType,Node);
 copy(NodeType,Node.prototype);
 
 /**
- * @param node 
+ * @param node
  * @param callback return true for continue,false for break
  * @return boolean true: break visit;
  */
@@ -12543,7 +12535,7 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
 		var prefix;
 		var uri;
 		var ns;
-		
+
 		isHTML =  (htmlns === node.namespaceURI) ||isHTML
 		buf.push('<',nodeName);
 
@@ -12888,7 +12880,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
 	var closeMap = {};
 	var start = 0;
         var end;
-        
+
 	while(true){
 		try{
 			var tagStart = source.indexOf('<',start);
@@ -13197,7 +13189,7 @@ function appendElement(el,domBuilder,currentNSMap){
 	var localNSMap = null;
         var nsp;
         var prefix;
-        
+
 	//var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
 	var i = el.length;
 	while(i--){
@@ -13632,4 +13624,4 @@ module.exports = Docxtemplater;
 });
 
 }
-}
\ No newline at end of file
+}
-- 
GitLab