`<` and `>` character are prefixed with `\` in method definitions
Closed this issue · 4 comments
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:
Is it possible to create an option on how <
and >
are escaped? Or better yet, turn <
into <
and >
into >
. I tried replacing those characters with the HTML entities, and it worked perfectly.
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 <
and \>
with >
in all markdown files in the docs/
directory.)
sed -i 's|\\<|\<|g' docs/**/*.md
sed -i 's|\\>|\>|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>
<hello>
<hello>
<hello>
thanks - i'll have a think about the best solution is for this.
Thank you for taking a look. I also created issue mkdocs/mkdocs#3563 to see if they have anything to add to it.
"useHTMLEncodedBrackets" option will html encode angle brackets (rather than escape backslash). Available in typedoc-plugin-markdown@4.2.0.