nix-community / nixdoc

Tool to generate documentation for Nix library functions [maintainer=@infinisil]
GNU General Public License v3.0
123 stars 15 forks source link

Fix/headings & check: nixdoc can always build nixpks manual #121

Closed hsjobeki closed 3 months ago

hsjobeki commented 4 months ago

This PR fixes the problems that where introduced with using any commonmark parser to shift the headings.

Currently nixdoc cannot be used to build the nixpkgs manual. This PR fixes that and also ensures that it remains buildable.

Even though headings might be detected and can be operated on, it became nearly impossible to serialize the parsed tokens/ast of any parser (the rest of the document). Any parser must support ALL underlying extensions that we use in nixpkgs docs. OR alternatively any parser should preserve whitespace and formatting, but i couldnt find any parser amongst the rust ecosystem with such properties.

Solution

The solution now involves to manually track whether we are inside or outside of code-blocks and shift only headings that are not inside a code block and start right at the beginning of the line.

ping @infinisil

Limitations

https://spec.commonmark.org/0.28/#fenced-code-blocks

Commonmark also specifies how unclosed codeblocks behave. We don't support unclosed code blocks.

- item   
    ```nix
    1
nixos-discourse commented 4 months ago

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-04-25-documentation-team-meeting-notes-122/44080/1

hsjobeki commented 3 months ago

@infinisil I know you where busy with some other work. I'd be delighted If you could find time to review this PR or tell me what to do with it.