Skip to content

Enhancement: put variable names between backticks #1025

@amedee

Description

@amedee

Description

I always run Prettier on auto-generated Markdown files, including those made by ansible-doctor. Prettier is opiniated and replaces double underscores (__) in variable names with Markdown bold (**) in role READMEs generated by ansible-doctor. Prettier can NOT be configured to not replace __ with **.

Example:

# Original variable in defaults/main.yml
imapsync__logrotate__dependent_config

Generated README.md by ansible-doctor:

## Table of contents

- [Requirements](#requirements)
- [Default Variables](#default-variables)
  - [imapsync__logrotate__dependent_config](#imapsync__logrotate__dependent_config)

...

## Default Variables

### imapsync__logrotate__dependent_config

README.md after Prettier:

## Table of contents

- [Requirements](#requirements)
- [Default Variables](#default-variables)
  - [imapsync**logrotate**dependent_config](#imapsync__logrotate__dependent_config)

...

## Default Variables

### imapsync**logrotate**dependent_config

Impact

  • TOC links break (#imapsync__logrotate__dependent_config no longer matches)
  • Markdown linters (MD051) fail
  • Variable names are misrepresented

Suggested fix

To render variable names literally, wrap them in backticks. Prettier will then not touch them.

## Table of contents

- [Requirements](#requirements)
- [Default Variables](#default-variables)
  - [`imapsync__logrotate__dependent_config`](#imapsync__logrotate__dependent_config)

...

## Default Variables

### `imapsync__logrotate__dependent_config`

Side effects

The variable names will be in a monospaced font in the rendered Markdown. Personally I actually see that as an improvement.

Steps to reproduce

  1. Create a variable with double underscores in a role.
  2. Run ansible-doctor to generate README.md.
  3. Observe __.
  4. Run npx prettier to prettify README.md.
  5. Observe replacement of __ with **.
  6. Run ansible-doctor again to generate README.md.
  7. Observe __.
  8. Manually wrap imapsync__logrotate__dependent_config in backticks.
  9. Run npx prettier to prettify README.md.
  10. Observe __.

Minimal YAML snippet

# roles/test_role/defaults/main.yml
imapsync__logrotate__dependent_config:
  - filename: imapsync
    log: /var/log/imapsync.log

Environment

  • ansible-doctor version: 8.2.0
  • OS: Ubuntu 24.04.3 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions