I have found that if you create a JavaScript tag inside a passage, and inside that tag you code a link using the function “write”, the linked passage is automatically created and/or linked in Twine’s visual editor:
[JavaScript]
write ("[[Go left]]");
[continue]
It automatically creates a passage named “Go left” (if it yet didn’t existed) and adds a visual connection to it.
For the same reason that having Link Markup in a comment does.
eg. The “find all links within a Passage” feature doesn’t understand what JavaScript code is either, so it just sees the [[Go left]] and decides that it looks like a standard Markup based link.
Using a String variable literal that contains mark-up link like characters will also trick the feature…
engine.extend('1.0.0', () => {
engine.event.prependListener('dom-click', el => {
let vars = el.dataset.cbSetVars;
if (vars) {
let result = engine.render(vars.replace(';',"\n")+"\n--");
}
});
config.template.inserts = [{
match: /^set\s+link/i,
render(passage, props) {
if (passage) {
return `<a href='javascript:void(0)'
data-cb-go="${passage}"
data-cb-set-vars="${props.set}">${props.label}</a>`;
}
}
}, ...config.template.inserts];
});
You can use it like a link {set link: 'Another passage', label: 'A link', set: 'foo: 2'}. The code in set is like the vars section, except that you can indicate multiple lines with a ; instead of a line break.
e.g. {set link: 'Another passage', label: 'A link', set: 'foo: 2;bar: 4;name "hello"'}
The straight quotation marks are converted into curly quotation marks, and the returned value is rendered as a string, not as a link.
Its really messy to mix different types of quotation marks.
But if you set the value of the variable “name” outside the insert (fin the vars section, for example) the code works flawlessly.
You’re missing a colon after name, I believe. Though that probably has nothing to do with the curly quotes rendering problem. I only mention it, just in case.
By the way, I’m learning so much about Chapbook from your questions and the answers from others. Thanks for that.
Changing out all of the typographic (curly) quotes, both single and double, for regular quotes will probably fix the problems you’re having. Even if you do have other issues to work out, you still need to do that as typographic quotes are not valid syntax.
It’s Chapbook that’s converting all straight quotes of " and ' to the curly variety. Javier is sharing the rendered output of how Chapbook is corrupting the code, I believe. I do know that Javier submitted the bug already and Chris acknowledged it and is on it. It’s just that David suggested a solution that seems to be prone to the curly quote bug after the bug was brought to light in another thread…
Holy crap! That’s perfect! Chris really went the extra mile with his code commenting. It reads like documentation. This is awesome and overwhelming at the same time. Still have to follow the breadcrumb trail to piece it all together, but it’s there. *mind blown*
I think this is not the same bug–issue with the code is that it’s inserting the value of set directly into HTML without escaping the quotation marks around "hello" in the example, so it returns HTML that closes the attribute too soon: <a ... data-set="name: "hello"">.
Here’s a tweak that works for me and also avoids the issue of having to use prependListener: