While writing my Initial Idea see details at the end of the post, I found out it’s too complex to start with.
I did have a closer look at the lezer markdown-parser plugin.
It seems we could use it to get the basic TW highlighting going. The MD source code seems to be relatively straight forward.
The repos intro says the following, where I did highlight the important part.
This is an incremental Markdown (CommonMark with support for extension) parser that integrates well with the Lezer parser system. It does not in fact use the Lezer runtime (that runs LR parsers, and Markdown can’t really be parsed that way), but it produces Lezer-style compact syntax trees and consumes fragments of such trees for its incremental parsing.
So it produces a tree with which the codemirror highlighter can work with.
I think that could be the way to go.
Since the parser already implements an extension system to eg: implement the GFM autolininking we could use this system to implement TW specific highlighting in a one by one basis, which would make it less intimidating.
That’s my thoughts
have fun!
-mario
Click! -- Details Initial Idea, which goes nowhere
I think the right way to go would be to use `$tw.wiki.renderTiddler(outputType,title,options)` as the basis. `.renderTiddler` allows TW to convert the parseTree into a widgetTree, which then is converted to HTML output.See the code:
- line 1229 –
var parser = this.parseTiddler(title,options)
instantiates the parser class and also caches the parseTree - line 1230 –
widgetNode = this.makeWidget(parser,options);
converts the parseTree into the widgetTree - line 1232 –
widgetNode.render(container,null);
creates the HTML output.
So instead of outputype="text/html"
we would need eg: outputype="application/vnd.lezer+json"
or something similar.
- instead of
widgetNode
we would get a lezer Tree- where each child is either a readonly
Tree
or aTreeBuffer
- where each child is either a readonly
class
TreeBufferTree buffers contain (type, start, end, endIndex) quads for each node. In such a buffer, nodes are stored in prefix order (parents before children, with the endIndex of the parent indicating which children belong to it).
I think the TreeBuffer
could be created with the information stored in the TW parseTree
. The TW parseTree has a very similar info.
BUT
The lezer tree has a context that is created by the lezer-parser. So to convert a TW AST to a lezer-tree we would basically need to recreate the parser.
→ While writing this and studying the docs I see this goes nowhere. → Way to complex to start with.
If phase 1 will be done, there should be enough experience to implement a conversation from TW AST to “lezer Tree”