Code Monkey home page Code Monkey logo

extwee's Introduction

codecov

npm version

License: MIT

NPM Badge

Table of Contents

  1. Story Compilation
  2. Format Support
  3. Node and Web API
    1. Objects
    2. Parsers
    3. Compilers
  4. Documentation
  5. Command-Line Usage
  6. Escaping Meta-Characters
  7. License

Story Compilation

The process of story compilation converts human-readable content, what is generally called a story, into a playable format such as HyperText Markup Language (HTML). The result is then presented as links or other visual, interactive elements for another party to interact with to see its content.

The term compilation is used because different parts of code are put together in a specific arrangement to enable later play. As part of Twine-compatible HTML, this means combining JavaScript code (generally a "story format") with story HTML data.

Extwee is not an authoring tool. It cannot be used to create story content. This data must be created using other tools or processes. Extwee can then compile the content with story format code to produce something playable.

Playable formats are the following and require external story formats1 to enable play:

  • Twine 2 HTML
  • Twine 1 HTML

More human-readable formats include:

  • Twee 32
  • Twine 2 JSON3

From 2009 to 2015, Twine 1 supported a now historical format named TWS. This was a binary format used for archival purposes. Extwee can read this format but does not support creating it because no other tools, including current versions of Twine, accept it as valid input.

Twine 2 supports exporting a collection of stories (known as a library) in the Twine 2 Archive HTML format. Extwee can also read and write this format, creating either a collection of stories from the data or writing a collection of internal objects to a file.

Format Support

Extwee supports multiple historical and current Twine-compatible formats.

Format Input Output
Twine 1 HTML (2006 - 2015) Yes Partial support. Twine 1 HTML can be produced, but the StorySettings optional passage introduced in Twine 1.4.0 requires external libraries like jQuery not included with Extwee.
Twine 1 TWS (2009 - 2015) Yes Extwee does not support TWS (Python pickle) output because no current version of Twine or other story compilation tool produces this historical format.
Twine 2 HTML (2015 - Present) Yes Yes
Twine 2 Archive HTML (2015 - Present) Yes Yes
Twee 3 (2021 - Present) Yes Yes
Twine 2 JSON (2023 - Present) Yes Yes

Note: Round-trip translations can present problems because of required fields and properties per format. Some metadata may be added or removed based on the specification being followed.

(back to top)

Node and Web API

The following objects and methods are available in Node.js or browser contexts.

Note: When used in a browser context, all objects and methods are part of the window.Extwee global.

Objects

An object must be created using either the new keyword in JavaScript or as the result of parsing data.

  • StoryFormat
  • Passage
  • Story

Story and Passage objects can generate multiple output formats: toTwee(), toTwine1HTML(), toTwine2HTML(), and toJSON(). Stories cannot be played in a browser without the corresponding compiler combining it with story format data.

(back to top)

Parsers

Translates output formats such as HTML, Twee, JSON, or JSONP into objects.

Note: Twine 1 story formats exist across multiple files (header.html and optional code.js). They cannot be parsed into a StoryFormat object.

  • parseTwee()
  • parseJSON()
  • parseStoryFormat()
  • parseTwine1HTML()
  • parseTwine2HTML()
  • parseTwine2ArchiveHTML()

(back to top)

Compilers

Compiles story, story formats, or other data into an archive or playable format.

  • compileTwine2HTML()
  • compileTwine1HTML()
  • compileTwine2ArchiveHTML()

Note: In order to create playable Twine 1 HTML, an engine.js file must be supplied.

Support Functionality

Multiple Twine formats support using an IFID to identify one work from another.

As part of its API, the Extwee method generateIFID() can be used to create a new IFID for a Story object or as part of other processes.

(back to top)

Documentation

Extwee has documentation hosted on GitHub Pages.

(back to top)

Command-Line Usage

Extwee supports a command-line interface for four general scenarios:

Compiling Twee 3 + Twine 2 Story Format into Twine 2 HTML

Compile Twee 3 + StoryFormat into Twine 2 HTML:

extwee -c -i <tweeFile> -s <storyFormat> -o <Twine2HTML>

De-compiling Twine 2 HTML into Twee 3

De-compile Twine 2 HTML into Twee 3:

