Read about our upcoming Code of Conduct on this issue

Commit b5c72d45 authored by Leon Arnott's avatar Leon Arnott
Browse files

Fixed bugs involving <tw-expression>s within collapsed whitespace, and <tw-include> elements.

 * <br>s inside <tw-expression>s inside the collapsed syntax are no longer removed, in keeping with treatment of other whitespace.

 * Fixed a bug where <tw-include> elements were not being closed properly.

 * Altered the CodeMirror styles some more.
parent 23039563001a
......@@ -61,7 +61,7 @@ Rough documentation is at http://twine2.neocities.org/
* This syntax should also work with computed indexing (`(1 + 2) of $a`) and `it` indexing (`1st of it`).
* Added `(savegame:)` and `(loadgame:)`.
* `(savegame:)` saves the game session's state to the browser's local storage. It takes 2 values: a slot name string (you'll usually just use a string like "A" or "B") and a filename (something descriptive of the current game's state). Example usage: `(savegame: "A", "Beneath the castle catacombs")`.
* `(savegame:)` currently has a significant **limitation**: it will fail if the story's variables contain values which aren't strings, booleans, arrays, datamaps or datasets. If, for instance, you put a changer command in a variable, like `(set: $fancytext to (font:"Arnold Bocklin"))`, `(savegame:)` would no longer work. I must apologise for this, and hope to eliminate this problem in future versions.
* `(savegame:)` currently has a significant **limitation**: it will fail if the story's variables are ever `(set:)` to values which aren't strings, numbers, booleans, arrays, datamaps or datasets. If, for instance, you put a changer command in a variable, like `(set: $fancytext to (font:"Arnold Bocklin"))`, `(savegame:)` would no longer work. I must apologise for this, and hope to eliminate this problem in future versions.
* `(savegame:)` evaluates to a boolean `true` if it succeeds and `false` if it fails (because the browser's local storage is disabled for some reason). You should write something like `(if: (savegame:"A","At the crossroads") is false)[The game could not be saved!]` to provide the reader with an apology if `(savegame:)` fails.
* `(loadgame:)` takes one value - a slot name such as that provided to `(savegame:)` - and loads a game from that slot, replacing the current game session entirely. Think of it as a `(goto:)` - if it succeeds, the passage is immediately exited.
* Harlowe automatically records the names of existing save files in the datamap `$Saves`. The expression `$Saves contains "Slot name"` will be `true` if that slot name is currently used.
......
......@@ -67,7 +67,7 @@ function ($, Utils, Selectors, State, Section) {
+ Utils.escape(setupPassage.get('name'))
+ "'>"
+ setupPassage.get('source')
+ "</" + tagType + " " + ">";
+ "</tw-include>";
}
/**
......
......@@ -260,15 +260,31 @@
"font-weight:bold;",
"italic, em":
"font-style:italic;",
verbatim:
"background-color: hsla(0,0%,50%,0.1)",
twineLink: twineLink,
tag: "color: #4d4d9d;",
twineLink:
twineLink,
tag:
"color: #4d4d9d;",
boolean: "color: #626262;",
string: "color: #008282;",
number: "color: #A15000;",
variable: "color: #005682;",
hookRef: "color: #007f54;",
boolean:
"color: #626262;",
string:
"color: #008282;",
number:
"color: #A15000;",
variable:
"color: #005682;",
hookRef:
"color: #007f54;",
heading:
"font-weight:bold;",
hr:
"display:block; background-image: linear-gradient(0deg, transparent,transparent 45%, silver 45%, transparent 55%, transparent);",
align:
"display:block; color: hsl(14, 99%, 27%); background-color: hsla(14, 99%, 87%, 0.2);",
escapedLine: "font-weight:bold; color: hsl(51, 100%, 30%);",
......
......@@ -212,15 +212,20 @@ function($, Utils, Selectors, Renderer, Environ, State, HookUtils, HookSet, Pseu
@param {jQuery} elem The element whose whitespace must collapse.
*/
function collapse(elem) {
var finalNode, lastVisibleNode, verbatimNode;
var finalNode, lastVisibleNode;
/*
A .filter() callback which removes nodes inside a <tw-verbatim> or
<tw-expression> element.
*/
function noVerbatim (e) {
return $(e).parents('tw-verbatim, tw-expression').length === 0;
function noVerbatim(e) {
/*
The (this || e) dealie is a kludge to support its use in a jQuery
.filter() callback as well as a bare function.
*/
return $(this || e).parents('tw-verbatim, tw-expression').length === 0;
}
/*
- If the node contains <br>, replace with a single space.
*/
......@@ -237,7 +242,7 @@ function($, Utils, Selectors, Renderer, Environ, State, HookUtils, HookSet, Pseu
We can skip the entire remainder of this function with just
this line here.
*/
return (lastVisibleNode = new Text("A"));
return (lastVisibleNode = new Text("A"));
}
/*
- If the node contains runs of whitespace, reduce all runs to single spaces.
......
......@@ -404,12 +404,16 @@ describe("basic twinemarkup syntax", function() {
expect(p.find('span').attr('title')).toBe(" ");
expect(p.text()).toBe("");
});
it("as a result, it won't affect text inside macros", function() {
it("won't affect text inside macros", function() {
expectMarkupToPrint("{(print:'Red Blue''s length)}", "10");
});
it("furthermore, it won't affect text outputted by expressions", function() {
it("won't affect text outputted by expressions", function() {
expectMarkupToPrint("{(set: $a to 'Red Blue')(print:$a)}", "Red Blue");
});
it("won't affect text outputted by (display:)", function() {
createPassage("B\nC", "grault");
expectMarkupToPrint("A\n{(display:'grault')}", "A\nB\nC");
});
it("won't affect text inside verbatim guards", function() {
var p = runPassage("{ ` ` }");
expect(p.text()).toBe(" ");
......@@ -426,7 +430,7 @@ describe("basic twinemarkup syntax", function() {
expect(p.text()).toBe("AB");
p = runPassage("{ A (if:true)[ ] B }");
expect(p.text()).toBe("A B");
var p = runPassage("{ A (if:true)[ B ] C }");
p = runPassage("{ A (if:true)[ B ] C }");
expect(p.text()).toBe("A B C");
p = runPassage("{ A (if:true)[ B C ] D }");
expect(p.text()).toBe("A B C D");
......
......@@ -17,6 +17,12 @@ describe("setup passages", function() {
createPassage("Gee","header",[header]);
expectMarkupToPrint("wow","Geewow");
});
it("creates proper <tw-include> elements", function() {
createPassage("Gee","header",[header]);
var p = runPassage("wow");
expect(p.find('tw-include').text()).toBe("Gee");
expect(p.text()).toBe("Geewow");
});
it("tagged passages can be removed", function() {
createPassage("(set: $red to $red + 1)","header",[header]);
expectMarkupToPrint("$red","1");
......@@ -55,6 +61,12 @@ describe("setup passages", function() {
createPassage("gee","footer",[footer]);
expectMarkupToPrint("Wow","Wowgee");
});
it("creates proper <tw-include> elements", function() {
createPassage("wow","footer",[footer]);
var p = runPassage("Gee");
expect(p.find('tw-include').text()).toBe("wow");
expect(p.text()).toBe("Geewow");
});
it("tagged passages can be removed", function() {
createPassage("(set: $red to $red + 1)","footer",[footer]);
expectMarkupToPrint("$red","0");
......@@ -92,6 +104,12 @@ describe("setup passages", function() {
expectMarkupToPrint("$red","1");
expectMarkupToPrint("$red","1");
});
it("creates proper <tw-include> elements", function() {
createPassage("Gee","setup",[startup]);
var p = runPassage("wow");
expect(p.find('tw-include').text()).toBe("Gee");
expect(p.text()).toBe("Geewow");
});
it("tagged passages run in alphabetical order", function() {
createPassage("(set: $red to 'A')","setup1",[startup]);
createPassage("(set: $red to $red + 'B')","setup2",[startup]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment