azimuth icon indicating copy to clipboard operation
azimuth copied to clipboard

Leverage prettier for markdown files

Open gabegma opened this issue 3 years ago • 3 comments

gabegma avatar Jun 07 '22 18:06 gabegma

Unfortunatly, prettier messes up admonitions:

 !!! info "How to temporarily disable pre-commits?"
-    For a specific commit, you can avoid running the pre-commits with the flag `--no-verify`. If you do this, make sure to run `pre-commit run --all-files` before opening a PR, which will run the pre-commit on all files.
-
+For a specific commit, you can avoid running the pre-commits with the flag `--no-verify`. If you do this, make sure to run `pre-commit run --all-files` before opening a PR, which will run the pre-commit on all files.
 

Issues opened:

  • https://github.com/prettier/prettier/issues/12985
  • https://github.com/prettier/prettier/issues/8640

The fix mentioned (adding a blank line between the !!! and the content) doesn't work on admonitions inside lists.

For future reference, this is the precommit hook I used:

  - repo: local
    hooks:
      - id: prettier-docs
        name: prettier-docs
        language: system
        entry: bash -c 'cd webapp && poetry run yarn prettier --write ../docs'
        files: docs

Dref360 avatar Jun 08 '22 14:06 Dref360

Did you mention yesterday that you found a fix for that? Did you need to install something with yarn first?

gabegma avatar Jun 09 '22 18:06 gabegma

I tried with another hook and got relatively close to it working, but it doesn't handle complex admonitions with code/bullets/multiple tables in them. I tabled this for now.

  - repo: https://github.com/executablebooks/mdformat
    rev: 0.7.16
    hooks:
      - id: mdformat
        exclude: docs/includes
        additional_dependencies:
          - mdformat-mkdocs
          - mdformat-admon
          - mdformat-beautysh
          - mdformat-footnote
          - mdformat-black
          - mdformat-simple-breaks
          - mdformat-tables

gabegma avatar Feb 21 '23 15:02 gabegma