extwee -d -i <twine2HTML> -o <outputTwee>

Compiling Twee 3 into Twine 1 HTML

Enabling Twine 1 mode requires using the -t1 or --twine1 flag.

Because Twine 1 story formats can be split across files, compilation requires the "engine" from Twine 1 named engine.js, the name of the story format, and then its header.html template code and the optional but often included code.js file.

extwee -t1 -c -i <tweeFile> -o <Twine1HTML> -engine <engineJS> -name <storyFormatName> -codejs <CodeJS> -header <header>

De-compiling Twine 1 HTML into Twee 3

Enabling Twine 1 mode requires using the -t1 or --twine1 flag.

extwee -t1 -d -i <twine1HTML> -o <outputTwee>

(back to top)

Roadmap

Each major version has its own GitHub project:

Tree Shaking Support

For advanced tree shaking patterns, most formats are broke into compile.js and parse.js files exporting associated compile() and parse() functions. When using the API, it is possible to only import a single function or object to produce smaller and potentially faster code in projects dependent on Extwee functionality.

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Footnotes

  1. Extwee does not include or publish story formats. These can be found in the Story Format Archive (SFA).

  2. Twee exists in three versions. The first existed between 2006 to 2009 and was part of Twine 1. The move to Twine 2 in 2009 dropped support and the story compilation tools Twee2 and Tweego adopted their own extensions and modifications. Beginning in 2017, work was done to unite the different projects. This resulted in Twee 3 in March 2021.

  3. In October 2023, JavaScript Object Notation (JSON) was added as a supported community format for story compilation tools. Extwee is the first tool to support this format.

extwee's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar videlais avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

extwee's Issues

`StoryMetadata` vs `StoryData`

The twee3 spec calls the metadata passage StoryData. Extwee seems to be looking for a passage called StoryMetadata from what I can see in the source code. I have not actually tried out Extwee yet, but I plan to, so I don't want to give the impression I did.

Add browser testing of webpacked Extwee

  • Add testing of Webpack version of Extwee.
    • Parse (Twine 1 HTML, Twine 2 HTML, Twine 2 Archive HTML, Twine 1 TWS, and Twee)
    • Compile (Twine 1 HTML, Twine 2 HTML, and Twine 2 Archive HTML)
    • Generate Twee and JSON

(Borrow from TwineSpace's use of Jest Puppeteer with per-suite setup.)

Allow direct access to story passages

It'd be nice if I could work with the passages array directly instead of having to use indirect methods like forEachPassage(). One use case (related to #443) was that I wanted to set the start of a story to the first passage in the array (because I didn't care about the starting point; I just wanted to get HTML). I could see myself wanting to use map or reduce on the passages array for other purposes, too.

Search '{$npm}/lib/node_modules/extwee/story-formats' directory if a full path isn't provided.

