Skip to content

Instantly share code, notes, and snippets.

@videlais

videlais/HTMLWriter.js Secret

Created Jun 23, 2019
Embed
What would you like to do?
// Build <tw-storydata>
this.storyData +=
'<tw-storydata name="' + this.story.name + '" ' +
'startnode="' + this.story.getStartingPassage() + '" ' +
'creator="' + this.story.creator + '" ' +
'creator-version="' + this.story.creatorVersion + '" ' +
'ifid="' + this.story.metadata.ifid + '" ' +
'zoom="' + this.story.metadata.zoom + '" ' +
'format="' + this.storyFormat.name + '" ' +
'format-version="' + this.storyFormat.version + '" ' +
'options hidden>\n';
// Build the STYLE
this.storyData += '<style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css">';
// Get any passages tagged with 'style'
let stylePassages = this.story.getStylePassages();
// Iterate through the collection and add to storyData
for(let content of stylePassages) {
this.storyData += content.text;
}
this.storyData += '</style>\n';
// Build the SCRIPT
this.storyData += '<script role="script" id="twine-user-script" type="text/twine-javascript">';
// Get any passages tagged with 'script'
let scriptPassages = this.story.getScriptPassages();
// Iterate through the collection and add to storyData
for(let content of scriptPassages) {
this.storyData += content.text;
}
this.storyData += '</script>\n';
// All the script data has been written.
// Delete all 'script'-tagged passages
this.story.deleteAllByTag("script");
// All the style data has been written.
// Delete all 'style'-tagged passages
this.story.deleteAllByTag("style");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment