Skip to content

Conversation

linonetwo
Copy link
Contributor

@linonetwo linonetwo commented Jun 12, 2024

closes #8255

Currently just a demo, I will gradually move code from https://github.com/tiddly-gittly/wikiast/tree/master/packages/wikiast-util-to-wikitext to here.

Try it with tiddler (Well, if official website have share plugin installed, I can put a link here):

AAA test

---

\```js
var match = reEnd.exec(this.parser.source)
\```

end

and run this in console:

$tw.utils.serializeParseTree($tw.wiki.parseTiddler('New Tiddler').tree) 

Copy link

vercel bot commented Jun 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview Jun 12, 2024 5:39pm

@linonetwo linonetwo changed the title Feat/to string feat: serialize AST node back to wikitext string Jun 12, 2024
@pmario
Copy link
Member

pmario commented Jun 13, 2024

The problem here is, that the output of you test does not produce the same rendered HTML output as the original source. See the screenshot.

image

@linonetwo
Copy link
Contributor Author

linonetwo commented Jun 13, 2024

First line is wrapped by a p element, but I haven't find the rule that produce the p element. And there was no p html in the source, so I may need to add some attribute to ast to show this p element is "fake".

Anyway, this is just a demo for API, do you like the API name and their usage? The further task is just adding exports.serailize = xxx to each rule.

@pmario
Copy link
Member

pmario commented Jun 13, 2024

First line is wrapped by a p element, but I haven't find the rule that produce the p element. And there was no p html in the source, so I may need to add some attribute to ast to show this p element is "fake".

IMO the current parser has a "systemic" problem with redundant P-tags, that we probably may need to solve first.

Working around this problem with "fake" elements will just increase your code complexity, instead of solving the underlaying problem. It will also create an other dependency, that will make solving the problem, in the core, in backwards compatible way even harder as it is now.

};

exports.getParser = function(type,options) {
options = $tw.utils.extend({},options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO your code will throw an RSOD if options is undefined
So options = options || {} should be used instead. We use this pattern all over the places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy $tw.utils.extend({},options) from somewhere nearby, I thought this will work.

@linonetwo
Copy link
Contributor Author

redundant P-tags

Can't remove then, many of my plugin style sheet is already depending on this structure. And p > text for block is following HTML5 semantic.

Another option is handle it like text node, regard it as a special case.

@pmario
Copy link
Member

pmario commented Jun 13, 2024

And p > text for block is following HTML5 semantic.

That's true, but we do have a lot of p > div which should not happen at all.

@linonetwo
Copy link
Contributor Author

linonetwo commented Jul 29, 2024

Handle the block rule by adding a rule: 'parseBlock' to WikiParser.prototype.parseBlock.

I've added some test for it.

@Jermolene
Copy link
Member

It kepts receiving conflict from other PRs, when will we merge this? @Jermolene

Apologies @linonetwo I appreciate your patience. Now that this PR is planned for v5.4.0 it will be merged once we release v5.3.7, when we'll start v5.4.0. (While we could start v5.4.0 in another branch alongside the development of v5.3.7, the problem is that we would just be shifting the friction you are experiencing with merge conflicts to a different branch).

Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2528.4 KB
PR 2532.1 KB

Diff: ⬆️ Increase: +3.7 KB

Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2528.4 KB
PR 2532.1 KB

Diff: ⬆️ Increase: +3.7 KB

@linonetwo
Copy link
Contributor Author

linonetwo commented May 29, 2025

Okay, I just help other PR fixing its test. Hope AI could help me do that in the future.

Looking forward to v5.4.0. I check this PR regularly because when someone in QQ group ask me about WYSIWYG editor's bug I will talk about this PR once and check it...

@saqimtiaz saqimtiaz moved this from In progress to Needs review in Planning for v5.4.0 Jun 17, 2025
@saqimtiaz saqimtiaz moved this from Needs feedback to Ready in Planning for v5.4.0 Jun 17, 2025
@linonetwo
Copy link
Contributor Author

linonetwo commented Jul 12, 2025

图片

Our serializer is based on rule field. And type field is for widgets. This is because many rules are producing type: "html", and block (p) don't even have a type.

This could cause some bug hard to debug when using it. So I write it here for future me (or AI that helps me).
P.S. won't be a problem if we have type-check. This is a tipical bug that typescript is created for.
gpt4.1 is too silly to fix this, but claude4 could find it in a second, so, no need for typescript!

@linonetwo
Copy link
Contributor Author

Any chance merging this? Do you think this new core plugin is feature completed?

@Jermolene
Copy link
Member

Hi @linonetwo I'm hoping we can merge #9135 in the next day or two, and then I believe we can start merging v5.4.0 PRs.

@Leilei332
Copy link
Contributor

@Jermolene IMO this PR is ready to be merged now.

@Copilot Copilot AI review requested due to automatic review settings October 11, 2025 08:23
Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2421.1 KB
PR 2424.8 KB

Diff: ⬆️ Increase: +3.7 KB

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a wikitext serialization feature that can convert parsed AST (Abstract Syntax Tree) nodes back to wikitext format. It implements a new plugin with serializers for various wikitext rules and utilities for reverse-engineering wikitext from parse trees.

Key changes:

  • Adds comprehensive serialization support for most wikitext syntax elements
  • Introduces a new void widget type for handling non-rendering nodes
  • Updates parser rules to include metadata needed for serialization

Reviewed Changes

Copilot reviewed 115 out of 117 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
plugins/tiddlywiki/wikitext-serialize/utils/parsetree.js Core serialization utilities with main serializeWikitextParseTree function
plugins/tiddlywiki/wikitext-serialize/rules/*.js Individual serializers for each wikitext rule (tables, headings, emphasis, etc.)
core/modules/widgets/void.js New void widget for handling non-rendering parse tree nodes
core/modules/parsers/wikiparser/rules/*.js Updates to parser rules to add serialization metadata
editions/test/tiddlers/tests/*.js Test files and test data for serialization functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2421.1 KB
PR 2424.8 KB

Diff: ⬆️ Increase: +3.7 KB

Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2421.1 KB
PR 2424.8 KB

Diff: ⬆️ Increase: +3.7 KB

Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2421.1 KB
PR 2424.8 KB

Diff: ⬆️ Increase: +3.7 KB

3 similar comments
Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2421.1 KB
PR 2424.8 KB

Diff: ⬆️ Increase: +3.7 KB

Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2421.1 KB
PR 2424.8 KB

Diff: ⬆️ Increase: +3.7 KB

Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2421.1 KB
PR 2424.8 KB

Diff: ⬆️ Increase: +3.7 KB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

[IDEA] Serailize/toString of AST node

7 participants