btrz-liquid-templates 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-liquid-templates",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Extension and helpers for liquid templates to deal with our data and other things we need to encapsulate",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/html.js CHANGED
@@ -90,8 +90,27 @@ function Html(engine) {
90
90
  });
91
91
  }
92
92
 
93
+ function Unescape(engine) {
94
+ this.registerTag("unescape", {
95
+ parse: function(tagToken) {
96
+ this.item = tagToken.args;
97
+ },
98
+ render: async function(ctx) {
99
+ const str = await this.liquid.evalValue(this.item, ctx);
100
+
101
+ return(str || "")
102
+ .replace(/&/g, '&')
103
+ .replace(/&lt;/g, '<')
104
+ .replace(/&gt;/g, '>')
105
+ .replace(/&quot;/g, '"')
106
+ .replace(/&#39;/g, "'");
107
+ }
108
+ });
109
+ }
110
+
93
111
  module.exports = {
94
- Html
112
+ Html,
113
+ Unescape
95
114
  };
96
115
 
97
116
 
package/src/index.js CHANGED
@@ -2,7 +2,10 @@ const {Liquid} = require("liquidjs");
2
2
  const {Localizer} = require("./localizer.js");
3
3
  const {HorizontalLine} = require("./lines.js");
4
4
  const {Barcode} = require("./barcode.js");
5
- const {Html} = require("./html.js");
5
+ const {
6
+ Html,
7
+ Unescape
8
+ } = require("./html.js");
6
9
  const {Money, CurcySymbol, CurcyIso, CurcyName, MoneyReduce} = require("./money.js");
7
10
  const {DateF, TimeF, DateTime, HumanDate, HumanDateTime, ExpDate, HumanArrivalDateTime, HumanDepartureDateTime,
8
11
  DepartureDateTime, ArrivalDateTime, DepartureDate, ArrivalDate, DepartureTime, ArrivalTime, HumanArrivalDate,
@@ -52,6 +55,7 @@ function getEngine() {
52
55
  });
53
56
  engine.plugin(Localizer);
54
57
  engine.plugin(Html);
58
+ engine.plugin(Unescape);
55
59
  engine.plugin(HorizontalLine);
56
60
  engine.plugin(Barcode);
57
61
  engine.plugin(Money);
@@ -748,4 +748,20 @@ and some more here`,
748
748
  const documentDefinition = await tpl.processToEscp(template, data);
749
749
  expect(documentDefinition).to.be.eql(`\u001bia\u0000\u001b@\u001b3$\u001bM\u001bEShift location closure #: 5c9f8f8f8f8f8f8f8f8f8f8\n\u001bF\u001b\u000f\f`);
750
750
  });
751
+
752
+ it("should return a text with unescaped characters", async () => {
753
+ const tpl = require("../src/index");
754
+ data.escapedCharacters = "&lt; &gt; &amp; $";
755
+ const template = `{
756
+ "content": [
757
+ "{%- unescape escapedCharacters %}"
758
+ ]
759
+ }`;
760
+ const documentDefinition = await tpl.processToObj(template, data);
761
+ expect(documentDefinition).to.be.eql({
762
+ "content": [
763
+ "< > & $"
764
+ ]
765
+ });
766
+ });
751
767
  });