typedoc-plugin-markdown icon indicating copy to clipboard operation
typedoc-plugin-markdown copied to clipboard

Getting extra spaces before a function parameter

Open ocavue opened this issue 1 year ago • 3 comments
trafficstars

Giving the following source code,

export function fn(
  a: () => number,
  b: number,
  c: GetNum,
): void {
  console.log(a() + b + c())
}

export type GetNum = () => number

And the following typedoc config,

{
    "plugin": [
        "typedoc-plugin-markdown",
    ],
    "useCodeBlocks": true,
    "expandParameters": true,
}

I get the result below:

# Function: fn()

```ts
fn(
   a:     () => number, 
   b: number, 
   c: GetNum): void
```

Notice that there are some extra spaces after a.

Minimal reproduction:

https://githubbox.com/issueset/typedoc-plugin-markdown-function-param

ocavue avatar Feb 23 '24 14:02 ocavue

Thank you - will fix this.

On a related note, you can actually format the output with Prettier using typedoc-plugin-remark. Example output here - https://github.com/tgreyuk/typedoc-plugin-markdown-examples/tree/main/examples/03-typedoc-plugin-remark#prettier.

tgreyuk avatar Feb 25 '24 23:02 tgreyuk

Oh thanks. I didn't know about typedoc-plugin-remark before.

For this particular code block, Prettier cannot format it. I found that I need to add a function keyword at the beginning to make Prettier work. I can achieve this by overriding helpers.getKeyword. typedoc-plugin-markdown's API is very flexible and I love it.

// Prettier cannot format this
fn(
   a:     () => number, 
   b: number, 
   c: GetNum): void
// Prettier can format this
function fn(
   a:     () => number, 
   b: number, 
   c: GetNum): void

ocavue avatar Feb 26 '24 09:02 ocavue

Thanks - thats a good spot actually. The function keyword should be present when useCodeBlocks are enabled.

tgreyuk avatar Feb 26 '24 18:02 tgreyuk