tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

An equivalent of 'nobr' that strips leading and trailing spaces #28

Closed inde3d closed 4 years ago

inde3d commented 4 years ago

Would it be possible to create an equivalent of the nobr tag that strips leading and trailing spaces from the output?

Currently you're required to either use line continuation markup, which is hard to deal with in long code, use Javascript, which is sometimes overkill for the things I want to do, or just put everything into one line, which is impractical with complicated code.

tmedwards commented 4 years ago

If you mean the leading and trailing whitespace from the passage content string as a whole or from each line of the passage content string, then you should be able to use the Config.passages.onProcess setting to accomplish your goal either way—be sure to read the accompanying note.

For the former:

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

For the latter:

Config.passages.onProcess = function (p) {
    return p.text.split(/\n/).map(function (l) { return l.trim(); }).join('\n');
};

If neither of those is what you meant, then you'll have to be more specific.

tmedwards commented 4 years ago

Closing this as the opener has not responded in over a month.