From 88c6377432c7786580820945229b11f6bfed378b Mon Sep 17 00:00:00 2001 From: Dan Cox Date: Thu, 21 Sep 2023 14:39:20 -0400 Subject: [PATCH] Updating naming for Twine1HTML and Twine2HTML --- index.js | 12 +-- src/JSONParser.js | 4 + src/JSONWriter.js | 4 + src/TWSParser.js | 4 + src/{HTMLParser.js => Twine2HTMLParser.js} | 10 +- src/{HTMLWriter.js => Twine2HTMLWriter.js} | 8 +- test/Roundtrip.test.js | 10 +- test/Roundtrip/round.html | 2 +- test/TweeWriter/test1.twee | 2 +- test/TweeWriter/test5.twee | 2 +- test/TweeWriter/test6.twee | 2 +- test/TweeWriter/test7.twee | 2 +- ...arser.test.js => Twine2HTMLParser.test.js} | 100 +++++++++--------- .../Example1.html | 0 .../Tags.html | 0 .../lyingStartnode.html | 0 .../lyingTagColors.html | 0 .../missingCreator.html | 0 .../missingCreatorVersion.html | 0 .../missingFormat.html | 0 .../missingFormatVersion.html | 0 .../missingIFID.html | 0 .../missingName.html | 0 .../missingPID.html | 0 .../missingPassageName.html | 0 .../missingPassageTags.html | 0 .../missingPosition.html | 0 .../missingScript.html | 0 .../missingSize.html | 0 .../missingStartnode.html | 0 .../missingStyle.html | 0 .../missingZoom.html | 0 .../tagColors.html | 0 .../twineExample.html | 0 .../twineExample2.html | 0 .../twineExample3.html | 0 ...riter.test.js => Twine2HTMLWriter.test.js} | 70 ++++++------ .../TestTags.html | 0 .../creator.html | 2 +- .../example6.twee | 0 .../missingStoryTitle.twee | 0 .../test11.html | 0 .../test2.html | 0 .../test3.html | 0 .../test4.html | 2 +- .../test6.html | 2 +- 46 files changed, 125 insertions(+), 113 deletions(-) rename src/{HTMLParser.js => Twine2HTMLParser.js} (97%) rename src/{HTMLWriter.js => Twine2HTMLWriter.js} (97%) rename test/{HTMLParser.test.js => Twine2HTMLParser.test.js} (57%) rename test/{HTMLParser => Twine2HTMLParser}/Example1.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/Tags.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/lyingStartnode.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/lyingTagColors.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingCreator.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingCreatorVersion.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingFormat.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingFormatVersion.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingIFID.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingName.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingPID.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingPassageName.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingPassageTags.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingPosition.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingScript.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingSize.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingStartnode.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingStyle.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/missingZoom.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/tagColors.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/twineExample.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/twineExample2.html (100%) rename test/{HTMLParser => Twine2HTMLParser}/twineExample3.html (100%) rename test/{HTMLWriter.test.js => Twine2HTMLWriter.test.js} (73%) rename test/{HTMLWriter => Twine2HTMLWriter}/TestTags.html (100%) rename test/{HTMLWriter => Twine2HTMLWriter}/creator.html (99%) rename test/{HTMLWriter => Twine2HTMLWriter}/example6.twee (100%) rename test/{HTMLWriter => Twine2HTMLWriter}/missingStoryTitle.twee (100%) rename test/{HTMLWriter => Twine2HTMLWriter}/test11.html (100%) rename test/{HTMLWriter => Twine2HTMLWriter}/test2.html (100%) rename test/{HTMLWriter => Twine2HTMLWriter}/test3.html (100%) rename test/{HTMLWriter => Twine2HTMLWriter}/test4.html (99%) rename test/{HTMLWriter => Twine2HTMLWriter}/test6.html (99%) diff --git a/index.js b/index.js index 42678cdc..17d11361 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,8 @@ import FileReader from './src/FileReader.js'; import TweeParser from './src/TweeParser.js'; import TweeWriter from './src/TweeWriter.js'; import StoryFormatParser from './src/StoryFormatParser.js'; -import HTMLParser from './src/HTMLParser.js'; -import HTMLWriter from './src/HTMLWriter.js'; +import Twine2HTMLParser from './src/Twine2HTMLParser.js'; +import Twine2HTMLWriter from './src/Twine2HTMLWriter.js'; import Story from './src/Story.js'; import Passage from './src/Passage.js'; import StoryFormat from './src/StoryFormat.js'; @@ -14,8 +14,8 @@ export { StoryFormat }; export { Passage }; export { Story }; export { StoryFormatParser }; -export { HTMLParser }; -export { HTMLWriter }; +export { Twine2HTMLParser }; +export { Twine2HTMLWriter }; // Export everything by default export default { @@ -26,6 +26,6 @@ export default { Passage, Story, parseStoryFormat: StoryFormatParser.parse, - parseHTML: HTMLParser.parse, - writeHTML: HTMLWriter.write + parseHTML: Twine2HTMLParser.parse, + writeHTML: Twine2HTMLWriter.write }; diff --git a/src/JSONParser.js b/src/JSONParser.js index b309332c..d559277c 100644 --- a/src/JSONParser.js +++ b/src/JSONParser.js @@ -2,6 +2,10 @@ import Story from './Story.js'; import StoryFormat from './StoryFormat.js'; import Passage from './Passage.js'; +/** + * @class JSONParser + * @module JSONParser + */ export default class JSONParser { /** * Import JSON string and return Story object. diff --git a/src/JSONWriter.js b/src/JSONWriter.js index 0f6742be..5e5abf03 100644 --- a/src/JSONWriter.js +++ b/src/JSONWriter.js @@ -2,6 +2,10 @@ import Story from './Story.js'; import StoryFormat from './StoryFormat.js'; import Passage from './Passage.js'; +/** + * @class JSONWriter + * @module JSONWriter + */ export default class JSONWriter { /** * Export Story as JSON string. diff --git a/src/TWSParser.js b/src/TWSParser.js index 782be2c6..6a03f67b 100644 --- a/src/TWSParser.js +++ b/src/TWSParser.js @@ -2,6 +2,10 @@ import Story from './Story.js'; import Passage from './Passage.js'; import { Parser } from 'pickleparser'; +/** + * @class TWSParser + * @module TWSParser + */ export default class TWSParser { /** * Parse TWS file (as Buffer) into Story. diff --git a/src/HTMLParser.js b/src/Twine2HTMLParser.js similarity index 97% rename from src/HTMLParser.js rename to src/Twine2HTMLParser.js index d57efbbe..f772ac5c 100644 --- a/src/HTMLParser.js +++ b/src/Twine2HTMLParser.js @@ -7,10 +7,10 @@ import { parse as HtmlParser } from 'node-html-parser'; import Story from './Story.js'; import Passage from './Passage.js'; /** - * @class HTMLParser - * @module HTMLParser + * @class Twine2HTMLParser + * @module Twine2HTMLParser */ -export default class HTMLParser { +export default class Twine2HTMLParser { /** * Parse HTML text into a JS DOM-like object * @public @@ -168,7 +168,7 @@ export default class HTMLParser { // Does name exist? if (Object.prototype.hasOwnProperty.call(attr, 'name')) { // Escape the name - name = HTMLParser.escapeMetacharacters(attr.name); + name = Twine2HTMLParser.escapeMetacharacters(attr.name); } else { console.warn('Encountered passage without a name! Will not add.'); } @@ -181,7 +181,7 @@ export default class HTMLParser { // (Attributes can, themselves, be empty strings.) if (attr.tags.length > 0 && attr.tags !== '""') { // Escape the tags - tags = HTMLParser.escapeMetacharacters(attr.tags); + tags = Twine2HTMLParser.escapeMetacharacters(attr.tags); // Split by spaces into an array tags = tags.split(' '); } diff --git a/src/HTMLWriter.js b/src/Twine2HTMLWriter.js similarity index 97% rename from src/HTMLWriter.js rename to src/Twine2HTMLWriter.js index 461619dd..3d996d24 100644 --- a/src/HTMLWriter.js +++ b/src/Twine2HTMLWriter.js @@ -11,10 +11,10 @@ import StoryFormat from './StoryFormat.js'; import { v4 as uuidv4 } from 'uuid'; /** - * @class HTMLWriter - * @module HTMLWriter + * @class Twine2HTMLWriter + * @module Twine2HTMLWriter */ -export default class HTMLWriter { +export default class Twine2HTMLWriter { /** * Write story to file using story format and adding any CSS and JS * @public @@ -174,7 +174,7 @@ export default class HTMLWriter { storyData += `size="${passage.metadata.size}" `; } - storyData += `>${HTMLWriter.escape(passage.text)}\n`; + storyData += `>${Twine2HTMLWriter.escape(passage.text)}\n`; }); storyData += ''; diff --git a/test/Roundtrip.test.js b/test/Roundtrip.test.js index 180806b7..3862e640 100644 --- a/test/Roundtrip.test.js +++ b/test/Roundtrip.test.js @@ -1,16 +1,16 @@ import TweeWriter from '../src/TweeWriter.js'; import FileReader from '../src/FileReader.js'; import TweeParser from '../src/TweeParser.js'; -import HTMLParser from '../src/HTMLParser.js'; +import Twine2HTMLParser from '../src/Twine2HTMLParser.js'; import StoryFormatParser from '../src/StoryFormatParser.js'; -import HTMLWriter from '../src/HTMLWriter.js'; +import Twine2HTMLWriter from '../src/Twine2HTMLWriter.js'; describe('Round-trip testing', () => { it('Should round-trip HTML-to-Twee', () => { // Read HTML const fr = FileReader.read('test/Roundtrip/Example1.html'); // Parse HTML - const s = HTMLParser.parse(fr); + const s = Twine2HTMLParser.parse(fr); // Write Story into Twee TweeWriter.write(s, 'test/Roundtrip/example1.twee'); // Read new Twee file @@ -33,11 +33,11 @@ describe('Round-trip testing', () => { // Parse Twee const story = TweeParser.parse(fr); // Write HTML - HTMLWriter.write('test/Roundtrip/round.html', story, sfp); + Twine2HTMLWriter.write('test/Roundtrip/round.html', story, sfp); // Read HTML const fr2 = FileReader.read('test/Roundtrip/round.html'); // Parse HTML - const story2 = HTMLParser.parse(fr2); + const story2 = Twine2HTMLParser.parse(fr2); // Number of passages should be the same, too expect(story2.size()).toBe(story.size()); // IFID should be the same diff --git a/test/Roundtrip/round.html b/test/Roundtrip/round.html index 85a6b0cd..fe0e781f 100644 --- a/test/Roundtrip/round.html +++ b/test/Roundtrip/round.html @@ -11,7 +11,7 @@ -