Apparently I need more iterations of this. And more practical coding, which I started to do only recently after months of learning the basics of wikitext mostly in read-only mode. I’m just not confident about it, which is curious by itself. I don’t get that “I don’t understand this at all” feeling, which would just make me abandon the quest with no regrets. But as soon as I try to write a practically useful snippet of wikitext code, I get stuck.
The newer version of your code mixes the correct way to reference a variable as a parameter to a filter step (with single angle brackets operator<varname>
) with using double angle brackets within square brackets (operator[<<varname>>]
).
I tried to use double brackets because that’s how variables are referenced when used to build other variables in context of a <$let>
widget. Since the filter (the one that is going to be passed to the custom assert widget) is stored in a variable, I tried to get the regexp (which contains the trouble causing square brackets itself) into the filter this way. Looks like it was a bad idea.
I hoped this
would be good enough. My test tiddler contains:
- lines of text
- empty lines (as in at the end of a non-empty line I hit Enter, cursor goes to the beginning of new line, I hit Enter again, I get an empty line above the cursor). this I referenced as “\n” above.
- lines that contain only a mix of zero or more whitespace characters (produced by pressing the Spacebar) and tab characters (produced by hitting the Tab key). hence the
[\s\t]*
regexp. visually, they look “empty” as well, but their size (in characters) is greater than zero. yet I treat both 2. and 3. as opposite to 1.
I believe this is the trim[]!is[blank]]
part of the filter. I never thought of doing that. I’ve never used trim
filter operator before, yet I still don’t understand why is this needed. Well, you explain why:
which will give false positives
but I still don’t understand why I’m going to get false positives.
Is each whitespace separated section of text meant to be a filter?
Not at all. My initial goal (for which I would’ve happily used a core filter assertion widget, if there was one, but there isn’t, hence I’m trying to write one to help me with writing unit tests, since the assert.equal
widget from another thread isn’t good at answering the “does this filter return at least one item? tell me by comparing two hardcoded values” question) was to write a filter that would let me distinguish between lines like 1. and lines like 2. or 3. (see above). The ultimate practical problem I want to solve is that I have tiddlers with content written in a hurry that have multiple consecutive “empty” (as in either 2. or 3.) lines of text, between lines of actual text (1.) and I want to find them with a script, to make text in those tiddlers look “nicer” by replacing multiple “empty” lines with just one, and sometimes entirely remove a single “empty” (as in 2.) one.
Your version of code produces the expected tests results with my test data. The biggest confusion about it, as I already said above, is why removing the trim[]!is[blank]]
part from the filter breaks everything and makes all tests pass (which is wrong).