Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow publishing stories without a starting passage set #443

Closed
klembot opened this issue Jan 9, 2024 · 2 comments · Fixed by #449
Closed

Allow publishing stories without a starting passage set #443

klembot opened this issue Jan 9, 2024 · 2 comments · Fixed by #449
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@klembot
Copy link

klembot commented Jan 9, 2024

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 on tw-storydata.

@videlais videlais self-assigned this Jan 9, 2024
@videlais videlais added this to the Extwee 2.2.2 milestone Jan 9, 2024
@videlais videlais added the enhancement New feature or request label Jan 9, 2024
@videlais
Copy link
Owner

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.

@videlais
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants