jupyter-book / mystmd

Command line tools for working with MyST Markdown.
https://mystmd.org/guide
MIT License
219 stars 64 forks source link

Add a helper function to inspect MyST AST objects in JavaScript (e.g. in `utils`) #1652

Open choldgraf opened 6 days ago

choldgraf commented 6 days ago

It's useful to be able to print log statements about the contents of AST, JavaScript objects, etc during a MyST build. However, for print AST objects, using console.log isn't that useful.

If you do

console.log(ast)

It only generates the top layer of AST so you can't see what's in the children etc.

There are two other ways to print the full AST, but both are a pain to remember:

console.dir(ast, { depth: null, colors: true });

and

console.log(JSON.stringify(ast, null, 2))

Suggestion: make this a utility function

We should provide developers a utility function inside of utils or ctx that shows the contents of AST in a user-friendly way.

For example:

utils.inspect(ast, depth=3)