feat: filter serialize, and mvvdisplayinline serializer#9722
Conversation
…isplayinline - Add titleQuote CST metadata to filter parser for double/single/unquoted shorthand title syntax, enabling lossless round-trip serialization - serializeFilterParseTree() now accepts maxRunsPerLine / wrapAt / indent options for formatter/linter support - Add serializeFilterParseTree() utility (filter.js) to wikitext-serialize plugin - Add mvvdisplayinline serializer rule to wikitext-serialize plugin - Add tests for all of the above - Add 5.5.0 release note folder and change note (PR number TBD)
✅ Deploy Preview for tiddlywiki-previews ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Confirmed: linonetwo has already signed the Contributor License Agreement (see contributing.md) |
📊 Build Size Comparison:
|
| Branch | Size |
|---|---|
| Base (master) | 2486.7 KB |
| PR | 2487.2 KB |
Diff: ⬆️ Increase: +0.6 KB
✅ Change Note Status
All change notes are properly formatted and validated!
📝 $:/changenotes/5.5.0/#9722
Type: enhancement | Category: developer
Release: 5.5.0
Filter serialization
🔗 #9722
👥 Contributors: linonetwo
📖 Change Note Guidelines
Change notes help track and communicate changes effectively. See the full documentation for details.
There was a problem hiding this comment.
Pull request overview
Adds enhanced filter serialization support to the wikitext-serialize plugin, enabling CST quote-style round-tripping for shorthand title filters and introducing basic formatting/wrapping options. Also adds a serializer for the mvvdisplayinline wiki rule and corresponding tests/release note entry.
Changes:
- Add
$tw.utils.serializeFilterParseTree(tree, options)with shorthand-title quote preservation and optional wrapping (maxRunsPerLine,wrapAt,indent) - Extend
$tw.wiki.parseFilter()to annotate shorthandtitleoperators withtitleQuoteCST metadata - Add
mvvdisplayinlinerule serializer plus new unit tests and serialize-spec fixture
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/tiddlywiki/wikitext-serialize/utils/filter.js | New filter AST → string serializer with CST quote round-trip and formatting options |
| plugins/tiddlywiki/wikitext-serialize/rules/mvvdisplayinline.js | New wikiruleserializer for ((var)) / (((filter))) inline display syntax |
| core/modules/filters.js | Annotate shorthand title operators with titleQuote during filter parsing |
| editions/test/tiddlers/tests/test-filter-serialize.js | Unit tests for filter serialization + CST quote preservation + formatting options |
| editions/test/tiddlers/tests/data/serialize/MvvDisplayInline.tid | Wikitext-serialize fixture cases for mvvdisplayinline |
| editions/tw5.com/tiddlers/releasenotes/5.5.0/#PRNUM.tid | Change note describing the new filter serialization behavior/options |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var filter = "[tag[a]] [tag[b]] [tag[c]] [tag[d]]"; | ||
| var tree = $tw.wiki.parseFilter(filter); | ||
| var serialized = $tw.utils.serializeFilterParseTree(tree, {maxRunsPerLine: 2}); | ||
| expect(serialized).toBe("[tag[a]] [tag[b]]\n [tag[c]] [tag[d]]"); |
There was a problem hiding this comment.
Why is the linebreak before the space? IMO it should be after the space, or the space should be replaced by the line-break.
There was a problem hiding this comment.
I'm testing lint/format of filter expression, this should be configuable. Usually when hard wrap a line, there is an indent.
There was a problem hiding this comment.
Or I could remove this, leave formatting to future. This API is not good enough.
There was a problem hiding this comment.
I think, if there is a configured linebreak, adding the indent parameter will also happen. So IMO the default should use the same logic as indent, with an empty "". So the logic is the same as indent. Only the test output will be different.
There was a problem hiding this comment.
it is more configuable now
…onsolidate tests - serializeOperator: handle deprecated regexp operands /pattern/(flags) - serializeFilterParseTree: skip empty operations (zero operators) - serializeFilterParseTree: clarify wrap separator logic (space replaced by newline+indent, no trailing space) - mvvdisplayinline.js: convert to ES2017 (const/let, template literals, destructuring) - test-filter-serialize.js: consolidate 31 individual tests into 8 grouped tests
|
I believe filter expression don't have recursion or tree structure, so its serialization is a simple map-reduce. |
|
Excellent idea thank you @linonetwo |
#8258 (comment) request add serialize for inline-MVV syntax.
And I find adding serialize for filter expression is very simple, so I do it together.