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

Template literal type props are not escaped properly in generated markdown #6024

Closed
brandongregoryscott opened this issue Oct 10, 2024 · 1 comment · Fixed by #6025
Closed
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil Help Wanted

Comments

@brandongregoryscott
Copy link
Contributor

Stencil version:

Current behavior:

When markdown docs are generated for a prop that is a Template Literal Type, e.g.

@Prop() width: `${number}px` | `${number}%`;

The markdown generator takes the type as-is without escaping the backticks, which has incorrect formatting (and breaks in an MDX parser)

| Property | Attribute | Description     | Type                                  | Default     |
| -------- | --------- | --------------- | ------------------------------------- | ----------- |
| `width`  | `width`   |                 | ``${number}%` \| `${number}px``       | `undefined` |
Property Attribute Description Type Default
width width ${number}%` | `${number}px undefined

Expected behavior:

Since the markdown generator adds its own backticks to style the type as a "code" value, it should escape values that contain backticks. I think you should be able to use two backticks and a space around each side of the type to safely escape the inner backticks.

| Property | Attribute | Description     | Type                                      | Default     |
| -------- | --------- | --------------- | ----------------------------------------- | ----------- |
| `width`  | `width`   |                 | `` `${number}%` \| `${number}px` ``       | `undefined` |
Property Attribute Description Type Default
width width `${number}%` | `${number}px` undefined

GitHub Reproduction Link:

See the minimal reproduction repo here: https://github.com/brandongregoryscott/stencil-prop-escape-reproduction

Editing the props and running npm run build should update the generated readme.

Other information:

I can probably workaround this by writing a Custom Docs Generator, but it seems like overkill to have to reimplement generation for events, methods, etc.

@ionitron-bot ionitron-bot bot added the triage label Oct 10, 2024
@christian-bromann christian-bromann added Bug: Validated This PR or Issue is verified to be a bug within Stencil Help Wanted and removed triage labels Oct 10, 2024
@christian-bromann
Copy link
Member

Thanks for filing the issue. Any contributions that may resolve this bug are much appreciated. Let me know if you have any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil Help Wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants