Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization API #95

Open
tmpfs opened this issue Mar 24, 2016 · 0 comments
Open

Serialization API #95

tmpfs opened this issue Mar 24, 2016 · 0 comments

Comments

@tmpfs
Copy link
Contributor

tmpfs commented Mar 24, 2016

I am now serializing and deserializing the AST with a 1:1 exact match such that it could be converted to a JSON document and back to an AST tree.

The rationale for this functionality is that I want to pipe an AST document between processes and felt that parsing documents on the way in and rendering on the way out was too much overhead.

The implementation is two static methods Node.serialize() and Node.deserialize(), I would like it if possible to add these methods to the commonmark Node class.

The code is here:

https://github.com/mkdoc/mkast/blob/aa0fa3c5bf4ca45e8c961ad14640543da60ec529/lib/node.js#L141-L355

The test specs serialize and deserialize have 100% coverage on those methods. Notably the deserialize spec ensures a 1:1 correlation with a deep equals comparison.

Note that we don't expose private properties in the serialized object so that iteration can consistently reference firstChild and next regardless of whether it is a full AST node (with parent references) or a detached serialized object.

During this process a few requests regarding public property access have arisen, could I please expose _lastLineBlank and _htmlBlockType with public getters?

Also at times I need to associate custom data with AST nodes and this has been a bit ad-hoc so far, hence the additional properties file etc. that I would like to tuck away in an object that commonmark Node supports, maybe userData or data?

If we can formalize a way to add custom data to nodes then I can update the serialize and deserialize methods to use that and it could be folded in to commonmark Node.

Thanks for all your help and patience - especially with those questions that deserved a RTFM response ;)

@tmpfs tmpfs mentioned this issue Mar 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant