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

< and > character are prefixed with \ in method definitions #564

Open
nicfv opened this issue Feb 1, 2024 · 3 comments
Open

< and > character are prefixed with \ in method definitions #564

nicfv opened this issue Feb 1, 2024 · 3 comments

Comments

@nicfv
Copy link

nicfv commented Feb 1, 2024

I brought up an issue in #557 but it was overlooked and then the issue was closed.

When using generic types in class methods, this will add \ characters before the < and >. See example:

export class Example<T> {
    constructor() { }
    /**
     * Get the first item in `arr`
     */
    public first(arr: T[]): T {
        return arr[0];
    }
}

Which yields this markdown file:

[min-example](../README.md) / [Exports](../modules.md) / Example

# Class: Example\<T\>

## Type parameters

| Name |
| :------ |
| `T` |

## Table of contents

### Constructors

- [constructor](Example.md#constructor)

### Methods

- [first](Example.md#first)

## Constructors

### constructor**new Example**\<`T`\>(): [`Example`](Example.md)\<`T`\>

#### Type parameters

| Name |
| :------ |
| `T` |

#### Returns

[`Example`](Example.md)\<`T`\>

#### Defined in

index.ts:2

## Methods

### first**first**(`arr`): `T`

Get the first item in `arr`

#### Parameters

| Name | Type |
| :------ | :------ |
| `arr` | `T`[] |

#### Returns

`T`

#### Defined in

index.ts:6

Which mostly makes sense, but when combining with mkdocs, I get these weird artifacts:

image

Is it possible to create an option on how < and > are escaped? Or better yet, turn < into &lt; and > into &gt;. I tried replacing those characters with the HTML entities, and it worked perfectly.

@nicfv
Copy link
Author

nicfv commented Feb 1, 2024

I just installed 4.0.0-next.47 by the way. It is amazing, great job, and thank you!

Unfortunately, I'm still experiencing this bug. :(

If not fixed, and someone comes across this post in the future, I added these lines to my workflow which seem to fix the problem. (These lines search and replace all instances of \< with &lt; and \> with &gt; in all markdown files in the docs/ directory.)

sed -i 's|\\<|\&lt;|g' docs/**/*.md
sed -i 's|\\>|\&gt;|g' docs/**/*.md

I could potentially see issues arising by using my code above, IF for example you have a URL that contains \< or \>. Since it will convert that to the HTML entity as well, some links might break. You could buff up that script to check to see if it's a markdown link, or the line contains http for example, and not run the replacement.

OR, if you have a comment that contains a code block with escaped square brackets, like this:

<hello>
\<hello>
<hello\>
\<hello\>

Then you'll end up with documentation looking like this:

<hello>
&lt;hello>
<hello&gt;
&lt;hello&gt;

@tgreyuk
Copy link
Member

tgreyuk commented Feb 1, 2024

thanks - i'll have a think about the best solution is for this.

@nicfv
Copy link
Author

nicfv commented Feb 1, 2024

Thank you for taking a look. I also created issue mkdocs/mkdocs#3563 to see if they have anything to add to it.

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 a pull request may close this issue.

2 participants