typedoc2md / typedoc-plugin-markdown

A plugin for TypeDoc that enables TypeScript API documentation to be generated in Markdown.
https://typedoc-plugin-markdown.org
MIT License
725 stars 177 forks source link

Getting extra spaces before a function parameter #580

Closed ocavue closed 7 months ago

ocavue commented 9 months ago

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
tgreyuk commented 9 months ago

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.

ocavue commented 9 months ago

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
tgreyuk commented 9 months ago

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