Git Product home page Git Product logo

Comments (2)

videlais avatar videlais commented on July 17, 2024

That makes sense to me. Like I mentioned on #446, I'm okay with being stricter on the required attributes (name and ifid) and looser on the optional ones. Like you mention, if they are not set, they should not be emitted.

from extwee.

videlais avatar videlais commented on July 17, 2024

Three main changes to address this and #446:

Only name and ifid are required, as per the spec. Parsing valid Twine 2 HTML requires these attributes; optional attributes will not be emitted if they are not set.

import { parseTwine2HTML } from 'extwee';

// `name` and `ifid` are required attributes.
// (Errors will be thrown if they are missing.)
const source = `<tw-storydata name="Blah" ifid="1234"></tw-storydata>`;

// Parse the HTML into a Story.
const s2 = parseTwine2HTML(source);

// `creator` and `creator-version` are optional attributes.
// Extwee sets them to its own name and version by default.
s2.creator = '';
s2.creatorVersion = '';

// Convert back into HTML.
// Produces `<tw-storydata name="Blah" ifid="1234" options hidden>\n</tw-storydata>`
console.log(s2.toTwine2HTML());

The method generateIFID() is now exposed as separate functionality.1

import { Story, generateIFID } from 'extwee';

// Create a new story
const s = new Story();

// Generate a new IFID.
s.IFID = generateIFID();

// Output the story as Twine 2 HTML.
console.log( s.toTwine2HTML() );

Conversion is less restrictive than compilation

Calls to toTwine2HTML() will convert whatever is available. However, trying to call compileTwine2HTML() when missing required attributes (either name or ifid) or when the IFID is not in the UUIDv4 format will throw errors. Technically, since startnode is optional per the spec, it is also now possible to create a story that will never play.

Footnotes

  1. Ideally, there should be a separate repo for generating IFIDs authoring and archiving tools following the Treaty of Babel can all use. There is ifid, but it has not been updated in six years and is GPL licensed. Maybe, as a future project, I'll do an updated fork.

from extwee.

Related Issues (20)

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.