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

stdlib: markdown conversor to erlang+html #8077

Conversation

kikofernandez
Copy link
Contributor

conversor from markdown to erlang+html. shell_docs needs documentation in erlang+html format, so that it can render the documentation attributes correctly in the shell. documentation attributes are written in markdown and, with this erlang+html conversion tool, shell_docs can interpret documentation attributes.

@kikofernandez kikofernandez self-assigned this Jan 31, 2024
@kikofernandez kikofernandez added the team:VM Assigned to OTP team VM label Jan 31, 2024
Copy link
Contributor

github-actions bot commented Jan 31, 2024

CT Test Results

    5 files    540 suites   1h 25m 28s ⏱️
4 216 tests 4 123 ✅  93 💤 0 ❌
9 975 runs  9 853 ✅ 122 💤 0 ❌

Results for commit 767ea13.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@josevalim
Copy link
Contributor

Could you have forgotten to push doc_html.erl? :)

Btw, we have a module in Elixir for converting markdown to ansi/shell. I assume that if you only care about ansi/shell, it is actually a subset of the problem of converting all of markdown to html: https://github.com/elixir-lang/elixir/blob/main/lib/elixir/lib/io/ansi/docs.ex

Tests are here: https://github.com/elixir-lang/elixir/blob/main/lib/elixir/test/elixir/io/ansi/docs_test.exs

@kikofernandez kikofernandez force-pushed the kiko/stdlib/markdown_to_erlang+html/OTP-18956 branch from 1a22adc to 79ea9f1 Compare February 14, 2024 07:41
@kikofernandez
Copy link
Contributor Author

@josevalim thanks! The thing is that not all of my tests pass, so I did not bother to push what I had...
We are not immediately going from markdown to ansi/shell, the approach that we thought could be easier was to go from markdown to erlang+html format (https://www.erlang.org/doc/man/shell_docs#type-chunk_element_attr), so that we do not need to deal with much of the formatting.

We will see how it goes :) Otherwise, we probably will re-use parts of the Elixir code :) That said, this PR was highly influenced by the Elixir docs.ex module, where docs.ex is great work and really understandable!

@lukaszsamson
Copy link
Contributor

From the LSP side it would be more convenient if we could skip erlang+html and get markdown. Currently LSPs need to implement a reverse conversion from erlang+html to markdown

@josevalim
Copy link
Contributor

I believe the docs chunk will have markdown for Erlang from OTP 27 onwards if using -doc.

@kikofernandez
Copy link
Contributor Author

Yes, docs chunks will have markdown. The erlang+html is just for transforming the erlang shell, so that one can write h(lists). The function h/1 is the one receiving markdown and converting to erlang+html, because that's what it knows how to render

@garazdawi
Copy link
Contributor

@lukaszsamson From an LSPs perspective you may want to use the new edoc_html_to_markdown module added in Erlang/OTP 27 that converts application/html+erlang to markdown. This is for projects that use edoc to create their documentation, or Erlang/OTP before 27.

But, as the others here have said, for all of the Erlang/OTP docs after 27 you will get the markdown directly from beam file using code:get_doc/1. There will of course always remain applications out there that uses edoc, so being able to handle both formats is a good thing.

@lukaszsamson
Copy link
Contributor

@lukaszsamson From an LSPs perspective you may want to use the new edoc_html_to_markdown module added in Erlang/OTP 27 that converts application/html+erlang to markdown. This is for projects that use edoc to create their documentation, or Erlang/OTP before 27.

But, as the others here have said, for all of the Erlang/OTP docs after 27 you will get the markdown directly from beam file using code:get_doc/1. There will of course always remain applications out there that uses edoc, so being able to handle both formats is a good thing.

Nice. Like you said the translation to markdown will need to stay until support for OTP 26 is dropped but that's not going to happen soon (ElixirLS currently still supports OTP 22)

@kikofernandez kikofernandez force-pushed the kiko/stdlib/markdown_to_erlang+html/OTP-18956 branch from 34078c4 to 5ea526c Compare March 4, 2024 15:50
@kikofernandez kikofernandez force-pushed the kiko/stdlib/markdown_to_erlang+html/OTP-18956 branch 2 times, most recently from d6ffd0f to f2cf613 Compare April 26, 2024 18:37
@kikofernandez kikofernandez added the testing currently being tested, tag is used by OTP internal CI label Apr 29, 2024
@kikofernandez kikofernandez requested a review from garazdawi April 29, 2024 06:52
lib/stdlib/src/doc_html.erl Outdated Show resolved Hide resolved
lib/stdlib/src/shell_docs.erl Outdated Show resolved Hide resolved
lib/stdlib/src/doc_html.erl Outdated Show resolved Hide resolved
lib/stdlib/src/doc_html.erl Outdated Show resolved Hide resolved
lib/stdlib/src/doc_html.erl Outdated Show resolved Hide resolved
documentation attributes are written in markdown and this parser
consumes markdown doc attributes and emits erlang+html. when someone
types the `h(mod)`, `shell_docs.erl` converts the markdown documentation
attribute to erlang+html, since `shell_docs.erl` knows how to interpret
this format.
@kikofernandez kikofernandez force-pushed the kiko/stdlib/markdown_to_erlang+html/OTP-18956 branch from 767ea13 to bf887e3 Compare April 30, 2024 08:27
@kikofernandez kikofernandez merged commit da17085 into erlang:master Apr 30, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants