Module Djot_json

Djot trees as JSON, in the format of djot.js's AST.

A node is an object with its "tag", the members of that tag, "attributes" when it has any and "pos" when it has a position. Tags and members are the ones djot.js writes, so its ast.ts is the reference for them.

Members and tags djot.js does not have:

Where the tree does not hold what djot.js writes:

Trees

val block : Djot.Block.t Djot.node Jsont.t

A Djot.Block.t.FootnoteDef is a "footnote" and a Djot.Block.t.RefDef a "reference", each where it is in the tree. A Djot.Block.t.AttrBlock is a "block_attributes", which djot.js's AST does not have.

An identifier is in "attributes" whether it was written or derived: a tree does not say which. Only of_doc writes "autoAttributes".

Decoding skips unknown members. It reads "plain", "pos" and a row's "head" and drops them, and puts an identifier under "autoAttributes" first among the attributes. So a decoded node has no position, and decoding what was encoded gives the same tree up to positions.

val inline : Djot.Inline.t Djot.node Jsont.t

Documents

val of_doc : Djot.Doc.t -> Jsont.json

The "doc" object: frontmatter when there is one, references, autoReferences and footnotes by label, then the blocks, with the definitions left out as djot.js does. A footnote has the attributes of its definition. An identifier in Djot.Doc.auto_identifiers is under "autoAttributes", as in djot.js. Nodes have a "pos" when the document was parsed with ~locs:true.

val to_string : ?format:Jsont.format -> Djot.Doc.t -> string

of_doc as JSON text.

  • parameter format

    default Jsont.Minify

val to_ast_string : Djot.Doc.t -> string

of_doc in the indented form djot.js prints with -t ast: one node per line with its position, members and attributes, children indented under it, then the references and the footnotes.

val to_doc : ?profile:Djot.Profile.t -> Jsont.json -> (Djot.Doc.t, string) Stdlib.result

The document a "doc" object describes: Djot.Doc.make of its "children", then its "references", then its "footnotes". An identifier under "autoAttributes" is left out and derived again. "autoReferences" is not read.

The JSON does not say where a definition stood, and has one definition per label. So for a document d, to_doc (of_doc d) has the definitions after the other blocks, without those an entry of the same label replaced, and no positions. Its HTML is that of d.

"frontmatter" is read with Djot.Frontmatter.make, so the fields come back and the YAML text they were written as does not. It is an error where make raises.

val of_string : ?file:string -> ?profile:Djot.Profile.t -> string -> (Djot.Doc.t, string) Stdlib.result

to_doc of JSON text.

  • parameter file

    the name an error gives for the text; "-" by default