It would be really helpful to be able to use ext wee -c file.twee -s chapbook-1.2.0 -o file.html where the story format is derived from the '{$npm}/lib/node_modules/extwee/story-formats' directory (using the latest version of a story format if a version number isn't provided, ie: "…-s chapbook …") if a full path (relative or absolute) isn't provided.

Having to always remember to enter the full path to various story-formats is a bit painful.

Stricter Twee output for required and optional StoryData properties

The ifid is the only required property of the StoryData passage.

The use of Story.toTwee() should:

  • Detect if internal IFID is not in UUIDv4 format, generate a warning, and create a new IFID.
  • Avoid generating format, format-version, start, tag-colors, or zoom unless those properties have non-default values.

Add documentation on CLI

Create documentation on the following:

  • Compiling Twee 3 + Twine 2 story format into Twine 2 HTML.
  • De-compiling Twine 2 HTML into Twee 3.
  • Compiling Twee 3 + Twine 1 engine.js + header.html + code.js into Twine 1 HTML.
  • De-compiling Twine 1 HTML into Twee 3.

Add support for searching SFA JSON download

Following downloading JSON database file, allow users to search for specific versions of story formats.

In Twine, story formats are saved as part of a story-formats.json file using the following format:

[
  {
  "id": "UUIDv4",
  "name": "Story Format Name",
  "version": "Semantic Version",
  "url": "relative location in the story-formats folder",
  "userAdded": true
  }
]

Consider TypeScript types

Even if you're not particularly in love with TypeScript, adding declarations makes life easier for those (being self-serving here) who do and doesn't force you into a TypeScript workflow. If you're interested in getting help with this, it's something I could probably pitch in with.

Expand API

  • Add parseJSON()
  • Add parseTwine1HTML()
  • Add parseTwine2ArchiveHTML()
  • Add compileTwine2ArchiveHTML()
  • Add compileTwine1HTML()

Add support for Twine 2 Archive

Read and write Twine 2 Archive files.

An archive is "one or more" <tw-storydata> elements.

  • Add Twine2ArchiveParser.js + tests
  • Add Twine2ArchiveWriter.js + tests

Add: All objects should be well-documented

Passage, Story, and StoryFormat should be well-documented:

  • Every property should be included as @property field.
  • Every class should have @class and @classdescfields.
  • Every class should have @example.

Parsing Twine 2 HTML doesn't unescape passage text

const story = parseTwine2HTML(`<tw-storydata name="test" ifid="test" startnode="1">
  <tw-passagedata name="test" pid="1">&lt;&quot;&apos;</tw-passagedata>
</tw-storydata>`);

console.log(story.getPassageByName('test').text);

yields &lt;&quot;&apos;. I think it should return <"' instead. This came up when I converted HTML output by Twine to Twee by doing essentially parseTwine2HTML(source).toTwee()--I end up with Twee source like this:

&gt; [[&quot;We&#x27;re both exhausted.&quot;]]

Command to help manage/update story-formats.

Instead of editing the formats by hand using the '{$npm}/lib/node_modules/extwee/story-formats' directory it would be helpful to be able to list, add, remove, and update the various story formats via the extwee command. Tweego has the ability to list the story-formats currently available in its configured story-format directory which is very helpful as the directory is usually easy to access (as the user has had to specify it) and can be configured via the TWEEGO_PATH environment variable.

Another option would be to provide users with a command that would open a Finder (or Windows and Linux equivalent) window containing the story-formats directory which would enable users to easily manage the various story-formats on their own.

Add: Every parse and compile should reference spec or doc

Every parse() and compile() function should reference specific Twine Specs file using @link{} JSDocs:

  • JSON parse
  • StoryFormat parse
  • Twee parse
  • Twine 1 HTML compile
  • Twine 1 HTML parse
  • Twine 2 HTML compile
  • Twine 2 HTML parse
  • Twine 2 Archive HTML parse
  • Twine 2 Archive HTML compile
  • Twine 1 TWS parse

Add JSDocs

Add JSDocs support for generating API documentation.

  • Add docs folder.
  • Add JSDocs.
  • Add clean theme.

Add documentation on API

Add documentation on the following:

  • Creating passage and story objects directly.
  • Exporting a story to Twee 3.
  • Exporting a story to Twine 2 JSON.
  • Combining a Twine 2 story format + Story into Twine 2 HTML.
  • Parsing Twine 2 JSON into Story.
  • Parsing Twine 1 HTML into Story (and Twee 3).
  • Dynamically creating passages.

Output attributes aren't escaped in HTML or Twee

I noticed that right now the output methods of Passage don't escape things outside of passage text that could cause parsing problems in the output. Some issues I see:

console.log(new Passage('"Test"', '', ['"bad"']).toTwine2HTML());

yields

<tw-passagedata pid="1" name=""Test"" tags=""bad"" ></tw-passagedata>

and on the Twee side:

console.log(new Passage('Where do tags begin? [well', '', ['hmm']).toTwee());

yields

:: Where do tags begin? [well [hmm]

The Twee spec is ambiguous about what to do here... FWIW, Twine outputs this currently:

:: Where do tags begin? \[well [hmm] {"position":"600,275","size":"100,100"}

Consider loose parsing modes

It'd be nice to optionally allow parsing HTML, for example, to permit missing attributes in <tw-storydata>. I get that you would want a strict mode by default, but it feels a bit overkill to block a story from being parsed if it's missing an IFID, for example.

Add support for saving compilation options in extwee.config.json

Originally, Extwee 2.0 was going to support a extwee.config.json file for saving compilation options between builds. This should return in Extwee 2.4 as part of SFA support (as it makes more sense to save the story format version from another database).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.