Skip to content

Commit 1cc2f98

Browse files
authored
fix: fix GFM markdown output (#1553)
GFM output is currently broken (since v13.2.2), which prevents tables from being written to markdown. This is because as of [remark v13.0.0][1], GFM support was added to the remark-gfm pacakge. 6b5bc25 fixed parsing GFM, however, it didn't add GFM support for markdown output. [1]: https://github.com/remarkjs/remark/releases/tag/13.0.0 Fixes: f4a46b1
1 parent 4600c97 commit 1cc2f98

File tree

3 files changed

+317
-1
lines changed

3 files changed

+317
-1
lines changed

__tests__/__snapshots__/bin.js.snap

Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,304 @@ f5 comment
21682168
"
21692169
`;
21702170
2171+
exports[`build GFM (e.g. markdown tables) for -f md 1`] = `
2172+
"<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2173+
2174+
### Table of Contents
2175+
2176+
* [Klass][1]
2177+
* [Parameters][2]
2178+
* [getFoo][3]
2179+
* [Examples][4]
2180+
* [withOptions][5]
2181+
* [Parameters][6]
2182+
* [withDeepOptions][7]
2183+
* [Parameters][8]
2184+
* [isClass][9]
2185+
* [Parameters][10]
2186+
* [isWeird][11]
2187+
* [Parameters][12]
2188+
* [isBuffer][13]
2189+
* [Parameters][14]
2190+
* [isArrayOfBuffers][15]
2191+
* [Parameters][16]
2192+
* [Examples][17]
2193+
* [MAGIC\\\\_NUMBER][18]
2194+
* [event][19]
2195+
* [CustomError][20]
2196+
* [Properties][21]
2197+
* [bar][22]
2198+
* [bar2][23]
2199+
* [Parameters][24]
2200+
* [bar3][25]
2201+
* [Foo][26]
2202+
* [bar][27]
2203+
* [Foobar][28]
2204+
* [bar][29]
2205+
* [customStreams][30]
2206+
* [passthrough][31]
2207+
* [tableObj][32]
2208+
2209+
## Klass
2210+
2211+
**Extends Stream.Writable**
2212+
2213+
Creates a new Klass
2214+
2215+
### Parameters
2216+
2217+
* \`foo\` &#x20;
2218+
2219+
### getFoo
2220+
2221+
Get this Klass's foo
2222+
2223+
#### Examples
2224+
2225+
this shows you how to getFoo
2226+
2227+
\`\`\`javascript
2228+
var x = foo.getFoo();
2229+
\`\`\`
2230+
2231+
Returns **[Number][33]** foo
2232+
2233+
### withOptions
2234+
2235+
A function with an options parameter
2236+
2237+
#### Parameters
2238+
2239+
* \`options\` **[Object][34]**&#x20;
2240+
2241+
* \`options.foo\` **[string][35]**&#x20;
2242+
* \`options.bar\` **[number][33]**&#x20;
2243+
* \`otherOptions\` **[number][33]?**&#x20;
2244+
2245+
### withDeepOptions
2246+
2247+
A function with a deep options parameter
2248+
2249+
#### Parameters
2250+
2251+
* \`options\` **[Object][34]**&#x20;
2252+
2253+
* \`options.foo\` **[string][35]**&#x20;
2254+
* \`options.bar\` **[Object][34]**&#x20;
2255+
2256+
* \`options.bar.buz\` **[string][35]**&#x20;
2257+
2258+
### isClass
2259+
2260+
Decide whether an object is a Klass instance
2261+
This is a \\\\[klasssic][Klass][1]
2262+
This is a \\\\[link to something that does not exist][DoesNot][36]
2263+
2264+
#### Parameters
2265+
2266+
* \`other\` **[Object][34]**&#x20;
2267+
* \`also\` **any**&#x20;
2268+
2269+
Returns **[boolean][37]** whether the other thing is a Klass
2270+
2271+
### isWeird
2272+
2273+
A function that triggers the case where the autolinker doesn't find
2274+
the referenced class type
2275+
2276+
#### Parameters
2277+
2278+
* \`other\` **Weird**&#x20;
2279+
2280+
Returns **[boolean][37]** whether the other thing is a Klass
2281+
2282+
### isBuffer
2283+
2284+
This method takes a Buffer object that will be linked to nodejs.org
2285+
2286+
#### Parameters
2287+
2288+
* \`buf\` **([Buffer][38] | [string][35])**&#x20;
2289+
* \`size\` **[number][33]** size&#x20;(optional, default \`0\`)
2290+
2291+
Returns **[boolean][37]** whether the other thing is a Klass
2292+
2293+
### isArrayOfBuffers
2294+
2295+
This method takes an array of buffers and counts them
2296+
2297+
#### Parameters
2298+
2299+
* \`buffers\` **[Array][39]<[Buffer][38]>** some buffers
2300+
2301+
#### Examples
2302+
2303+
\`\`\`javascript
2304+
var k = new Klass();
2305+
k.isArrayOfBuffers();
2306+
\`\`\`
2307+
2308+
Returns **[number][33]** how many
2309+
2310+
### MAGIC\\\\_NUMBER
2311+
2312+
A magic number that identifies this Klass.
2313+
2314+
### event
2315+
2316+
Klass event
2317+
2318+
## CustomError
2319+
2320+
a typedef with nested properties
2321+
2322+
### Properties
2323+
2324+
* \`error\` **[object][34]** An error
2325+
2326+
* \`error.code\` **[string][35]** The error's code
2327+
* \`error.description\` **[string][35]** The error's description
2328+
2329+
## bar
2330+
2331+
Get an instance of [Klass][1]. Will make
2332+
a [klass instance multiword][1],
2333+
like a [klass][1]
2334+
2335+
Returns **[Klass][1]** that class
2336+
2337+
## bar2
2338+
2339+
Rest property function
2340+
2341+
### Parameters
2342+
2343+
* \`toys\` **...[Number][33]**&#x20;
2344+
2345+
Returns **[undefined][40]** nothing
2346+
2347+
## bar3
2348+
2349+
Get an instance of [Klass][1]. Will make
2350+
a [klass instance multiword][1],
2351+
like a [klass][1]. This needs a [number][33] input.
2352+
2353+
Returns **[undefined][40]** nothing
2354+
2355+
## Foo
2356+
2357+
This is Foo
2358+
2359+
### bar
2360+
2361+
This is bar
2362+
2363+
## Foobar
2364+
2365+
This is Foobar
2366+
must have a distinct id from Foo.bar
2367+
2368+
### bar
2369+
2370+
This is bar
2371+
2372+
## customStreams
2373+
2374+
I am the container of stream types
2375+
2376+
### passthrough
2377+
2378+
I am a passthrough stream that belongs to customStreams
2379+
2380+
## tableObj
2381+
2382+
| Col 1 | Col 2 | Col 3 |
2383+
| ----- | ----- | ----- |
2384+
| Dat 1 | Dat 2 | Dat 3 |
2385+
| Dat 4 | Dat 5 | Dat 6 |
2386+
2387+
[1]: #klass
2388+
2389+
[2]: #parameters
2390+
2391+
[3]: #getfoo
2392+
2393+
[4]: #examples
2394+
2395+
[5]: #withoptions
2396+
2397+
[6]: #parameters-1
2398+
2399+
[7]: #withdeepoptions
2400+
2401+
[8]: #parameters-2
2402+
2403+
[9]: #isclass
2404+
2405+
[10]: #parameters-3
2406+
2407+
[11]: #isweird
2408+
2409+
[12]: #parameters-4
2410+
2411+
[13]: #isbuffer
2412+
2413+
[14]: #parameters-5
2414+
2415+
[15]: #isarrayofbuffers
2416+
2417+
[16]: #parameters-6
2418+
2419+
[17]: #examples-1
2420+
2421+
[18]: #magic_number
2422+
2423+
[19]: #event
2424+
2425+
[20]: #customerror
2426+
2427+
[21]: #properties
2428+
2429+
[22]: #bar
2430+
2431+
[23]: #bar2
2432+
2433+
[24]: #parameters-7
2434+
2435+
[25]: #bar3
2436+
2437+
[26]: #foo
2438+
2439+
[27]: #bar-1
2440+
2441+
[28]: #foobar
2442+
2443+
[29]: #bar-2
2444+
2445+
[30]: #customstreams
2446+
2447+
[31]: #passthrough
2448+
2449+
[32]: #tableobj
2450+
2451+
[33]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
2452+
2453+
[34]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
2454+
2455+
[35]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
2456+
2457+
[36]: DoesNot
2458+
2459+
[37]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
2460+
2461+
[38]: https://nodejs.org/api/buffer.html
2462+
2463+
[39]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
2464+
2465+
[40]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
2466+
"
2467+
`;
2468+
21712469
exports[`lint command generates lint output 1`] = `""`;
21722470
21732471
exports[`should use browser resolve 1`] = `

__tests__/bin.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,21 @@ test.skip('fatal error', async function () {
368368
}
369369
});
370370

371+
test('build GFM (e.g. markdown tables) for -f md', async function () {
372+
const data = await documentation(
373+
['build', 'fixture/html/nested.input.js', '--shallow', '-f', 'md'],
374+
{},
375+
false
376+
);
377+
expect(data).toMatchSnapshot();
378+
expect(data).toMatch(
379+
`| Col 1 | Col 2 | Col 3 |
380+
| ----- | ----- | ----- |
381+
| Dat 1 | Dat 2 | Dat 3 |
382+
| Dat 4 | Dat 5 | Dat 6 |`
383+
);
384+
});
385+
371386
test.skip('build --document-exported', async function () {
372387
const data = await documentation(
373388
['build fixture/document-exported.input.js --document-exported -f md'],

src/output/markdown.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { remark } from 'remark';
2+
import remarkGfm from 'remark-gfm';
23
import markdownAST from './markdown_ast.js';
34

45
/**
@@ -25,5 +26,7 @@ export default function markdown(comments, args) {
2526
if (!args) {
2627
args = {};
2728
}
28-
return markdownAST(comments, args).then(ast => remark().stringify(ast));
29+
return markdownAST(comments, args).then(ast =>
30+
remark().use(remarkGfm).stringify(ast)
31+
);
2932
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy