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

Consider adding "AST in JSON" output fromat #58

Closed
matklad opened this issue Nov 1, 2022 · 4 comments
Closed

Consider adding "AST in JSON" output fromat #58

matklad opened this issue Nov 1, 2022 · 4 comments

Comments

@matklad
Copy link
Contributor

matklad commented Nov 1, 2022

Problem: I'd love to experiment with djot, but I don't know lua, and would rather use a language I am already familiar with (Rust or TypeScript).

Proposed solution: add djot -a -j to output AST in some JSON format which then could be easily consumed by other programs.

I think I probably can get something like this via pandoc, but I'd rather avoid adding one more tool to the pipeline.

Yeah, the appropriate pandoc spell is pandoc -f djot-reader.lua -t json example.djot. There's another drawback with that approach: today's pandoc json output is a rather low-level encoding of Haskell data structures, it's not something you can just JSON.parse in javascript and get a natural API. I think there's some benefit to defining a more first-class JSON AST encoding for djot.

@jgm
Copy link
Owner

jgm commented Nov 1, 2022

That's a good idea, and I don't think this would be too difficult. However, I'm reluctant to make this library depend on a json library -- right now it has no dependencies. One option would be an optional module that consumes the output of to_ast and produces json. Or maybe I can just write the necessary json-generating code without using a library.

@matklad
Copy link
Contributor Author

matklad commented Nov 1, 2022

Yeah, I don't think a library is required to emit json, we can just push stuff to string, the same what we do for HTML (I think?)

Very much appreciate the zero-dependency nature of the reference impl!

@matklad
Copy link
Contributor Author

matklad commented Nov 3, 2022

I think this is mostly done now, via -a -j. Most of discussion here happened in #60 :)

@matklad matklad closed this as completed Nov 3, 2022
@jgm
Copy link
Owner

jgm commented Nov 3, 2022

I've added this to the live sandbox, too

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

2 participants