Closed klembot closed 9 months ago
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.
Three main changes to address this and #446:
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());
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() );
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.
[^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.
It'd be nice if I could pass a flag when calling Story.toTwine2HTML() to allow publishing without a start point set. In this case, I would expect it to not emit a
startnode
attribute ontw-storydata
.