Sketch-sh / sketch-sh

Sketch.sh - Online Code Editor and ReasonML community
https://sketch.sh
Other
425 stars 37 forks source link

Data format: serialization and deserialization #41

Open thangngoc89 opened 6 years ago

thangngoc89 commented 6 years ago

I want the data to be as portable as possible so here are some of my thoughts about data serialization and deserialization:

Source code format (.re, .ml):

Any notebook should be a valid ReasonML program.

When serialize a note into source code format, text block will be block comment like this:

/*:  # ReasonML playground */
(*:  # ReasonML playground *)

Notice the colon, it's used to distinguish between text block and actual code comment in deserialization.

Markdown format

~~Simply convert code blocks into markdown's codeblock with fences ~~

From @jordwalke in #98

Another approach to permanence, would be to have an export/import feature. Imagine importing a standard markdown file where `reason tags become the runnable example code blocks.

`reason-norun could become blocks embedded as code that doesn't become a runnable block, but instead is only syntax highlighted.


TODO:

kyldvs commented 6 years ago

I would make all the text content blocks on their own line, rather than the same line as the /*:, so you have:

/*:
# ReasonML playground
*/

Instead of

/*: # ReasonML playground */

I think this would make the serialized file easier to read and understand. There would be no need to deal with trimming lines (spaces in front of markdown lines can be meaningful) or determining to fit it in one line comments.

With this restraint, you could do something more explicit than /*:, perhaps:

/* rtop-ui:text-block
# ReasonML playground
*/

This could also give you a way to add other kinds of blocks in the future, by modifying text-block.

I also think it could be important to allow some sort of meta-data about how the code is run, perhaps you want to disable certain warnings in the notebook. That could then be done like:

/* rtop-ui:metadata
-w -40
*/
letouzey commented 4 years ago

I would also be very interested by a direct way to save / import sketch.sh pages. In the meantime, I'm made a quick'n dirty downloader tool : https://github.com/letouzey/sketch-downloader . It uses curl used to dump the json data of the page, then a little ocaml script to pretty-print it as markdown and OCaml/Reason code. @thangngoc89 thanks for creating and maintaining this nice plateform.