Replies: 15 comments 30 replies
-
IIRC, an editor pane for variables was suggested at one point. While a worthy long term goal, the initial implementation would be via syntax within the brew. I would also suggest that maybe we could establish a convention of code-fencing the definitions, something like this.
|
Beta Was this translation helpful? Give feedback.
-
Collating various ideas seen in the wild:
Some are going well beyond the simplest implementation of course. |
Beta Was this translation helpful? Give feedback.
-
More discussion here, including solving the Halting Problem. |
Beta Was this translation helpful? Give feedback.
-
We could also look to how Twine handles variables https://twinery.org/cookbook/terms/terms_variables.html |
Beta Was this translation helpful? Give feedback.
-
Two ideas from reddit ..
An example might help: Consider a snippet template for a monster, NPC, magic item, or even spell. Within that block various variables are declared (e.g. character abilities of strength/wisdom/et al), and are available to be used within that block, either as simple outputs or in computed expresssions (e.g. a skill chance that is affected by an ability score). That much so far doesn't really call much need for scoping or objects. However, within that same block one could declare another variable — one which is not scoped — and stuff all those local variables into that object. Like this:
Above, the underscore |
Beta Was this translation helpful? Give feedback.
-
Some of our template snippets have smarts backstage to generate interesting content (instead of the exact same static text every time). Elsewhere, there has been discussion (#1870) of being able to dynamically edit/regen these template snippets (vs. needing to manually edit the raw output). I'm thinking these two features could be leveraged, perhaps like this:
Here locally scoped variables are declared for each property or attribute of the block (and then used in the block) .. and the snippet dynamic editor widget just looks for locally scoped variables to update with new values (either manually entered via a widget-wizard UI, or dynamically generated by scripting) This way the Side note: not 100% happy with this, as it means a snippet template doubles in size with all the variable declarations. |
Beta Was this translation helpful? Give feedback.
-
From gitter:
OK, if we use
See https://regex101.com/r/ViICSZ/ for details and test cases. |
Beta Was this translation helpful? Give feedback.
-
If we have structured variables like [monster.stats.STR], then it could be useful to have a variable definition that loads the variable value from an API.
A couple of such sources: |
Beta Was this translation helpful? Give feedback.
-
We can flag code blocks for specific purposes by exploiting the A possibility is to treat code-spans that start with a square-bracket Thus, this:
Renders as: <p>On a sunny day, we meet our hero Hrothgar the Mighty. [ed: does it have to be sunny?]</p> This way one-line variable declarations are succinct. Also solves the problem that "text blah blah [editorial comment]" doesn't attempt to be rendered as if
|
Beta Was this translation helpful? Give feedback.
-
There might be a role for variables/calculations to play in determining the text of page-footers (which would normally be copying the text from the |
Beta Was this translation helpful? Give feedback.
-
Proposal
** Or other suitable library. It was the first I spotted that would let us feed variables into it and parse a string formula. |
Beta Was this translation helpful? Give feedback.
-
I had a thought the other day that we could use a system not unlike Ye Olde BASIC variable types: String Definition:
returns: String Variable Here I imagine that when the Markdown Tokenizer runs, it creates a Mathematical Definition:
returns: 6 This would operate in a similar fashion, but rather than tokenizing the value, it would instead be parsed by something like expr-eval. Neither of these can happen until #3089 is merged, because until that time, each page is it's own Markdown space, so variable information doesn't carry across a page break. I feel like the scope has increased immensely from the original "simple text substitution" - we don't need a sledgehammer to crack this walnut; we can always start with a simple system that we can actually implement, and extend it later to be API-querying, JSON-fetching, all-singing all-dancing Grand Poobah of variable implementations later, as the need for those features arises. |
Beta Was this translation helpful? Give feedback.
-
Noted for later:
I especially like that we can add our own functions into the eval sandbox. We could do things like add a custom function for |
Beta Was this translation helpful? Give feedback.
-
Much of what follows makes assumptions based on #3159 and #3144 being merged or very similar work taking place. I think it would be helpful to make some small language breaks. I propose for purpose of this discussion we break "variables" up into three categories:
I think now is the time to firm up the syntax choices. The two most discussed models I see are:
The biggest problem ( besides a refactor :)) I see in the first option is that the only way I have been able to assign a string using the flink model is using The first option also makes it harder to implement inline multi-expression token and/or multi-line token. An acceptable workaround would be to drop inline multi-expression tokens and create a block level token that permits one expression to a line. e.g.
Another suggestion I've seen was to prefix the Working through writing this I'm leaning towards a the new token idea, but using |
Beta Was this translation helpful? Give feedback.
-
Well this took a nice turn, variables are here, the discussion will keep open for future issues, see #3199 for the merged version. |
Beta Was this translation helpful? Give feedback.
-
Capturing conversation from Gitter (edited for clarity and length):
G.Ambatte: I posted my Adventure Template in the subReddit earlier today, and @Gazook89 made a comment about my use of variables as stand ins for text substitution. This got me thinking that - hypothetically, at least - a list could be added to a brew's metadata consisting of pairs of strings - the first being a key and the second a value, used for text substitution. An arbitrary marker could then be used to identify the keys - say,
$$key$$
- which is then somehow handled as value instead.This line of thought led me to the \client\homebrew\editor\editor.jsx, where the render function calls the <BrewRenderer [...]> with one of the passed values being this.props.brew.text.
So my thinking is that if this.props.brew.text were passed through some sort of replaceAll function that could process said key-value pairs from the brew's metadata, then it would be passed into the BrewRenderer and appear in the output window.
And, if I understand it correctly, this point even precedes Markdown parsing, so one might be to create a key like
$$pagebreak$$
with a value of \page/n<div class="pageNumber auto"></div> and then not have to enter the same page set up on every single page.Eric Scheid: There have been similar thoughts with various MD tools. If we were to do this, we should put the UI for defining the vars into a new editor pane (i.e. not some weird markdown text to be not-rendered). Just like we’re doing with CSS.
The variable markup I’ve seen about are {{variable}} and {$variable}.
The former conflicts with our v3 {{blocks}} markup.
G.Ambatte: Yeah, I believe that's one of the things planned for v3 - tabs for CSS and Metadata. Or at least, it was at one point. Embedding a \page and <div class='pageNumber auto'> looks to work the way I thought it might, so this type of system could also be used to create shortcuts for repetitive hunks of code.
Trevor Buckner: Yes this is definitely something we could do if we agree on a good syntax.
Here's another approach that builds off of the existing 'reference Link' syntax. https://www.brianchildress.co/variables-in-markdown/
By the way, I've been adding significant changes to the Marked.js library that should allow easier/more stable creation of our custom Markdown extensions like this.
Gazook89: That article is frustratingly brief, at least for me. How does it work with just substitution rather than creating a link ? JS?
G.Ambatte: I agree - when he said "example", I was looking for an implementation, not just the bare bones of an idea.
Trevor Buckner: We can easily introduce a signifier character to distinguish between links and direct variable text. Maybe put it in quotes, or use two colons: [myvar]::hello guys
My initial thought is having a user type out [myVar]:: Ragnar the Red, which they could find in a pre-made snippet, is simpler than asking them to dig through a menu. And on our end, we end up doing some parsing either way we approach it, but hiding the output is trivial.
Marked.js makes it pretty easy to re-parse your "snippets" at any point. We make the "reflink" parser change [MYVAR] to **myBoldSnippet**, and then immediately feed that substring back into Marked again so the result is <strong>myBoldSnippet</strong> before it ever gets sent to the browser.
We already do that with the mustache divs.
At this point, the topic changed in the Gitter conversation.
In summation: while the definition syntax of [key]:: value appears to have been agreed upon, the usage syntax is still yet to be clearly defined.
Beta Was this translation helpful? Give feedback.
All reactions