extwee 2.3.11 → 2.3.12

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.
Files changed (179) hide show
  1. package/CHANGELOG.md +219 -0
  2. package/CONTRIBUTING.md +305 -0
  3. package/README.md +16 -0
  4. package/build/extwee.core.min.js +1 -1
  5. package/build/extwee.twine1html.min.js +1 -1
  6. package/build/extwee.twine2archive.min.js +1 -1
  7. package/build/extwee.tws.min.js +1 -1
  8. package/package.json +8 -5
  9. package/src/Story.js +2 -2
  10. package/types/src/Story.d.ts +1 -1
  11. package/.github/FUNDING.yml +0 -3
  12. package/.github/codeql-analysis.yml +0 -51
  13. package/.github/dependabot.yml +0 -11
  14. package/.github/workflows/dependabot-automerge.yml +0 -23
  15. package/.github/workflows/nodejs.yml +0 -28
  16. package/.travis.yml +0 -13
  17. package/babel.config.json +0 -18
  18. package/docs/.nojekyll +0 -0
  19. package/docs/README.md +0 -224
  20. package/docs/_sidebar.md +0 -19
  21. package/docs/build/extwee.core.min.js +0 -1
  22. package/docs/build/extwee.twine1html.min.js +0 -1
  23. package/docs/build/extwee.twine2archive.min.js +0 -1
  24. package/docs/build/extwee.tws.min.js +0 -1
  25. package/docs/demos/compiler/extwee.core.min.js +0 -1
  26. package/docs/demos/compiler/index.css +0 -105
  27. package/docs/demos/compiler/index.html +0 -359
  28. package/docs/demos/decompile/extwee.core.min.js +0 -1
  29. package/docs/demos/decompile/index.css +0 -584
  30. package/docs/demos/decompile/index.html +0 -468
  31. package/docs/examples/dynamicPassages.md +0 -28
  32. package/docs/examples/jsonToTwee.md +0 -23
  33. package/docs/examples/twsToTwee.md +0 -25
  34. package/docs/formats/json.md +0 -17
  35. package/docs/formats/twee.md +0 -13
  36. package/docs/formats/twine1HTML.md +0 -13
  37. package/docs/formats/twine2ArchiveHTML.md +0 -13
  38. package/docs/formats/twine2HTML.md +0 -13
  39. package/docs/formats/tws.md +0 -9
  40. package/docs/index.html +0 -26
  41. package/docs/install/npm.md +0 -16
  42. package/docs/install/npx.md +0 -79
  43. package/docs/objects/passage.md +0 -47
  44. package/docs/objects/story.md +0 -69
  45. package/docs/objects/storyformat.md +0 -27
  46. package/eslint.config.js +0 -28
  47. package/extwee.config.json +0 -6
  48. package/extwee.config.md +0 -67
  49. package/jest.config.json +0 -5
  50. package/test/CLI/CLI.test.js +0 -49
  51. package/test/CLI/files/example.json +0 -1
  52. package/test/CLI/files/example6.twee +0 -22
  53. package/test/CLI/files/harlowe.js +0 -3
  54. package/test/CLI/files/input.html +0 -47
  55. package/test/CLI/files/output/test.twee +0 -0
  56. package/test/CLI/files/test.twee +0 -18
  57. package/test/CLI/files/tweeExample.twee +0 -17
  58. package/test/CLI/files/twine1/LICENSE.txt +0 -32
  59. package/test/CLI/files/twine1/code.js +0 -5
  60. package/test/CLI/files/twine1/engine.js +0 -43
  61. package/test/CLI/files/twine1/header.html +0 -325
  62. package/test/CLI/files/twine1Test.html +0 -371
  63. package/test/CLI/files/twineExample.html +0 -16
  64. package/test/Config/Config.test.js +0 -76
  65. package/test/Config/files/empty.json +0 -3
  66. package/test/Config/files/full.json +0 -8
  67. package/test/Config/files/invalid.json +0 -1
  68. package/test/Config/files/valid.json +0 -6
  69. package/test/Config/isDirectory.test.js +0 -50
  70. package/test/Config/isFile.test.js +0 -53
  71. package/test/Config/loadStoryFormat.test.js +0 -117
  72. package/test/Config/readDirectories.test.js +0 -78
  73. package/test/IFID/IFID.Generate.test.js +0 -10
  74. package/test/JSON/JSON.Parse.test.js +0 -316
  75. package/test/Objects/Passage.test.js +0 -274
  76. package/test/Objects/SnowmanCompatibility.test.js +0 -111
  77. package/test/Objects/Story.test.js +0 -1075
  78. package/test/Objects/StoryFormat.test.js +0 -219
  79. package/test/Roundtrip/Files/Example1.html +0 -64
  80. package/test/Roundtrip/Files/LICENSE +0 -19
  81. package/test/Roundtrip/Files/example1.twee +0 -10
  82. package/test/Roundtrip/Files/example2.twee +0 -27
  83. package/test/Roundtrip/Files/example4.twee +0 -27
  84. package/test/Roundtrip/Files/harlowe.js +0 -3
  85. package/test/Roundtrip/Files/round.html +0 -49
  86. package/test/Roundtrip/Roundtrip.test.js +0 -54
  87. package/test/StoryFormat/StoryFormat.Parse.test.js +0 -479
  88. package/test/TWS/Parse.test.js +0 -56
  89. package/test/TWS/TWSParser/Example5.tws +0 -414
  90. package/test/TWS/TWSParser/noscale.tws +0 -0
  91. package/test/TWS/TWSParser/nostory.tws +0 -0
  92. package/test/Twee/Twee.Escaping.test.js +0 -200
  93. package/test/Twee/Twee.Parse.test.js +0 -108
  94. package/test/Twee/TweeParser/cursed.twee +0 -16
  95. package/test/Twee/TweeParser/cycling.twee +0 -75
  96. package/test/Twee/TweeParser/emptytags.twee +0 -2
  97. package/test/Twee/TweeParser/example.twee +0 -32
  98. package/test/Twee/TweeParser/malformed.twee +0 -2
  99. package/test/Twee/TweeParser/missing.twee +0 -19
  100. package/test/Twee/TweeParser/multipleScriptPassages.twee +0 -19
  101. package/test/Twee/TweeParser/multipleStyleTag.twee +0 -19
  102. package/test/Twee/TweeParser/multipletags.twee +0 -10
  103. package/test/Twee/TweeParser/noTitle.twee +0 -2
  104. package/test/Twee/TweeParser/notes.twee +0 -16
  105. package/test/Twee/TweeParser/pasagemetadataerror.twee +0 -2
  106. package/test/Twee/TweeParser/scriptPassage.twee +0 -16
  107. package/test/Twee/TweeParser/singletag.twee +0 -13
  108. package/test/Twee/TweeParser/start.twee +0 -2
  109. package/test/Twee/TweeParser/startMetadata.twee +0 -14
  110. package/test/Twee/TweeParser/storydataerror.twee +0 -25
  111. package/test/Twee/TweeParser/style.twee +0 -16
  112. package/test/Twee/TweeParser/stylePassage.twee +0 -16
  113. package/test/Twee/TweeParser/test.twee +0 -25
  114. package/test/Twine1HTML/Twine1HTML.Compile.test.js +0 -180
  115. package/test/Twine1HTML/Twine1HTML.Parse.Web.test.js +0 -484
  116. package/test/Twine1HTML/Twine1HTML.Parse.test.js +0 -183
  117. package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/LICENSE +0 -674
  118. package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/engine.js +0 -43
  119. package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/jquery.js +0 -4
  120. package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/modernizr.js +0 -4
  121. package/test/Twine1HTML/Twine1HTMLCompiler/engineTest.html +0 -1
  122. package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/LICENSE +0 -32
  123. package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/code.js +0 -4
  124. package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/header.html +0 -327
  125. package/test/Twine1HTML/Twine1HTMLCompiler/test.html +0 -0
  126. package/test/Twine1HTML/Twine1HTMLCompiler/test1.html +0 -6
  127. package/test/Twine1HTML/Twine1HTMLCompiler/test2.html +0 -6
  128. package/test/Twine1HTML/Twine1HTMLCompiler/test3.html +0 -43
  129. package/test/Twine1HTML/Twine1HTMLCompiler/test4.html +0 -372
  130. package/test/Twine1HTML/Twine1HTMLCompiler/test5.html +0 -372
  131. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Compile.test.js +0 -35
  132. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.Web.test.js +0 -293
  133. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.test.js +0 -42
  134. package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLCompiler/test1.html +0 -6
  135. package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLParser/test1.html +0 -3
  136. package/test/Twine2HTML/Twine2HTML.Compile.test.js +0 -139
  137. package/test/Twine2HTML/Twine2HTML.Parse.Web.test.js +0 -329
  138. package/test/Twine2HTML/Twine2HTML.Parse.test.js +0 -192
  139. package/test/Twine2HTML/Twine2HTMLCompiler/TestTags.html +0 -42
  140. package/test/Twine2HTML/Twine2HTMLCompiler/creator.html +0 -50
  141. package/test/Twine2HTML/Twine2HTMLCompiler/example6.twee +0 -16
  142. package/test/Twine2HTML/Twine2HTMLCompiler/format.js +0 -9
  143. package/test/Twine2HTML/Twine2HTMLCompiler/missingStoryTitle.twee +0 -29
  144. package/test/Twine2HTML/Twine2HTMLCompiler/test11.html +0 -121
  145. package/test/Twine2HTML/Twine2HTMLCompiler/test2.html +0 -58
  146. package/test/Twine2HTML/Twine2HTMLCompiler/test3.html +0 -49
  147. package/test/Twine2HTML/Twine2HTMLCompiler/test4.html +0 -50
  148. package/test/Twine2HTML/Twine2HTMLCompiler/test6.html +0 -49
  149. package/test/Twine2HTML/Twine2HTMLParser/Example1.html +0 -53
  150. package/test/Twine2HTML/Twine2HTMLParser/Tags.html +0 -15
  151. package/test/Twine2HTML/Twine2HTMLParser/lyingStartnode.html +0 -15
  152. package/test/Twine2HTML/Twine2HTMLParser/lyingTagColors.html +0 -48
  153. package/test/Twine2HTML/Twine2HTMLParser/missingCreator.html +0 -11
  154. package/test/Twine2HTML/Twine2HTMLParser/missingCreatorVersion.html +0 -11
  155. package/test/Twine2HTML/Twine2HTMLParser/missingFormat.html +0 -11
  156. package/test/Twine2HTML/Twine2HTMLParser/missingFormatVersion.html +0 -11
  157. package/test/Twine2HTML/Twine2HTMLParser/missingIFID.html +0 -11
  158. package/test/Twine2HTML/Twine2HTMLParser/missingPassageTags.html +0 -15
  159. package/test/Twine2HTML/Twine2HTMLParser/missingPosition.html +0 -15
  160. package/test/Twine2HTML/Twine2HTMLParser/missingScript.html +0 -14
  161. package/test/Twine2HTML/Twine2HTMLParser/missingSize.html +0 -35
  162. package/test/Twine2HTML/Twine2HTMLParser/missingStartnode.html +0 -11
  163. package/test/Twine2HTML/Twine2HTMLParser/missingStyle.html +0 -14
  164. package/test/Twine2HTML/Twine2HTMLParser/missingZoom.html +0 -11
  165. package/test/Twine2HTML/Twine2HTMLParser/tagColors.html +0 -31
  166. package/test/Twine2HTML/Twine2HTMLParser/twineExample.html +0 -23
  167. package/test/Twine2HTML/Twine2HTMLParser/twineExample2.html +0 -15
  168. package/test/Twine2HTML/Twine2HTMLParser/twineExample3.html +0 -15
  169. package/test/Twine2HTML/Twine2HTMLParser/unescaping.html +0 -33
  170. package/test/Web/web-core-coverage.test.js +0 -175
  171. package/test/Web/web-core-global.test.js +0 -93
  172. package/test/Web/web-core.test.js +0 -156
  173. package/test/Web/web-exports.test.js +0 -136
  174. package/test/Web/web-twine1html.test.js +0 -105
  175. package/test/Web/web-twine2archive.test.js +0 -96
  176. package/test/Web/web-tws.test.js +0 -77
  177. package/test/Web/window.Extwee.test.js +0 -97
  178. package/tsconfig.json +0 -21
  179. package/webpack.config.js +0 -47
@@ -1,274 +0,0 @@
1
- import Passage from '../../src/Passage.js';
2
- import { parse as HTMLParser } from 'node-html-parser';
3
-
4
- describe('Passage', () => {
5
- describe('constructor()', () => {
6
- it('Set default values', () => {
7
- const p = new Passage();
8
- expect(p.name).toBe('');
9
- expect(p.tags).toHaveLength(0);
10
- expect(p.text).toBe('');
11
- expect(typeof p.metadata).toBe('object');
12
- });
13
- });
14
-
15
- describe('name', () => {
16
- it('Set name', () => {
17
- const p = new Passage();
18
- p.name = 'New';
19
- expect(p.name).toBe('New');
20
- });
21
-
22
- it('Throw error if name is not String', () => {
23
- const p = new Passage();
24
- expect(() => {
25
- p.name = 1;
26
- }).toThrow();
27
- });
28
- });
29
-
30
- describe('tags', () => {
31
- it('Set tags', () => {
32
- const p = new Passage();
33
- p.tags = ['tag'];
34
- expect(p.tags).toHaveLength(1);
35
- });
36
-
37
- it('Throw error if tags is not Array', () => {
38
- const p = new Passage();
39
- expect(() => {
40
- p.tags = 1;
41
- }).toThrow();
42
- });
43
- });
44
-
45
- describe('metadata', () => {
46
- it('Set metadata', () => {
47
- const p = new Passage();
48
- p.metadata = { position: '100,100' };
49
- expect(p.metadata).toEqual({ position: '100,100' });
50
- });
51
-
52
- it('Throw error if metadata is not an Object', () => {
53
- const p = new Passage();
54
- expect(() => {
55
- p.metadata = 1;
56
- }).toThrow();
57
- });
58
- });
59
-
60
- describe('text', () => {
61
- it('Set text', () => {
62
- const p = new Passage();
63
- p.text = 'New';
64
- expect(p.text).toBe('New');
65
- });
66
-
67
- it('Throw error if text is not a String', () => {
68
- const p = new Passage();
69
- expect(() => {
70
- p.text = 1;
71
- }).toThrow();
72
- });
73
- });
74
-
75
- describe('toTwee()', () => {
76
- it('Create name string', () => {
77
- const p = new Passage('Name', 'Test');
78
- expect(p.toTwee()).toBe(':: Name\nTest\n\n');
79
- });
80
- it('Create tags string', () => {
81
- const p = new Passage('Name', 'Test', ['tags', 'another']);
82
- expect(p.toTwee()).toBe(':: Name [tags another]\nTest\n\n');
83
- });
84
- it('Create metadata string', () => {
85
- const p = new Passage('Name', 'Test', ['tags', 'another'], { position: '100,100' });
86
- expect(p.toTwee()).toBe(':: Name [tags another] {"position":"100,100"}\nTest\n\n');
87
- });
88
- });
89
-
90
- describe('toJSON()', function () {
91
- it('Should hold default values', function () {
92
- const p = new Passage();
93
- const r = JSON.parse(p.toJSON());
94
- expect(r.name).toBe('');
95
- expect(r.text).toBe('');
96
- expect(r.tags.length).toBe(0);
97
- expect(Object.keys(r.metadata).length).toBe(0);
98
- });
99
- });
100
-
101
- describe('toTwine2HTML()', function () {
102
- let p = null;
103
- let result = null;
104
-
105
- beforeEach(() => {
106
- p = new Passage('Test', 'Word', ['tag1'], { some: 'thing' });
107
- result = p.toTwine2HTML();
108
- });
109
-
110
- it('Should contain default PID', function () {
111
- expect(result.includes('pid="1"')).toBe(true);
112
- });
113
-
114
- it('Should include name', function () {
115
- expect(result.includes('name="Test"')).toBe(true);
116
- });
117
-
118
- it('Should include single tag', function () {
119
- expect(result.includes('tags="tag1"')).toBe(true);
120
- });
121
-
122
- it('Should include multiple tags', function () {
123
- p.tags = ['tag1', 'tag2'];
124
- result = p.toTwine2HTML();
125
- expect(result.includes('tags="tag1 tag2"')).toBe(true);
126
- });
127
-
128
- it('Should include position, if it exists', function () {
129
- p.metadata = { position: '102,99' };
130
- result = p.toTwine2HTML();
131
- expect(result.includes('position="102,99"')).toBe(true);
132
- });
133
-
134
- it('Should include size, if it exists', function () {
135
- p.metadata = { size: '100,100' };
136
- result = p.toTwine2HTML();
137
- expect(result.includes('size="100,100"')).toBe(true);
138
- });
139
- });
140
-
141
- describe('toTwine1HTML()', function () {
142
- let p = null;
143
- let result = null;
144
-
145
- beforeEach(() => {
146
- p = new Passage('Test', 'Word', ['tag1'], { position: '12, 12' });
147
- result = p.toTwine1HTML();
148
- });
149
-
150
- it('Should include tiddler', function () {
151
- expect(result.includes('tiddler="Test"')).toBe(true);
152
- });
153
-
154
- it('Should include single tag', function () {
155
- expect(result.includes('tags="tag1"')).toBe(true);
156
- });
157
-
158
- it('Should include multiple tags', function () {
159
- p.tags = ['tag1', 'tag2'];
160
- result = p.toTwine1HTML();
161
- expect(result.includes('tags="tag1 tag2"')).toBe(true);
162
- });
163
-
164
- it('Should include position, if it exists', function () {
165
- p.metadata = { position: '102,99' };
166
- result = p.toTwine1HTML();
167
- expect(result.includes('position="102,99"')).toBe(true);
168
- });
169
-
170
- it('Should use default position', function () {
171
- p.metadata = {};
172
- result = p.toTwine1HTML();
173
- expect(result.includes('position="10,10"')).toBe(true);
174
- });
175
- });
176
-
177
- describe('Escaping', function () {
178
- it('Should HTML-encode passage text content with double quotes', function () {
179
- const p = new Passage('Test', 'Word "word"');
180
- // Passage text MUST be HTML-encoded for valid HTML output
181
- expect(p.toTwine2HTML().includes('"word"')).toBe(true);
182
- expect(p.toTwine2HTML().includes('>Word "word"<')).toBe(false);
183
- });
184
-
185
- it('Should HTML-encode passage text content with ampersands', function () {
186
- const p = new Passage('Test', 'Word & word');
187
- // Passage text MUST be HTML-encoded
188
- expect(p.toTwine2HTML().includes('&amp;')).toBe(true);
189
- expect(p.toTwine2HTML().includes('>Word & word<')).toBe(false);
190
- });
191
-
192
- it('Should HTML-encode passage text content with less than', function () {
193
- const p = new Passage('Test', 'Word < word');
194
- // Passage text MUST be HTML-encoded
195
- expect(p.toTwine2HTML().includes('&lt;')).toBe(true);
196
- expect(p.toTwine2HTML().includes('>Word < word<')).toBe(false);
197
- });
198
-
199
- it('Should HTML-encode passage text content with greater than', function () {
200
- const p = new Passage('Test', 'Word > word');
201
- // Passage text MUST be HTML-encoded
202
- expect(p.toTwine2HTML().includes('&gt;')).toBe(true);
203
- expect(p.toTwine2HTML().includes('>Word > word<')).toBe(false);
204
- });
205
-
206
- it('Should HTML-encode passage text content with special characters', function () {
207
- const p = new Passage('Test', 'Word &<>"\' word');
208
- // Passage text MUST be HTML-encoded
209
- expect(p.toTwine2HTML().includes('&amp;')).toBe(true);
210
- expect(p.toTwine2HTML().includes('&lt;')).toBe(true);
211
- expect(p.toTwine2HTML().includes('&gt;')).toBe(true);
212
- expect(p.toTwine2HTML().includes('&quot;')).toBe(true);
213
- // Single quotes can be encoded as either &apos; or &#39;
214
- const html = p.toTwine2HTML();
215
- expect(html.includes('&apos;') || html.includes('&#39;')).toBe(true);
216
- expect(html.includes('>Word &<>"\' word<')).toBe(false);
217
- });
218
-
219
- it('Should escape meta-characters safely in name attribute', function () {
220
- const p = new Passage('"Test"');
221
- // Attributes SHOULD be HTML-encoded
222
- expect(p.toTwine2HTML().includes('name="&quot;Test&quot;"')).toBe(true);
223
- expect(p.toTwine1HTML().includes('tiddler="&quot;Test&quot;"')).toBe(true);
224
- });
225
-
226
- it('Should HTML-encode passage text including JavaScript/HTML code', function () {
227
- const p = new Passage('Test', '<%\n$.getScript("https://example.com/script.js");\n%>');
228
- const html = p.toTwine2HTML();
229
- // JavaScript code in passages MUST be HTML-encoded in the HTML file
230
- // The story format will retrieve it via .innerHTML which decodes entities automatically
231
- expect(html.includes('&lt;%')).toBe(true);
232
- expect(html.includes('%&gt;')).toBe(true);
233
- expect(html.includes('&quot;https://example.com/script.js&quot;')).toBe(true);
234
- // Raw characters should NOT appear in the HTML
235
- expect(html.includes('$.getScript("https://example.com/script.js");')).toBe(false);
236
- });
237
-
238
- it('Should escape meta-characters safely in tags attribute', function () {
239
- const p = new Passage('Test', 'Word', ['&tag', '"bad"']);
240
- // Attributes SHOULD be HTML-encoded
241
- expect(p.toTwine2HTML().includes('tags="&amp;tag &quot;bad&quot;"')).toBe(true);
242
- expect(p.toTwine1HTML().includes('tags="&amp;tag &quot;bad&quot;"')).toBe(true);
243
- });
244
-
245
- it('Should escape meta-characters safely in Twee header', function () {
246
- const p = new Passage('Where do tags begin? [well', '', ['hmm']);
247
- expect(p.toTwee().includes('Where do tags begin? \\[well [hmm]')).toBe(true);
248
- });
249
-
250
- it('Should produce valid HTML attributes', function () {
251
- // Generate passage.
252
- const p = new Passage('"Test"', '"Word"', ['&tag', '"bad"'], { position: '100,100' });
253
- // Parse HTML.
254
- const d = new HTMLParser(p.toTwine2HTML());
255
- // Test attributes.
256
- expect(d.querySelector('tw-passagedata').getAttribute('name')).toBe('"Test"');
257
- expect(d.querySelector('tw-passagedata').getAttribute('tags')).toBe('&tag "bad"');
258
- expect(d.querySelector('tw-passagedata').getAttribute('position')).toBe('100,100');
259
- // Use Twine 2 result.
260
- const s = '<tw-passagedata pid="1" name="&quot;Test&quot;" tags="&amp;tag &quot;bad&quot;" position="100,100" size="100,100"></tw-passagedata>';
261
- // Parse HTML.
262
- const t = new HTMLParser(s);
263
- // Test Twine 2 attributes.
264
- expect(t.querySelector('tw-passagedata').getAttribute('name')).toBe('"Test"');
265
- expect(t.querySelector('tw-passagedata').getAttribute('tags')).toBe('&tag "bad"');
266
- expect(t.querySelector('tw-passagedata').getAttribute('position')).toBe('100,100');
267
- });
268
-
269
- it('Should escape double-colon at start of text when exporting to Twee', function () {
270
- const p = new Passage('test', ':: nefarious');
271
- expect(p.toTwee()).toBe(':: test\n\\:: nefarious\n\n');
272
- });
273
- });
274
- });
@@ -1,111 +0,0 @@
1
- import Passage from '../../src/Passage.js';
2
- import { Story } from '../../src/Story.js';
3
-
4
- describe('Snowman Compatibility Tests', function () {
5
- describe('JavaScript Code in Passages', function () {
6
- it('Should not HTML-encode JavaScript with quotes', function () {
7
- const p = new Passage('External', '<%\n$.getScript("https://code.jquery.com/jquery-3.6.0.min.js");\n%>');
8
- const html = p.toTwine2HTML();
9
-
10
- // Should NOT have HTML entities
11
- expect(html.includes('&quot;')).toBe(true);
12
- expect(html.includes('&lt;')).toBe(true);
13
- expect(html.includes('&gt;')).toBe(true);
14
- });
15
-
16
- it('Should preserve complex JavaScript code', function () {
17
- const code = `<%
18
- var data = {"key": "value", "test": true};
19
- if (data.test) {
20
- console.log("This is a test");
21
- }
22
- %>`;
23
- const p = new Passage('Test', code);
24
- const html = p.toTwine2HTML();
25
-
26
- expect(html.includes('&quot;')).toBe(true);
27
- expect(html.includes('&lt;')).toBe(true);
28
- expect(html.includes('&gt;')).toBe(true);
29
- });
30
- });
31
-
32
- describe('HTML Content in Passages', function () {
33
- it('Should not HTML-encode HTML tags', function () {
34
- const p = new Passage('HUD', '<h1>This is the HUD!</h1>\n<p>Status: <strong>Active</strong></p>');
35
- const html = p.toTwine2HTML();
36
-
37
- // Should NOT have HTML entities
38
- expect(html.includes('&lt;h1&gt;')).toBe(true);
39
- expect(html.includes('&lt;strong&gt;')).toBe(true);
40
- });
41
-
42
- it('Should preserve nested HTML structures', function () {
43
- const htmlContent = `<div class="container">
44
- <h2>Title</h2>
45
- <ul>
46
- <li>Item 1</li>
47
- <li>Item 2</li>
48
- </ul>
49
- </div>`;
50
- const p = new Passage('Container', htmlContent);
51
- const html = p.toTwine2HTML();
52
-
53
- expect(html.includes('&lt;')).toBe(true);
54
- expect(html.includes('&gt;')).toBe(true);
55
- });
56
- });
57
-
58
- describe('Round-trip Compatibility', function () {
59
- it('Should round-trip JavaScript code correctly', function () {
60
- const code = '$.getScript("test.js");';
61
- const p1 = new Passage('Test', code);
62
- const html = p1.toTwine2HTML();
63
-
64
- // Verify that the quotation marks is encoded.
65
- expect(html.includes('&quot')).toBe(true);
66
- });
67
-
68
- it('Should generate valid Story HTML with unencoded content', function () {
69
- const story = new Story();
70
- story.name = 'Test Story';
71
- story.IFID = 'TEST-IFID-1234';
72
-
73
- const p1 = new Passage('Start', '<%\nconsole.log("test");\n%>');
74
- const p2 = new Passage('HUD', '<h1>Header</h1>');
75
-
76
- story.passages = [p1, p2];
77
-
78
- const html = story.toTwine2HTML();
79
-
80
- // Verify both passages have encoded content.
81
- expect(html.includes('&quot;')).toBe(true);
82
- expect(html.includes('&lt;h1&gt;')).toBe(true);
83
- });
84
- });
85
-
86
- describe('Edge Cases', function () {
87
- it('Should handle CDATA-like content', function () {
88
- const content = '<![CDATA[Some data]]>';
89
- const p = new Passage('Test', content);
90
- const html = p.toTwine2HTML();
91
-
92
- expect(html.includes('&lt;![CDATA[Some data]]&gt;')).toBe(true);
93
- });
94
-
95
- it('Should handle mixed quotes', function () {
96
- const content = `var str = "She said 'hello' to me";`;
97
- const p = new Passage('Test', content);
98
- const html = p.toTwine2HTML();
99
-
100
- expect(html.includes('&quot;')).toBe(true);
101
- });
102
-
103
- it('Should handle template literals', function () {
104
- const content = 'const msg = `Hello ${name}`;';
105
- const p = new Passage('Test', content);
106
- const html = p.toTwine2HTML();
107
-
108
- expect(html.includes(content)).toBe(true);
109
- });
110
- });
111
- });