markdown-it / markdown-ast-spec

Markdown AST spec
6 stars 5 forks source link

Node info #3

Open puzrin opened 7 years ago

puzrin commented 7 years ago

Problem:

Fields

Checklist

geyang commented 7 years ago

The current node type is good enough to me. I really don't mind working with a custom node syntax, be it 2-level array or tree. Because there is no standard amongst the different parsers, effort in making a nice node format would not have a large positive impact.

puzrin commented 7 years ago

Initial problem is related to parser algorythms. Sometime scanner needs to discad data and jump back, or modify last created node. The same for "path stack" to current node. This is more difficult with existing arrays and recursive calls.

But this can be improved via better data store:

And we still can keep 2-level lists. Those are more easy to scan (without recursion), but more difficult to modify. Situation with AST is reverse.

geyang commented 7 years ago

And we still can keep 2-level lists. Those are more easy to scan (without recursion), but more difficult to modify. Situation with AST is reverse.

What about use a component array with keys that allow easy component loop up and easly modify:

how to generate these keys is an art in itself. In some sense incrementing integers is good enough and other id generation doesn't get you much.


AST: 
{ root: component_id,
componet_id_list: [component_id1, id2 ...],
component_id1: component 1,
component_id2: component 2 { child_id1, child_id2}
}