Skip to content

Markdown output #1341

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

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open

Markdown output #1341

wants to merge 37 commits into from

Conversation

davesnx
Copy link

@davesnx davesnx commented May 1, 2025

Hi,

This PR might come out of the blue, but there's a good reason. Let me explain myself in the "Why" below.

Also, when I was half done, I discovered a stale PR (#791) targeting the same problem, and I thought it could be helpful to other people.

Why

We use odoc in Melange's documentation, to generate API references for Melange libraries, such as Belt, Js, and Stdlib. While the rest of the documentation is handled by vitepress a static site generator working with Markdown files, with a lot of interesting features.

This works reasonably well, but creates a big barrier between the documentation sites:

  • Can't reference the melange.re docs articles from inside mld
  • Search from melange.re docs don't find anything inside the generated HTML
  • Users go from a unified experience to a different experience, melange.re is a SPA while generated HTML is an MPA
  • Navigation on the header and sidebar isn't the same and can't be unified
  • and a few more small details, such as favicon, tracking scripts, same syntax highlight and all features that a static site generator may give

For this reason, I wanted to generate markdown from odoc and (in the melange case) have another process that manipulates those markdown files to expand the documentation.

Another big use case for Markdown generation is Github, or any markdown renderer platform really.

How

I forked the HTML backend into a markdown2, removed what's unnecessary, and implemented Markdown construction with cmarkit.

I currently name it markdown2 since there is odoc_md and doc_of_md under the markdown folder. I suggest renaming markdown -> odoc-md (or just md) and markdown2 -> markdown in a new PR

Notes about implementation

  • References aren't a thing in Markdown's headings. I removed them, but I could always render HTML and keep the references, but it would be better to have an option for this. WDYT about --allow-html where I enable this functionality of outputting HTML
  • Similar cases for video/audio. Which isn't supported in pure markdown, but is supported in the CommonMark spec. We could fallback to HTML
  • I left a few TODOS in the code that are mostly doubts/questions about odoc that could be good to have a 2nd pair of eyes
  • All testing has been done in 2 cram tests: markdown-with-belt.t and markdown.t. I could probably split them or organise them differently

Example

melange-re/melange-re.github.io#224

Future work

davesnx added 28 commits March 7, 2025 13:36
* 'master' of github.com:/ocaml/odoc: (31 commits)
  Update docs
  Parser: Ensure parser can be called concurrently
  Parser: Fixes following PR review
  Parser: more tests
  Parser: Allow \ddd escape sequence in code-block metadata
  Parser: Use lexer for quoted strings in code block metadata
  Simplify code-block tag types and parser
  Warn on escaped character that does not need escaping
  Tag parsing: Unescape everything
  Make ocamlformat ignore cppo file
  Fix odoc_of_md wrt new tag type
  Fix typo
  Disable extract-code on OCaml < 4.10
  Extract code: handle error
  Add location to the whole tag block
  Add location to binding key and value
  Add location for tag/binding
  Fix unescaping of quoted strings
  Parse code block tags
  OCaml 4.14 compatibility
  ...
@davesnx davesnx mentioned this pull request May 1, 2025
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

Successfully merging this pull request may close these issues.

1 participant