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

Syntax for metadata on code blocks #633

Closed
Julow opened this issue Mar 11, 2021 · 4 comments
Closed

Syntax for metadata on code blocks #633

Julow opened this issue Mar 11, 2021 · 4 comments

Comments

@Julow
Copy link
Collaborator

Julow commented Mar 11, 2021

It should be possible to attach metadata to code blocks. There is two main use-cases:

  • Running Mdx on OCaml and mld files. It needs per-block configuration.
  • Code highlighting. The HTML backend adds color highlighting but assumes that all blocks contain OCaml code.

Odoc won't try to interpret or to render them, they would be present in the parse tree but discared afterwards.

During a previous meeting, we proposed the following syntax:

{@language metadata [
]}

The metadata part is an arbitrary string and is optional.
We'd need quoting, I propose wrapping it with double quotes ("") and allowing OCaml's escaping (eg. \" and everything String.escape produces).

The language part is not optional.

For example:

{@sh [
rm -rf /
]}
{@ocaml env=f1 version>=4.06 [
# let x = 1 ;;
val x : 1
]}
@dbuenzli
Copy link
Contributor

Code extraction is another use case. There's a long discussion about it in #303

@jonludlam
Copy link
Member

@dbuenzli yes, I'm hoping mdx will do that job for us. It's got code extraction working already (but from markdown files).

@dbuenzli
Copy link
Contributor

Honestly I rather not add more tools to the basics I need for dev (and especially not tools that do black magic). It doesn't seem super hard to add file extraction to odoc itself by starting from the document IR.

@Julow
Copy link
Collaborator Author

Julow commented Jan 5, 2022

This is implemented in https://github.com/ocaml-doc/odoc-parser and has been released (1.0.0).

@Julow Julow closed this as completed Jan 5, 2022
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

3 participants