ocaml / omd

extensible Markdown library and tool in "pure OCaml"
ISC License
156 stars 46 forks source link

move auto id into AST #301

Open tatchi opened 1 year ago

tatchi commented 1 year ago

Fixes #296

This moves the auto identifiers logic into the AST (when parsing the document). It moves the auto_identifiers parameter from the Omd.to_html function to the Omd.{of_channel,of_string} function.

I'm not sure if this API is ideal because it means that we have to parse a document twice (once with auto_identifiers set to true and once with false) if we want to print it with/without auto-identifiers.

let with_ids = Omd.of_string ~auto_identifiers:true "..." |> Omd.to_html
let without_ids = Omd.of_string ~auto_identifiers:false "..." |> Omd.to_html

Perhaps including the auto-ids in the AST and deciding whether or not to include them at the time of printing would be a better solution.

let doc = Omd.of_string "..." in
let with_ids = Omd.to_html ~auto_identifiers:true doc
let without_ids = Omd.to_html ~auto_identifiers:false doc

The only problem is that we'd need to distinguish an explicit id from an auto-generated one in the AST.