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

Parse code blocks metadata #2

Merged
merged 4 commits into from
Sep 16, 2021
Merged

Conversation

Julow
Copy link
Contributor

@Julow Julow commented Jul 23, 2021

The first commit parses the "metadata" string that can be attached to code blocks into two fields: the language tag and the arbitrary metadata string. The AST node is changed to

  | `Code_block of
    (string with_location * string with_location option) option
    * string with_location

The second field is parsed as before, it takes any characters until the first [, there's no escaping and it doesn't strip trailing whitespaces.
The first field is parsed as a word (a new definition of "word"). It is mandatory when using the {@lang metadata[ ... ]} syntax.

The second commit allows newlines between the two fields. Newlines were already allowed but were treated as part of the second field.

The parsing of code blocks still has rough edges (eg. lack of escaping, including the trailing whitespaces) but this shouldn't make it worse.

Julow added 4 commits July 23, 2021 16:01
The metadata string, if present, is required to start with the language
tag. The code block AST node is now:

    (language tag * metadata option) option * content
Newlines were already allowed by lack of restrictions on the second
field. This commit allows them explicitly and improve edge cases.
Documentation comments cannot be attached to polymorphic variant
constructors.
@jonludlam
Copy link
Collaborator

It looks like we are missing tests for the new functionality?

@Julow
Copy link
Contributor Author

Julow commented Sep 16, 2021

Which test is missing ? The previous tests are still useful, there are new tests for the edge cases of the new "parsing" code.

@jonludlam
Copy link
Collaborator

Huh, you're absolutely right, I've no idea why I didn't see that first time!

@jonludlam jonludlam merged commit 626ccc9 into ocaml-doc:main Sep 16, 2021
@jonludlam jonludlam mentioned this pull request Sep 25, 2021
jonludlam added a commit to jonludlam/opam-repository that referenced this pull request Dec 11, 2021
CHANGES:

- New syntax to allow associating metadata with code blocks
  (@Julow, ocaml-doc/odoc-parser#2, ocaml-doc/odoc-parser#3)
jonludlam pushed a commit to jonludlam/odoc-parser that referenced this pull request Feb 22, 2023
Fix new paragraph starting on `|`
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.

2 participants