extwee 1.6.2 → 2.0.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.
Files changed (151) hide show
  1. package/.eslintrc.json +25 -24
  2. package/.github/workflows/nodejs.yml +24 -24
  3. package/.travis.yml +13 -13
  4. package/CODE_OF_CONDUCT.md +82 -0
  5. package/LICENSE +21 -21
  6. package/README.md +36 -205
  7. package/SECURITY.md +12 -0
  8. package/babel.config.json +22 -0
  9. package/bin/extwee.js +49 -0
  10. package/index.js +31 -26
  11. package/package.json +60 -45
  12. package/src/FileReader.js +33 -35
  13. package/src/HTMLParser.js +343 -206
  14. package/src/HTMLWriter.js +196 -172
  15. package/src/Passage.js +202 -24
  16. package/src/Story.js +461 -122
  17. package/src/StoryFormat.js +300 -28
  18. package/src/StoryFormatParser.js +142 -59
  19. package/src/TweeParser.js +166 -207
  20. package/src/TweeWriter.js +98 -96
  21. package/story-formats/chapbook-1.2.0/format.js +1 -0
  22. package/story-formats/chapbook-1.2.0/logo.svg +1 -0
  23. package/story-formats/harlowe-1.2.4/format.js +1 -0
  24. package/story-formats/harlowe-1.2.4/icon.svg +78 -0
  25. package/story-formats/harlowe-2.1.0/format.js +2 -0
  26. package/story-formats/harlowe-2.1.0/icon.svg +78 -0
  27. package/story-formats/harlowe-3.1.0/format.js +3 -0
  28. package/story-formats/harlowe-3.1.0/icon.svg +78 -0
  29. package/story-formats/paperthin-1.0.0/format.js +1 -0
  30. package/story-formats/paperthin-1.0.0/icon.svg +5 -0
  31. package/story-formats/snowman-1.4.0/format.js +1 -0
  32. package/story-formats/snowman-1.4.0/icon.svg +436 -0
  33. package/story-formats/snowman-2.0.2/format.js +1 -0
  34. package/story-formats/snowman-2.0.2/icon.svg +436 -0
  35. package/story-formats/sugarcube-1.0.35/LICENSE +23 -0
  36. package/story-formats/sugarcube-1.0.35/format.js +1 -0
  37. package/story-formats/sugarcube-1.0.35/icon.svg +56 -0
  38. package/story-formats/sugarcube-2.31.1/LICENSE +22 -0
  39. package/story-formats/sugarcube-2.31.1/format.js +1 -0
  40. package/story-formats/sugarcube-2.31.1/icon.svg +56 -0
  41. package/test/{HTMLWriter/example7.twee → CLI/example6.twee} +16 -16
  42. package/test/CLI/harlowe.js +3 -0
  43. package/test/CLI/input.html +47 -0
  44. package/test/CLI/test.twee +18 -0
  45. package/test/CLI/test2.html +47 -0
  46. package/test/CLI/tweeExample.twee +17 -0
  47. package/test/CLI/twineExample.html +15 -0
  48. package/test/CLI.test.js +30 -0
  49. package/test/FileReader.test.js +14 -0
  50. package/test/HTMLParser/Example1.html +53 -0
  51. package/test/HTMLParser/Tags.html +15 -0
  52. package/test/HTMLParser/lyingStartnode.html +15 -0
  53. package/test/HTMLParser/lyingTagColors.html +48 -0
  54. package/test/HTMLParser/missingCreator.html +11 -0
  55. package/test/HTMLParser/missingCreatorVersion.html +11 -0
  56. package/test/HTMLParser/missingFormat.html +11 -0
  57. package/test/HTMLParser/missingFormatVersion.html +11 -0
  58. package/test/HTMLParser/missingIFID.html +11 -0
  59. package/test/HTMLParser/missingName.html +33 -0
  60. package/test/HTMLParser/missingPID.html +15 -0
  61. package/test/HTMLParser/missingPassageName.html +15 -0
  62. package/test/HTMLParser/missingPassageTags.html +15 -0
  63. package/test/HTMLParser/missingPosition.html +15 -0
  64. package/test/HTMLParser/missingScript.html +14 -0
  65. package/test/HTMLParser/missingSize.html +35 -0
  66. package/test/HTMLParser/missingStartnode.html +11 -0
  67. package/test/HTMLParser/missingStyle.html +14 -0
  68. package/test/HTMLParser/missingZoom.html +11 -0
  69. package/test/HTMLParser/tagColors.html +31 -0
  70. package/test/HTMLParser/twineExample.html +15 -46
  71. package/test/HTMLParser/twineExample2.html +15 -0
  72. package/test/HTMLParser/twineExample3.html +15 -0
  73. package/test/HTMLParser.test.js +177 -0
  74. package/test/HTMLWriter/TestTags.html +42 -0
  75. package/test/HTMLWriter/{test10.html → creator.html} +8 -5
  76. package/test/HTMLWriter/example6.twee +16 -16
  77. package/test/HTMLWriter/{example.twee → missingStoryTitle.twee} +29 -29
  78. package/test/HTMLWriter/test11.html +123 -0
  79. package/test/HTMLWriter/test2.html +15 -12
  80. package/test/HTMLWriter/test3.html +7 -13
  81. package/test/HTMLWriter/test4.html +8 -5
  82. package/test/HTMLWriter/test6.html +7 -5
  83. package/test/HTMLWriter.test.js +279 -0
  84. package/test/Passage.test.js +104 -0
  85. package/test/Roundtrip/Example1.html +64 -0
  86. package/test/Roundtrip/example1.twee +21 -0
  87. package/test/Roundtrip/example2.twee +18 -0
  88. package/test/Roundtrip/harlowe.js +3 -0
  89. package/test/Roundtrip/round.html +50 -0
  90. package/test/Roundtrip.test.js +48 -0
  91. package/test/Story/startmeta.twee +29 -29
  92. package/test/Story/test.twee +25 -25
  93. package/test/Story.test.js +282 -0
  94. package/test/StoryFormat.test.js +152 -0
  95. package/test/StoryFormatParser/example.js +3 -0
  96. package/test/StoryFormatParser/{test2.js → example2.js} +3 -3
  97. package/test/StoryFormatParser/format_doublename.js +1 -0
  98. package/test/StoryFormatParser/harlowe.js +2 -2
  99. package/test/StoryFormatParser/missingAuthor.js +1 -0
  100. package/test/StoryFormatParser/missingDescription.js +1 -0
  101. package/test/StoryFormatParser/missingImage.js +1 -0
  102. package/test/StoryFormatParser/missingLicense.js +1 -0
  103. package/test/StoryFormatParser/missingName.js +1 -0
  104. package/test/StoryFormatParser/missingProofing.js +1 -0
  105. package/test/StoryFormatParser/missingSource.js +1 -0
  106. package/test/StoryFormatParser/missingURL.js +1 -0
  107. package/test/StoryFormatParser/missingVersion.js +1 -0
  108. package/test/StoryFormatParser/versionWrong.js +1 -0
  109. package/test/StoryFormatParser.test.js +91 -0
  110. package/test/TweeParser/emptytags.twee +2 -2
  111. package/test/TweeParser/example.twee +32 -29
  112. package/test/TweeParser/missing.twee +19 -0
  113. package/test/{HTMLWriter/example5.twee → TweeParser/multipleScriptPassages.twee} +19 -13
  114. package/test/{HTMLWriter/example4.twee → TweeParser/multipleStyleTag.twee} +19 -13
  115. package/test/TweeParser/multipletags.twee +10 -2
  116. package/test/TweeParser/noTitle.twee +2 -0
  117. package/test/TweeParser/notes.twee +16 -32
  118. package/test/TweeParser/pasagemetadataerror.twee +2 -2
  119. package/test/{HTMLWriter/example2.twee → TweeParser/scriptPassage.twee} +16 -13
  120. package/test/TweeParser/singletag.twee +13 -2
  121. package/test/TweeParser/startMetadata.twee +14 -0
  122. package/test/TweeParser/storydataerror.twee +25 -25
  123. package/test/{HTMLWriter/example3.twee → TweeParser/stylePassage.twee} +16 -13
  124. package/test/TweeParser/test.twee +25 -25
  125. package/test/TweeParser.test.js +79 -0
  126. package/test/TweeWriter/test1.twee +14 -9
  127. package/test/TweeWriter/test3.twee +7 -10
  128. package/test/TweeWriter/test4.twee +14 -0
  129. package/test/TweeWriter/test5.twee +20 -0
  130. package/test/TweeWriter.test.js +82 -0
  131. package/main.js +0 -106
  132. package/src/DirectoryReader.js +0 -114
  133. package/src/DirectoryWatcher.js +0 -87
  134. package/test/DirectoryReader/css/test.css +0 -3
  135. package/test/DirectoryReader1/js/Site.js +0 -1
  136. package/test/DirectoryReader2/error.js +0 -1
  137. package/test/DirectoryReader2/example.css +0 -3
  138. package/test/DirectoryReader2/index.twee +0 -6
  139. package/test/DirectoryReader3/twee/index.twee +0 -6
  140. package/test/DirectoryWatcher/example.txt +0 -0
  141. package/test/DirectoryWatcher/test.txt +0 -0
  142. package/test/DirectoryWatcher/test1.txt +0 -0
  143. package/test/HTMLWriter/test5.html +0 -48
  144. package/test/HTMLWriter/test7.html +0 -48
  145. package/test/HTMLWriter/test8.html +0 -48
  146. package/test/HTMLWriter/test9.html +0 -48
  147. package/test/StoryFormatParser/test.js +0 -2
  148. package/test/TweeParser/test.twee3 +0 -11
  149. package/test/TweeWriter/metatest.twee +0 -12
  150. package/test/TweeWriter/test2.twee +0 -15
  151. package/test/test.js +0 -736
package/.eslintrc.json CHANGED
@@ -1,24 +1,25 @@
1
- {
2
- "env": {
3
- "commonjs": true,
4
- "es6": true,
5
- "node": true
6
- },
7
- "extends": [
8
- "standard",
9
- "plugin:jsdoc/recommended"
10
- ],
11
- "globals": {
12
- "Atomics": "readonly",
13
- "SharedArrayBuffer": "readonly"
14
- },
15
- "parserOptions": {
16
- "ecmaVersion": 2018
17
- },
18
- "rules": {
19
- "semi": ["error", "always"]
20
- },
21
- "plugins": [
22
- "jsdoc"
23
- ]
24
- }
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2020": true,
5
+ "jest/globals": true
6
+ },
7
+ "extends": [
8
+ "standard",
9
+ "plugin:jest/recommended",
10
+ "plugin:jsdoc/recommended"
11
+ ],
12
+ "parserOptions": {
13
+ "ecmaVersion": 11,
14
+ "sourceType": "module"
15
+ },
16
+ "rules": {
17
+ "semi": ["error", "always"]
18
+ },
19
+ "plugins": [
20
+ "jest",
21
+ "@babel",
22
+ "jsdoc"
23
+ ],
24
+ "parser": "@babel/eslint-parser"
25
+ }
@@ -1,24 +1,24 @@
1
- name: Node CI
2
-
3
- on: [push]
4
-
5
- jobs:
6
- build:
7
-
8
- runs-on: ubuntu-latest
9
-
10
- strategy:
11
- matrix:
12
- node-version: [12.x]
13
-
14
- steps:
15
- - uses: actions/checkout@v1
16
- - name: Use Node.js ${{ matrix.node-version }}
17
- uses: actions/setup-node@v1
18
- with:
19
- node-version: ${{ matrix.node-version }}
20
- - run: npm install
21
- - run: npm run lint
22
- - run: npm run test
23
- env:
24
- CI: true
1
+ name: Node CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ matrix:
12
+ node-version: [12.x]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v1
16
+ - name: Use Node.js ${{ matrix.node-version }}
17
+ uses: actions/setup-node@v1
18
+ with:
19
+ node-version: ${{ matrix.node-version }}
20
+ - run: npm install
21
+ - run: npm run lint
22
+ - run: npm run test
23
+ env:
24
+ CI: true
package/.travis.yml CHANGED
@@ -1,13 +1,13 @@
1
- language: node_js
2
-
3
- node_js:
4
- - "node"
5
-
6
- install:
7
- - npm install
8
- - npm install codecov
9
-
10
- script:
11
- - npm run test
12
- - npm run report-coverage
13
- - codecov
1
+ language: node_js
2
+
3
+ node_js:
4
+ - "node"
5
+
6
+ install:
7
+ - npm install
8
+ - npm install codecov
9
+
10
+ script:
11
+ - npm run test
12
+ - npm run report-coverage
13
+ - codecov
@@ -0,0 +1,82 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
7
+
8
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
9
+
10
+ ## Our Standards
11
+
12
+ Examples of behavior that contributes to a positive environment for our community include:
13
+
14
+ * Demonstrating empathy and kindness toward other people
15
+ * Being respectful of differing opinions, viewpoints, and experiences
16
+ * Giving and gracefully accepting constructive feedback
17
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
18
+ * Focusing on what is best not just for us as individuals, but for the overall community
19
+
20
+ Examples of unacceptable behavior include:
21
+
22
+ * The use of sexualized language or imagery, and sexual attention or advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email address, without their explicit permission
26
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
27
+
28
+ ## Enforcement Responsibilities
29
+
30
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
31
+
32
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
33
+
34
+ ## Scope
35
+
36
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
37
+
38
+ ## Enforcement
39
+
40
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to maintainer of this repository.
41
+
42
+ All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at `https://www.contributor-covenant.org/version/2/0/code_of_conduct.html`.
77
+
78
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
79
+
80
+ [homepage]: https://www.contributor-covenant.org
81
+
82
+ For answers to common questions about this code of conduct, see the FAQ at `https://www.contributor-covenant.org/faq`. Translations are available at `https://www.contributor-covenant.org/translations`.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 Dan Cox
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Dan Cox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,205 +1,36 @@
1
- [![Build Status](https://travis-ci.org/videlais/extwee.svg?branch=master)](https://travis-ci.org/videlais/extwee) [![codecov](https://codecov.io/gh/videlais/extwee/branch/master/graph/badge.svg)](https://codecov.io/gh/videlais/extwee)
2
-
3
- [![NPM Badge](https://nodei.co/npm/extwee.png?downloads=true)](https://www.npmjs.com/package/extwee)
4
-
5
- # Extwee 1.6.2
6
-
7
- Extwee is a Twee compiler supporting Twine 2-style formats using the [Twee 3 specification](https://github.com/iftechfoundation/twine-specs/blob/master/twee-3-specification.md).
8
-
9
- It will read both Twee 2 (Twee2) and Twee 3 formatted files, but does not understand or currently support Twee 1 (Twine 1.4.2) or Twee2 special passages for Twine 1.X formatting.
10
-
11
- *Extwee does not support Twine 1.X story formats.*
12
-
13
- ## Binary Releases
14
-
15
- Compiled versions for Windows, MacOS X, and Linux can be found under [Releases](https://github.com/videlais/extwee/releases)
16
-
17
- ## Story Formats
18
-
19
- Starting with Extwee 1.5, the latest versions of Harlowe (1.X, 2.X, and 3.X), SugarCube (1.X and 2.X) and Snowman (1.X) are now packaged with binary builds.
20
-
21
- ## Compatibility With Other Tools
22
-
23
- * Does not parse StorySettings
24
- * Does not parse `@includes`
25
- * Does not parse StoryIncludes
26
- * Does not handle [haml]; will not parse HAML
27
- * Does not handle [twee2] special passages
28
-
29
- ## Command-Line Usage
30
-
31
- When working with the binary builds of Extwee, the operating system is part of the file name. In Windows, for examples, the build is called `extwee-win.exe`.
32
-
33
- Extwee supports the following command-line arguments:
34
-
35
- * `i`: Input Twee file
36
- * `v`: Version of Extwee
37
- * `f`: Path to the Story Format's `format.js` file
38
- * `d`: HTML file to decompile into Twee code
39
- * `o`: Output file
40
- * `r`: Path of directory to read
41
- * `w`: Enable directory watching mode
42
-
43
- Using the command-line arguments, Extwee operates in four "modes":
44
- * Twee to HTML
45
-
46
- For simple, single-file compiling of Twee code into HTML, the arguments `i`, `o`, and `f` are used. These specify the input Twee file, the output HTML file, and the story format to use.
47
-
48
- `extwee-[OS] -i source.twee -o output.html -f path/format.js`
49
-
50
- * HTML to Twee
51
-
52
- For simple, single-file decompiling of HTML into Twee code, the arguments `d` and `o` are used. They specify the HTML file to read and the Twee file to create.
53
-
54
- `extwee-[OS] -d file.html -o source.twee `
55
-
56
- * Directory Reading
57
-
58
- For more complex, multiple file usage, the argument `r` can be used to read a directory. This is used with the `o` and `f` options to specify what output file and which story format to use.
59
-
60
- `extwee-[OS] -r path/ -o output.html -f path/format.js`
61
-
62
- * Directory Watching
63
-
64
- For more complex, multiple file usage, the argument `w` can be used to "watch" a directory for any new files or changes. While in this mode, Extwee will re-use the Directory Reading mode when it detects any additional files or changes. The specified output file will be re-build fresh each time.
65
-
66
- `extwee-[OS] -w path/ -o output.html -f path/format.js`
67
-
68
- ### File Formats
69
-
70
- When watching a directory, Extwee will look for `tw`, `tw2`, `tw3`, `twee`, `twee2`, and `twee3` files. All other modes will accept any text files as input.
71
-
72
- ### Escaping Metacharacters
73
-
74
- Extwee will attempt to escape the metacharacters of `{`, `}`, `[`, and `]` when moving to and from Twee notation. However, even with this support, it *highly recommended* to avoid these characters in passage name and tags to avoid confusion and potential issues.
75
-
76
- ## API Usage
77
-
78
- Extwee can be installed via NPM.
79
-
80
- `npm i extwee`
81
-
82
- As a NPM package, Extwee's objects can also be used independent of the binary builds as part of other projects. It exposes the following objects and their properties and functions.
83
-
84
- ### *FileReader*
85
-
86
- *FileReader* wraps *fs.existsSync* and *fs.readFileSync*. It accepts the path to a file and will throw an error if the file cannot be found or read.
87
-
88
- `let fr = new FileReader("path");`
89
-
90
- #### Properties
91
-
92
- * *contents*: The textual content of the read file.
93
-
94
- ### *TweeParser*
95
-
96
- *TweeParser* accepts Twee textual content and saves an internal *Story* object populated with any passages found.
97
-
98
- `let tp = new TweeParser("tweeContent");`
99
-
100
- #### Properties
101
-
102
- * *story*: The internal *Story* object created and populated during parsing.
103
-
104
- ### *TweeWriter*
105
-
106
- *TweeWriter* accepts a *Story* and path to file the Twee file.
107
-
108
- `let tw = new TweeWriter(Story, "path/");`
109
-
110
- ### *StoryFormat*
111
-
112
- *StoryFormat* accepts a JS object (and will throw an error if not).
113
-
114
- It is uncommon for *StoryFormat* to be used directly.
115
-
116
- #### Properties
117
-
118
- * *name*: Name of the story format.
119
- * *version*: Version of the story format.
120
- * *description*: Description of the story format.
121
- * *author*: Author of the story format.
122
- * *image*: Logo image URL
123
- * *url*: URL of story format
124
- * *license*: License of the story format
125
- * *proofing*: If story format is a proofing story format or not
126
- * *source*: The JS source of the story format
127
-
128
- ### *Passage*
129
-
130
- *Passage* represents a single passage in a Twine story. It accepts `name` (String), `tags` (Array), `metadata` (JS Object), `text` (String), and `pid` (Integer).
131
-
132
- It is uncommon for *Passage* to be used directly.
133
-
134
- #### Properties:
135
-
136
- * *name*: Name of passage.
137
- * *tags*: Array of any tags.
138
- * *metadata*: Object holding any passage metadata
139
- * *text*: Text of the passage.
140
- * *pid*: Passage Identification Number (PID)
141
-
142
- ### *Story*
143
-
144
- The *Story* object holds all information about a Twine story including its metadata, passages, and name.
145
-
146
- `let s = new Story();`
147
-
148
- #### Properties
149
-
150
- * *name*: Name of the story. (Defaults to "Unknown").
151
- * *metadata*: Story metadata represented by `StoryData` passage in Twee 3
152
- * *passages*: Array of *Passage* objects.
153
- * *creator*: Set to `package.json` name (i.e. Exwee).
154
- * *creatorVersion*: Set to `package.json` version.
155
-
156
- #### Functions
157
-
158
- * *getStylePassages()*: Returns an array of any passages with the tag "stylesheet".
159
- * *getScriptPassages()*: Returns an array of any passages with the tag "script".
160
- * *deleteAllByTag(tag)*: Deletes any passages with the tag `tag`.
161
- * *getStartingPassage()*: Returns the PID of the starting passage (either `Start` or `StoryData`'s' `start` override, if found).
162
-
163
- ### *StoryFormatParser*
164
-
165
- *StoryFormatParser* accepts the path to a story format's `format.js` file. Upon successful parsing, it keeps an internal *StoryFormat* object.
166
-
167
- `let sfp = new StoryFormatParser("path/format.js");`
168
-
169
- #### Properties
170
-
171
- * *storyFormat*: Either `null` (upon failure to parse) or a *StoryFormat* object
172
-
173
- ### *HTMLParser*
174
-
175
- *HTMLParser* accepts HTML content to parse. Upon successful parsing, it stores an internal *Story* object.
176
-
177
- #### Properties
178
-
179
- * *story*: Upon successful parsing, this object will hold the story and all passages found.
180
-
181
- ### *HTMLWriter*
182
-
183
- *HTMLWriter* accepts the path to an output file, a *Story* object, a *StoryFormat* object, and optional extra CSS and JS content.
184
-
185
- `let hw = new HTMLWriter("path/", Story, StoryFormat, extraCSS, extraJS)`
186
-
187
- ## Common API Usage Patterns
188
-
189
- ### Reading and Parsing a Twee file
190
- ```
191
- const Extwee = require("extwee");
192
-
193
- let file = new Extwee.FileReader("tweefile.twee");
194
- let tp = new Extwee.TweeParser(file.contents);
195
- // tp.story will hold the parsed story and passages
196
- ```
197
-
198
- ### Reading and Parsing a Twine 2 HTML file
199
- ```
200
- const Extwee = require("extwee");
201
-
202
- let file = new Extwee.FileReader("twine2.html");
203
- let hp = new Extwee.HTMLParser(file.contents);
204
- // hp.story will hold the parsed story and passages
205
- ```
1
+ # Status
2
+
3
+ [![Build Status](https://travis-ci.org/videlais/extwee.svg?branch=master)](https://travis-ci.org/videlais/extwee)
4
+
5
+ [![codecov](https://codecov.io/gh/videlais/extwee/branch/master/graph/badge.svg)](https://codecov.io/gh/videlais/extwee) [![npm version](https://badge.fury.io/js/extwee.svg)](https://badge.fury.io/js/extwee)
6
+
7
+ [![NPM Badge](https://nodei.co/npm/extwee.png?downloads=true)](https://www.npmjs.com/package/extwee)
8
+
9
+ ## Summary
10
+
11
+ Extwee is a Twee compiler supporting Twine 2-style formats using the [Twee 3 specification](https://github.com/iftechfoundation/twine-specs/blob/master/twee-3-specification.md).
12
+
13
+ It will read both Twee 2 (Twee2) and Twee 3 formatted files, but does not understand or currently support Twee 1 (Twine 1.4.2) or Twee2 special passages for Twine 1.X formatting.
14
+
15
+ *Extwee does not support Twine 1.X story formats.*
16
+
17
+ ## Story Formats
18
+
19
+ Starting with Extwee 1.5, the latest versions of Twine 2 story formats are included. See each story format for its own license.
20
+
21
+ ## Command-Line Usage
22
+
23
+ Extwee supports NPX commands:
24
+
25
+ * Compile: `npx extwee -c -i <input twee> -s <input story format JS> -o <output HTML>`
26
+ * Decompile: `npx extwee -d -i <input HTML> -o <output twee>`
27
+
28
+ ### Escaping Metacharacters
29
+
30
+ Extwee will attempt to escape the metacharacters of `{`, `}`, `[`, and `]` when moving to and from Twee notation. However, even with this support, it *highly recommended* to avoid these characters in passage name and tags to avoid confusion and potential issues.
31
+
32
+ ## Installation
33
+
34
+ Extwee can be installed via NPM.
35
+
36
+ `npm i extwee`
package/SECURITY.md ADDED
@@ -0,0 +1,12 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 1.6 | :x: |
8
+ | 2.0 | :white_check_mark: |
9
+
10
+ ## Reporting a Vulnerability
11
+
12
+ When reporting a vulnerability, start with an issue. This will be flagged and integrated into the current project and fast-tracked for a new version.
@@ -0,0 +1,22 @@
1
+ {
2
+ "plugins": [
3
+ ["@babel/plugin-proposal-class-properties", { "loose": true }],
4
+ ["@babel/plugin-proposal-private-methods" , { "loose": true }],
5
+ ["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
6
+ ],
7
+ "presets": [
8
+ [
9
+ "@babel/env",
10
+ {
11
+ "targets": {
12
+ "edge": "17",
13
+ "firefox": "60",
14
+ "chrome": "67",
15
+ "safari": "11.1"
16
+ },
17
+ "useBuiltIns": "usage",
18
+ "corejs": "3.8.0"
19
+ }
20
+ ]
21
+ ]
22
+ }
package/bin/extwee.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @fileoverview CLI for Extwee
5
+ * @author Dan Cox
6
+ */
7
+
8
+ // Import everything
9
+ import Extwee from '../index.js';
10
+ // Import Commander
11
+ import { Command } from 'commander';
12
+
13
+ // Creat a new Command
14
+ const program = new Command();
15
+
16
+ program
17
+ .version('2.0.0')
18
+ .option('-c', 'From Twee into HTML')
19
+ .option('-d', 'From HTML into Twee')
20
+ .option('-s <storyformat>', 'Path to storyformat')
21
+ .option('-i <inputFile>', 'Path to input file')
22
+ .option('-o <outputFile>', 'Path to output file');
23
+
24
+ // Set the process title
25
+ process.title = 'extwee';
26
+
27
+ // Parse the passed arguments
28
+ program.parse(process.argv);
29
+
30
+ // Create object of passed arguments parsed by Commander
31
+ const options = program.opts();
32
+
33
+ // Decompile branch
34
+ if(options.D === true) {
35
+ const inputHTML = Extwee.readFile(options.I);
36
+ const storyObject = Extwee.parseHTML(inputHTML);
37
+ Extwee.writeTwee(storyObject, options.O);
38
+ process.exit();
39
+ }
40
+
41
+ // Compile branch
42
+ if(options.C === true) {
43
+ const inputTwee = Extwee.readFile(options.I);
44
+ const story = Extwee.parseTwee(inputTwee);
45
+ const inputStoryFormat = Extwee.readFile(options.S);
46
+ const parsedStoryFormat = Extwee.parseStoryFormat(inputStoryFormat);
47
+ Extwee.writeHTML(options.O, story, parsedStoryFormat);
48
+ process.exit();
49
+ }
package/index.js CHANGED
@@ -1,26 +1,31 @@
1
- const FileReader = require('./src/FileReader.js');
2
- const TweeParser = require('./src/TweeParser.js');
3
- const TweeWriter = require('./src/TweeWriter.js');
4
- const StoryFormatParser = require('./src/StoryFormatParser.js');
5
- const HTMLParser = require('./src/HTMLParser.js');
6
- const HTMLWriter = require('./src/HTMLWriter.js');
7
- const DirectoryReader = require('./src/DirectoryReader.js');
8
- const DirectoryWatcher = require('./src/DirectoryWatcher.js');
9
- const Story = require('./src/Story.js');
10
- const Passage = require('./src/Passage.js');
11
- const StoryFormat = require('./src/StoryFormat.js');
12
-
13
- module.exports = {
14
- FileReader: FileReader,
15
- TweeParser: TweeParser,
16
- TweeWriter: TweeWriter,
17
- StoryFormat: StoryFormat,
18
- Passage: Passage,
19
- Story: Story,
20
- StoryFormatParser: StoryFormatParser,
21
- FileReader: FileReader,
22
- HTMLParser: HTMLParser,
23
- HTMLWriter: HTMLWriter,
24
- DirectoryReader: DirectoryReader,
25
- DirectoryWatcher: DirectoryWatcher
26
- };
1
+ import FileReader from './src/FileReader.js';
2
+ import TweeParser from './src/TweeParser.js';
3
+ import TweeWriter from './src/TweeWriter.js';
4
+ import StoryFormatParser from './src/StoryFormatParser.js';
5
+ import HTMLParser from './src/HTMLParser.js';
6
+ import HTMLWriter from './src/HTMLWriter.js';
7
+ import Story from './src/Story.js';
8
+ import Passage from './src/Passage.js';
9
+ import StoryFormat from './src/StoryFormat.js';
10
+
11
+ export { FileReader };
12
+ export { TweeParser };
13
+ export { StoryFormat };
14
+ export { Passage };
15
+ export { Story };
16
+ export { StoryFormatParser };
17
+ export { HTMLParser };
18
+ export { HTMLWriter };
19
+
20
+ // Export everything by default
21
+ export default {
22
+ readFile: FileReader.read,
23
+ parseTwee: TweeParser.parse,
24
+ writeTwee: TweeWriter.write,
25
+ StoryFormat,
26
+ Passage,
27
+ Story,
28
+ parseStoryFormat: StoryFormatParser.parse,
29
+ parseHTML: HTMLParser.parse,
30
+ writeHTML: HTMLWriter.write
31
+ };