Custom Markup/Fountain implementation Sugarcube

Twine: 2.36, Sugarcube 2.36.1

Hey there, I’m a screenwriter attempting to implement the fountain markup language in Twine. It would drastically help in the efficiency of the teams writing process, as some of the writers I’m working with are very code allergic, and I’m honestly pretty noob myself. I’ve found some javascript that should do most of the job here: GitHub - mattdaly/Fountain.js: A JavaScript parser for the screenplay format Fountain

I’ve tried using this on PassageInit and PassageReady passages, as well as dropping it directly into the Story Javascript to no avail. I’m a bit over my head and not sure what I’m doing wrong, would love any guidance you could offer.

Thanks so much
S

I wasn’t able to test this, but try the following in the Story JavaScript after the fountain code:

Config.passages.onProcess = function (p) {
	return fountain(p.text);
};

EDIT: You’ll also likely need to edit the final bit of the fountain code.

FIND:

}).call(this);

REPLACE WITH:

}).call(window);

The fountain() function returns an Object whose minimum structure is…

{
	title: '...',
	html: {
		title_page: '...',
		script: '...'
	}
}

…with the script property appearing to contain the HTML element structure generated for the processed Fountain mark-up.

Based on this fact the suggested Config.passages.onProcess handler may need to be changed to be…

Config.passages.onProcess = function (p) {
	return fountain(p.text).html.script;
};

Thank you both so much for your help on this! Indeed it is sort of doing something now… though it seems like I’ve lost the ability to use SugarCube markup… which kind of makes sense now that I think about it. If I format the links with raw html it still seems to work

Good catch. I should have looked more closely at that.

 

Assuming that you mean the link markup ([[…]]), looking at the Fountain.js code it’s the “note” markup that’s overriding it. If you don’t feel you need the note markup, you could always disable it.

EDIT: There’s also the possibility of turning it into a macro instead—e.g., <<fountain>>…<</fountain>>—so you only Fountain the bits you want, if that seems like something you could make work.

these are such good thoughts! the notes markup was totally the thing screwing me. You all are heroes.