Seems I’ve been working a lot on text parsing recently… I’m working on a survey template that uses sections marked with ! prefixes to organize questions.
While I can successfully identify and display the section headers, I’m having trouble capturing the content between these section markers within the reveal widget.
But, while the reveal state works for the section headers, I cannot render the desired content as nested inside it. I suspect it might be related to the filter context within the reveal widget? Toying with it the last few days, I haven’t been able to budge it.
While a global definition for doublebreak is a good idea, there’s two issues with the code suggested by @springer:
Using $:/tags/Global will not invoke the $set widget to define a global variable. Rather, it will only process \define, \procedure, and \function definitions.
Rather than embedding literal newlines into the code, I recommend using the charcode[...] operator to generate the appropriate linefeed characters (ASCII code 10).
The following global function definition will work:
\function double.break() [charcode[10],[10]]
which can then be referenced as <<double.break>> (or <double.break> when used in filter syntax).
There are times when it makes sense to use the features of the SetWidget rather than procedures or functions to create global variables. This can be accomplished by placing the set variable widget in a tiddler that is tagged $:/tags/Global. …
At any rate, I’m always happy to defer to you about best practices!
How are you defining <<section-state>>? If you add some hard-coded content in the section-content div (outside the $list), does it get properly displayed?
Since you’re not animating the $reveal anyway, as an additional debug step I’d try replacing
I admit I haven’t studied your code very closely, but is it possible that :filter[<currentTiddler>... should be :filter[<..currentTiddler>? As written, you’re getting the survey-text field from the tiddler whose title corresponds to the output of the previous filter run… which is possible, but seems like it might not be your intent…
It’s a bit difficult to debug without access to the rest of your testing environment — for instance, you’re using the variables <<firstLine>> and <<currentBlock>>, but they’re not defined in the context you’ve provided. So I’ll just offer my generalized approach to filter debugging, which is to paste your $list variable (<<question>>, in this case) inside the $list, where you currently have the survey item content. Then either start removing segments of the filter until you get the results you expect, or start from a simpler form of the filter and re-add operators until it breaks.
You don’t need to define <<..currentTiddler>>; this is a special variable defined within the context of some prefixed filter runs, like :filter and :map, which redefine <<currentTiddler>> to refer to each input value of that run. <<..currentTiddler>> preserves the original value of <<currentTiddler>> outside the filter.
Here, you’re splitting blocks at double line breaks, with the first line becoming the header. But your sample text also uses double line breaks after each h1, e.g.
! Section 2
This is another section
This means that “This is another section” becomes the <<firstLine>> of its own block, rather than the <<description>> of Section 2 — but since it’s not prefixed with !, it’s not displayed by the following list. And conversely, Section 2 has no content to display even when it’s unfolded because there are no other lines in the same block.
I see, I was confused about ``<<..currentTiddler>> That’s very good info to know. I thought I might as well redefine it so I’d know it had the correct value.
This is another section to represent a question, without a description.