markdown-magic 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +295 -101
  2. package/cli.js +4 -1
  3. package/lib/block-parser.js +32 -28
  4. package/lib/block-parser.test.js +2 -0
  5. package/lib/cli.js +101 -19
  6. package/lib/cli.test.js +12 -12
  7. package/lib/index.js +418 -119
  8. package/lib/process-contents.js +59 -23
  9. package/lib/process-file.js +39 -4
  10. package/lib/transforms/code.js +33 -10
  11. package/lib/transforms/file.js +4 -2
  12. package/lib/transforms/index.js +114 -0
  13. package/lib/transforms/sectionToc.js +2 -2
  14. package/lib/transforms/toc.js +22 -4
  15. package/lib/transforms/wordCount.js +2 -2
  16. package/lib/utils/fs.js +8 -172
  17. package/lib/utils/fs.test.js +4 -162
  18. package/lib/utils/hash-file.js +28 -0
  19. package/lib/utils/logs.js +16 -2
  20. package/lib/utils/syntax.js +1 -0
  21. package/lib/utils/text.js +1 -1
  22. package/lib/utils/toposort.js +131 -0
  23. package/package.json +4 -3
  24. package/lib/utils/md/filters.js +0 -20
  25. package/lib/utils/md/find-code-blocks.js +0 -88
  26. package/lib/utils/md/find-date.js +0 -32
  27. package/lib/utils/md/find-frontmatter.js +0 -92
  28. package/lib/utils/md/find-frontmatter.test.js +0 -17
  29. package/lib/utils/md/find-html-tags.js +0 -105
  30. package/lib/utils/md/find-images-md.js +0 -27
  31. package/lib/utils/md/find-images.js +0 -107
  32. package/lib/utils/md/find-links.js +0 -220
  33. package/lib/utils/md/find-unmatched-html-tags.js +0 -32
  34. package/lib/utils/md/fixtures/2022-01-22-date-in-filename.md +0 -14
  35. package/lib/utils/md/fixtures/file-with-frontmatter.md +0 -32
  36. package/lib/utils/md/fixtures/file-with-links.md +0 -153
  37. package/lib/utils/md/md.test.js +0 -105
  38. package/lib/utils/md/parse.js +0 -146
  39. package/lib/utils/md/utils.js +0 -19
package/README.md CHANGED
@@ -19,135 +19,250 @@ This `README.md` is generated with `markdown-magic` [view the raw file](https://
19
19
  [Video demo](http://www.youtube.com/watch?v=4V2utrvxwJ8) • [Example Repo](https://github.com/DavidWells/repo-using-markdown-magic)
20
20
 
21
21
  ## Table of Contents
22
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (TOC:collapse=true&collapseText=Click to expand) -->
22
+ <!-- ⛔️ MD-MAGIC-EXAMPLE:START TOC collapse=true collapseText="Click to expand" -->
23
23
  <details>
24
24
  <summary>Click to expand</summary>
25
25
 
26
26
  - [About](#about)
27
27
  - [Install](#install)
28
28
  - [Usage](#usage)
29
+ - [Running via CLI](#running-via-cli)
30
+ - [Running programmatically](#running-programmatically)
31
+ - [Syntax Examples](#syntax-examples)
32
+ - [Basic](#basic)
33
+ - [Curly braces](#curly-braces)
34
+ - [Square brackets](#square-brackets)
35
+ - [Parentheses](#parentheses)
36
+ - [Functions](#functions)
29
37
  - [API](#api)
30
- - [Configuration Options](#configuration-options)
31
- - [CLI Usage](#cli-usage)
38
+ - [`MarkdownMagicOptions`](#markdownmagicoptions)
39
+ - [`OutputConfig`](#outputconfig)
40
+ - [`MarkdownMagicResult`](#markdownmagicresult)
32
41
  - [Transforms](#transforms)
33
42
  - [> TOC](#-toc)
34
43
  - [> CODE](#-code)
35
44
  - [> FILE](#-file)
36
45
  - [> REMOTE](#-remote)
37
46
  - [Inline transforms](#inline-transforms)
38
- - [🔌 Markdown magic plugins](#-markdown-magic-plugins)
47
+ - [Legacy v1 & v2 plugins](#legacy-v1--v2-plugins)
39
48
  - [Adding Custom Transforms](#adding-custom-transforms)
40
49
  - [Plugin Example](#plugin-example)
41
50
  - [Other usage examples](#other-usage-examples)
42
51
  - [Custom Transform Demo](#custom-transform-demo)
43
- - [Prior Art](#prior-art)
44
- - [License](#license)
45
52
  - [Usage examples](#usage-examples)
46
53
  - [Misc Markdown helpers](#misc-markdown-helpers)
54
+ - [Prior Art](#prior-art)
55
+ - [License](#license)
47
56
 
48
57
  </details>
49
58
  <!-- ⛔️ MD-MAGIC-EXAMPLE:END -->
50
59
 
60
+ <!-- ⛔️ MD-MAGIC-EXAMPLE:START FILE src=./docs/1_Getting-Started.md -->
51
61
  ## Install
52
62
 
63
+ To get started. Install the npm package.
64
+
53
65
  ```bash
54
66
  npm install markdown-magic --save-dev
55
67
  ```
56
68
 
57
69
  ## Usage
58
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (CODE:src=./examples/1-_basic-usage.js) -->
59
- <!-- The below code snippet is automatically added from ./examples/1-_basic-usage.js -->
70
+
71
+ Use comment blocks in your markdown
72
+
73
+ **Example:**
74
+ ```md
75
+ <!-- doc-gen remote url=http://url-to-raw-md-file.md -->
76
+ This content will be dynamically replaced from the remote url
77
+ <!-- end-doc-gen -->
78
+ ```
79
+
80
+ Then run `markdown-magic` via it's CLI or programmatically.
81
+
82
+ ### Running via CLI
83
+
84
+ Run `markdown --help` to see all available CLI options
85
+
86
+ ```bash
87
+ markdown
88
+ # or
89
+ md-magic
90
+ ```
91
+
92
+ CLI usage example with options
93
+
94
+ ```bash
95
+ md-magic --path '**/*.md' --config ./config.file.js
96
+ ```
97
+
98
+ In NPM scripts, `npm run docs` would run the markdown magic and parse all the `.md` files in the directory.
99
+
100
+ ```json
101
+ "scripts": {
102
+ "docs": "md-magic --path '**/*.md'"
103
+ },
104
+ ```
105
+
106
+ If you have a `markdown.config.js` file where `markdown-magic` is invoked, it will automatically use that as the configuration unless otherwise specified by `--config` flag.
107
+
108
+ ### Running programmatically
109
+
110
+ ```js
111
+ const { markdownMagic } = require('../lib')
112
+
113
+ /* By default all .md files in cwd will be processed */
114
+ markdownMagic().then((results) => {
115
+ console.log('result keys', Object.keys(results))
116
+ })
117
+ ```
118
+
60
119
  ```js
61
120
  import path from 'path'
62
121
  import markdownMagic from 'markdown-magic'
63
122
 
123
+ // Process a Single File
64
124
  const markdownPath = path.join(__dirname, 'README.md')
65
125
  markdownMagic(markdownPath)
66
126
  ```
67
127
  <!-- ⛔️ MD-MAGIC-EXAMPLE:END *-->
68
128
 
69
- ### API
129
+ <!-- ⛔️ MD-MAGIC-EXAMPLE:START (FILE:src=./docs/Syntax.md) -->
130
+ ## Syntax Examples
70
131
 
71
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (RENDERDOCS:path=./lib/index.js)
72
- - Do not remove or modify this section -->
73
- Markdown Magic
74
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END - Do not remove or modify this section -->
132
+ There are various syntax options. Choose your favorite.
75
133
 
76
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (RENDERDOCS:path=./lib/process-file.js)
77
- - Do not remove or modify this section -->
78
- ### Configuration Options
134
+ ### Basic
79
135
 
80
- - `transforms` - *object* - (optional) Custom commands to transform block contents, see transforms & custom transforms sections below.
136
+ `openWord transformName [opts]`
81
137
 
82
- - `outputDir` - *string* - (optional) Change output path of new content. Default behavior is replacing the original file
138
+ ```md
139
+ <!-- doc-gen transformName optionOne='hello' optionTwo='there' -->
140
+ content to be replaced
141
+ <!-- end-doc-gen -->
142
+ ```
83
143
 
84
- - `matchWord` - *string* - (optional) Comment pattern to look for & replace inner contents. Default `AUTO-GENERATED-CONTENT`
144
+ ### Curly braces
85
145
 
86
- - `DEBUG` - *Boolean* - (optional) set debug flag to `true` to inspect the process
87
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END - Do not remove or modify this section -->
146
+ `openWord {transformName} [opts]`
88
147
 
89
- ## CLI Usage
148
+ ```md
149
+ <!-- doc-gen {transformName} optionOne='hello' optionTwo='there' -->
150
+ content to be replaced
151
+ <!-- end-doc-gen -->
152
+ ```
90
153
 
91
- You can use `markdown-magic` as a CLI command. Run `markdown --help` to see all available CLI options
154
+ ### Square brackets
92
155
 
93
- ```bash
94
- markdown --help
95
- # or
96
- md-magic
156
+ `openWord [transformName] [opts]`
157
+
158
+ ```md
159
+ <!-- doc-gen [transformName] optionOne='hello' optionTwo='there' -->
160
+ content to be replaced
161
+ <!-- end-doc-gen -->
97
162
  ```
98
163
 
99
- This is useful for adding the package quickly to your `package.json` npm scripts
164
+ ### Parentheses
100
165
 
101
- CLI usage example with options
166
+ `openWord (transformName) [opts]`
102
167
 
103
- ```bash
104
- md-magic --path '**/*.md' --config ./config.file.js
168
+ ```md
169
+ <!-- doc-gen (transformName) optionOne='hello' optionTwo='there' -->
170
+ content to be replaced
171
+ <!-- end-doc-gen -->
105
172
  ```
106
173
 
107
- In NPM scripts, `npm run docs` would run the markdown magic and parse all the `.md` files in the directory.
174
+ ### Functions
108
175
 
109
- ```json
110
- "scripts": {
111
- "docs": "md-magic --path '**/*.md' --ignore 'node_modules'"
112
- },
176
+ `openWord transformName([opts])`
177
+
178
+ ```md
179
+ <!-- doc-gen transformName(
180
+ foo='bar'
181
+ baz=['qux', 'quux']
182
+ ) -->
183
+ content to be replaced
184
+ <!-- end-doc-gen -->
113
185
  ```
186
+ <!-- ⛔️ MD-MAGIC-EXAMPLE:END *-->
114
187
 
115
- If you have a `markdown.config.js` file where `markdown-magic` is invoked, it will automatically use that as the configuration unless otherwise specified by `--config` flag.
188
+ <!-- ⛔️ MD-MAGIC-EXAMPLE:START JSDocs path="./lib/index.js" -->
189
+ ### API
190
+
191
+ Markdown Magic Instance
116
192
 
117
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (CODE:src=./md.config.js) -->
118
- <!-- The below code snippet is automatically added from ./md.config.js -->
119
193
  ```js
120
- /* CLI markdown.config.js file example */
121
- module.exports = {
122
- // handleOutputPath: (currentPath) => {
123
- // const newPath = 'x' + currentPath
124
- // return newPath
125
- // },
126
- // handleOutputPath: (currentPath) => {
127
- // const newPath = currentPath.replace(/fixtures/, 'fixtures-out')
128
- // return newPath
129
- // },
130
- transforms: {
131
- /* Match <!-- AUTO-GENERATED-CONTENT:START (transformOne) --> */
132
- transformOne() {
133
- return `This section was generated by the cli config md.config.js file`
134
- },
135
- functionName() {
136
- return `xyz`
137
- }
138
- }
139
- }
194
+ markdownMagic(globOrOpts, options)
140
195
  ```
141
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END *-->
196
+
197
+ | Name | Type | Description |
198
+ |:---------------------------|:---------------:|:-----------|
199
+ | `globOrOpts` | `FilePathsOrGlobs or MarkdownMagicOptions` | Files to process or config. |
200
+ | `options` (optional) | `MarkdownMagicOptions` | Markdown magic config. |
201
+
202
+ **Returns**
203
+
204
+ `Promise<MarkdownMagicResult>`
205
+
206
+ **Example**
207
+
208
+ ```js
209
+ markdownMagic(['**.**.md'], options).then((result) => {
210
+ console.log(`Processing complete`, result)
211
+ })
212
+ ```
213
+
214
+ #### `MarkdownMagicOptions`
215
+
216
+ Configuration for markdown magic
217
+
218
+ Below is the main config for `markdown-magic`
219
+
220
+ | Name | Type | Description |
221
+ |:---------------------------|:---------------:|:-----------|
222
+ | `files` (optional) | `FilePathsOrGlobs` | Files to process. |
223
+ | `transforms` (optional) | `Array` | Custom commands to transform block contents, see transforms & custom transforms sections below. Default: `defaultTransforms` |
224
+ | `output` (optional) | `OutputConfig` | Output configuration. |
225
+ | `syntax` (optional) | `SyntaxType` | Syntax to parse. Default: `md` |
226
+ | `open` (optional) | `string` | Opening match word. Default: `doc-gen` |
227
+ | `close` (optional) | `string` | Closing match word. If not defined will be same as opening word. Default: `end-doc-gen` |
228
+ | `cwd` (optional) | `string` | Current working directory. Default process.cwd(). Default: `process.cwd() ` |
229
+ | `outputFlatten` (optional) | `boolean` | Flatten files that are output. |
230
+ | `useGitGlob` (optional) | `boolean` | Use git glob for LARGE file directories. |
231
+ | `dryRun` (optional) | `boolean` | See planned execution of matched blocks. Default: `false` |
232
+ | `debug` (optional) | `boolean` | See debug details. Default: `false` |
233
+ | `silent` (optional) | `boolean` | Silence all console output. Default: `false` |
234
+ | `failOnMissingTransforms` (optional) | `boolean` | Fail if transform functions are missing. Default skip blocks. Default: `false` |
235
+
236
+ #### `OutputConfig`
237
+
238
+ Optional output configuration
239
+
240
+ | Name | Type | Description |
241
+ |:---------------------------|:---------------:|:-----------|
242
+ | `directory` (optional) | `string` | Change output path of new content. Default behavior is replacing the original file. |
243
+ | `removeComments` (optional) | `boolean` | Remove comments from output. Default is false. Default: `false` |
244
+ | `pathFormatter` (optional) | `function` | Custom function for altering output paths. |
245
+ | `applyTransformsToSource` (optional) | `boolean` | Apply transforms to source file. Default is true. This is for when outputDir is set. Default: `false` |
246
+
247
+ #### `MarkdownMagicResult`
248
+
249
+ Result of markdown processing
250
+
251
+ | Name | Type | Description |
252
+ |:---------------------------|:---------------:|:-----------|
253
+ | `errors` | `Array` | Any errors encountered. |
254
+ | `filesChanged` | `Array<string>` | Modified files. |
255
+ | `results` | `Array` | md data. |
256
+ <!-- ⛔️ MD-MAGIC-EXAMPLE:END - Do not remove or modify this section -->
142
257
 
143
258
  ## Transforms
144
259
 
145
260
  Markdown Magic comes with a couple of built-in transforms for you to use or you can extend it with your own transforms. See 'Custom Transforms' below.
146
261
 
147
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (RENDERDOCS:path=./lib/transforms/index.js) - Do not remove or modify this section -->
262
+ <!-- ⛔️ MD-MAGIC-EXAMPLE:START JSDocs path="./lib/transforms/index.js" -->
148
263
  ### > TOC
149
264
 
150
- Generate taxxxxble of contents from markdown file
265
+ Generate table of contents from markdown file
151
266
 
152
267
  **Options:**
153
268
  - `firsth1` - *boolean* - (optional): Show first h1 of doc in table of contents. Default `false`
@@ -158,15 +273,20 @@ Generate taxxxxble of contents from markdown file
158
273
 
159
274
  **Example:**
160
275
  ```md
161
- <!-- AUTO-GENERATED-CONTENT:START (TOC) -->
276
+ <!-- doc-gen (TOC) -->
162
277
  toc will be generated here
163
- <!-- AUTO-GENERATED-CONTENT:END -->
278
+ <!-- end-doc-gen -->
164
279
  ```
165
280
 
166
281
  Default `MATCHWORD` is `AUTO-GENERATED-CONTENT`
167
282
 
168
283
  ---
169
284
 
285
+ | Name | Type | Description |
286
+ |:---------------------------|:---------------:|:-----------|
287
+ | `content` | `string` | The current content of the comment block. |
288
+ | `options` | `object` | The options passed in from the comment declaration. |
289
+
170
290
  ### > CODE
171
291
 
172
292
  Get code from file or URL and put in markdown
@@ -179,21 +299,26 @@ Get code from file or URL and put in markdown
179
299
 
180
300
  **Example:**
181
301
  ```md
182
- <!-- AUTO-GENERATED-CONTENT:START (CODE:src=./relative/path/to/code.js) -->
302
+ <!-- doc-gen (CODE:src=./relative/path/to/code.js) -->
183
303
  This content will be dynamically replaced with code from the file
184
- <!-- AUTO-GENERATED-CONTENT:END -->
304
+ <!-- end-doc-gen -->
185
305
  ```
186
306
 
187
307
  ```md
188
- <!-- AUTO-GENERATED-CONTENT:START (CODE:src=./relative/path/to/code.js&lines=22-44) -->
308
+ <!-- doc-gen (CODE:src=./relative/path/to/code.js&lines=22-44) -->
189
309
  This content will be dynamically replaced with code from the file lines 22 through 44
190
- <!-- AUTO-GENERATED-CONTENT:END -->
310
+ <!-- end-doc-gen -->
191
311
  ```
192
312
 
193
313
  Default `MATCHWORD` is `AUTO-GENERATED-CONTENT`
194
314
 
195
315
  ---
196
316
 
317
+ | Name | Type | Description |
318
+ |:---------------------------|:---------------:|:-----------|
319
+ | `content` | `string` | The current content of the comment block. |
320
+ | `options` | `object` | The options passed in from the comment declaration. |
321
+
197
322
  ### > FILE
198
323
 
199
324
  Get local file contents.
@@ -203,15 +328,20 @@ Get local file contents.
203
328
 
204
329
  **Example:**
205
330
  ```md
206
- <!-- AUTO-GENERATED-CONTENT:START (FILE:src=./path/to/file) -->
331
+ <!-- doc-gen (FILE:src=./path/to/file) -->
207
332
  This content will be dynamically replaced from the local file
208
- <!-- AUTO-GENERATED-CONTENT:END -->
333
+ <!-- end-doc-gen -->
209
334
  ```
210
335
 
211
336
  Default `MATCHWORD` is `AUTO-GENERATED-CONTENT`
212
337
 
213
338
  ---
214
339
 
340
+ | Name | Type | Description |
341
+ |:---------------------------|:---------------:|:-----------|
342
+ | `content` | `string` | The current content of the comment block. |
343
+ | `options` | `object` | The options passed in from the comment declaration. |
344
+
215
345
  ### > REMOTE
216
346
 
217
347
  Get any remote Data and put in markdown
@@ -221,14 +351,19 @@ Get any remote Data and put in markdown
221
351
 
222
352
  **Example:**
223
353
  ```md
224
- <!-- AUTO-GENERATED-CONTENT:START (REMOTE:url=http://url-to-raw-md-file.md) -->
354
+ <!-- doc-gen (REMOTE:url=http://url-to-raw-md-file.md) -->
225
355
  This content will be dynamically replaced from the remote url
226
- <!-- AUTO-GENERATED-CONTENT:END -->
356
+ <!-- end-doc-gen -->
227
357
  ```
228
358
 
229
359
  Default `MATCHWORD` is `AUTO-GENERATED-CONTENT`
230
360
 
231
361
  ---
362
+
363
+ | Name | Type | Description |
364
+ |:---------------------------|:---------------:|:-----------|
365
+ | `content` | `string` | The current content of the comment block. |
366
+ | `options` | `object` | The options passed in from the comment declaration. |
232
367
  <!-- ⛔️ MD-MAGIC-EXAMPLE:END - Do not remove or modify this section -->
233
368
 
234
369
  ## Inline transforms
@@ -239,10 +374,12 @@ The face symbol 👉 <!-- MD-MAGIC-EXAMPLE:START (INLINE_EXAMPLE) -->**⊂◉‿
239
374
 
240
375
  **Example:**
241
376
  ```md
242
- <!-- AUTO-GENERATED-CONTENT:START (FILE:src=./path/to/file) -->xyz<!-- AUTO-GENERATED-CONTENT:END -->
377
+ <!-- doc-gen (FILE:src=./path/to/file) -->xyz<!-- end-doc-gen -->
243
378
  ```
244
379
 
245
- ## 🔌 Markdown magic plugins
380
+ ## Legacy v1 & v2 plugins
381
+
382
+ These plugins work with older versions of markdown-magic. Adapting them to the newer plugin syntax should be pretty straight forward.
246
383
 
247
384
  * [wordcount](https://github.com/DavidWells/markdown-magic-wordcount/) - Add wordcount to markdown files
248
385
  * [github-contributors](https://github.com/DavidWells/markdown-magic-github-contributors) - List out the contributors of a given repository
@@ -273,13 +410,12 @@ Plugins run in order of registration.
273
410
  The below code is used to generate **this markdown file** via the plugin system.
274
411
 
275
412
  <!-- ⛔️ MD-MAGIC-EXAMPLE:START (CODE:src=./examples/generate-readme.js) -->
276
- <!-- The below code snippet is automatically added from ./examples/generate-readme.js -->
277
413
  ```js
278
- const fs = require('fs')
279
414
  const path = require('path')
280
- const doxxx = require('doxxx')
415
+ const { readFileSync } = require('fs')
416
+ const { parseComments } = require('doxxx')
281
417
  const { markdownMagic } = require('../lib')
282
- // const { markdownMagic } = require('markdown-magic')
418
+ const { deepLog } = require('../lib/utils/logs')
283
419
 
284
420
  const config = {
285
421
  matchWord: 'MD-MAGIC-EXAMPLE', // default matchWord is AUTO-GENERATED-CONTENT
@@ -291,21 +427,81 @@ const config = {
291
427
  // options = { optionOne: hi, optionOne: DUDE}
292
428
  return `This will replace all the contents of inside the comment ${options.optionOne}`
293
429
  },
294
- /* Match <!-- AUTO-GENERATED-CONTENT:START (RENDERDOCS:path=../file.js) --> */
295
- RENDERDOCS(api) {
296
- console.log('api', api)
297
- const { options } = api
298
- console.log('options.path', path.resolve(options.path))
299
- const fileContents = fs.readFileSync(options.path, 'utf8')
300
- const docBlocs = doxxx.parseComments(fileContents, { raw: true, skipSingleStar: true })
430
+ /* Match <!-- AUTO-GENERATED-CONTENT:START JSDocs path="../file.js" --> */
431
+ JSDocs(markdownMagicPluginAPI) {
432
+ const { options } = markdownMagicPluginAPI
433
+ const fileContents = readFileSync(options.path, 'utf8')
434
+ const docBlocs = parseComments(fileContents, { skipSingleStar: true })
435
+ .filter((item) => {
436
+ return !item.isIgnored
437
+ })
438
+ /* Remove empty comments with no tags */
301
439
  .filter((item) => {
302
440
  return item.tags.length
303
441
  })
304
- console.log('docBlocs', docBlocs)
305
- // process.exit(1)
442
+ /* Remove inline type defs */
443
+ .filter((item) => {
444
+ return item.description.text !== ''
445
+ })
446
+ /* Sort types to end */
447
+ .sort((a, b) => {
448
+ if (a.type && !b.type) return 1
449
+ if (!a.type && b.type) return -1
450
+ return 0
451
+ })
452
+
453
+ docBlocs.forEach((data) => {
454
+ // console.log('data', data)
455
+ delete data.code
456
+ })
457
+ // console.log('docBlocs', docBlocs)
458
+
459
+ if (docBlocs.length === 0) {
460
+ throw new Error('No docBlocs found')
461
+ }
462
+
463
+ // console.log(docBlocs.length)
306
464
  let updatedContent = ''
307
465
  docBlocs.forEach((data) => {
308
- updatedContent += `${data.description.full}\n\n`
466
+ if (data.type) {
467
+ updatedContent += `#### \`${data.type}\`\n\n`
468
+ }
469
+
470
+ updatedContent += `${data.description.text}\n`
471
+
472
+ if (data.tags.length) {
473
+ let table = '| Name | Type | Description |\n'
474
+ table += '|:---------------------------|:---------------:|:-----------|\n'
475
+ data.tags.filter((tag) => {
476
+ if (tag.tagType === 'param') return true
477
+ if (tag.tagType === 'property') return true
478
+ return false
479
+ }).forEach((tag) => {
480
+ const optionalText = tag.isOptional ? ' (optional) ' : ' '
481
+ const defaultValueText = (typeof tag.defaultValue !== 'undefined') ? ` Default: \`${tag.defaultValue}\` ` : ' '
482
+ console.log('tag', tag)
483
+ table += `| \`${tag.name}\`${optionalText}`
484
+ table += `| \`${tag.type.replace('|', 'or')}\` `
485
+ table += `| ${tag.description.replace(/\.\s?$/, '')}.${defaultValueText}|\n`
486
+ })
487
+ updatedContent+= `\n${table}\n`
488
+
489
+ const returnValues = data.tags.filter((tag) => tag.tagType === 'returns')
490
+ if (returnValues.length) {
491
+ returnValues.forEach((returnValue) => {
492
+ updatedContent += `**Returns**\n\n`
493
+ updatedContent += `\`${returnValue.type}\`\n\n`
494
+ })
495
+ }
496
+
497
+ const examples = data.tags.filter((tag) => tag.tagType === 'example')
498
+ if (examples.length) {
499
+ examples.forEach((example) => {
500
+ updatedContent += `**Example**\n\n`
501
+ updatedContent += `\`\`\`js\n${example.tagValue}\n\`\`\`\n\n`
502
+ })
503
+ }
504
+ }
309
505
  })
310
506
  return updatedContent.replace(/^\s+|\s+$/g, '')
311
507
  },
@@ -313,7 +509,6 @@ const config = {
313
509
  return '**⊂◉‿◉つ**'
314
510
  },
315
511
  lolz() {
316
- console.log('run lol')
317
512
  return `This section was generated by the cli config markdown.config.js file`
318
513
  },
319
514
  /* Match <!-- AUTO-GENERATED-CONTENT:START (pluginExample) --> */
@@ -340,7 +535,6 @@ return function myCustomTransform (content, options)
340
535
  ```
341
536
 
342
537
  <!-- ⛔️ MD-MAGIC-EXAMPLE:START (CODE:src=./examples/plugin-example.js) -->
343
- <!-- The below code snippet is automatically added from ./examples/plugin-example.js -->
344
538
  ```js
345
539
  /* Custom Transform Plugin example */
346
540
  module.exports = function customPlugin(pluginOptions) {
@@ -386,6 +580,16 @@ View the raw source of this `README.md` file to see the comment block and see ho
386
580
  This will replace all the contents of inside the comment DUDE
387
581
  <!-- ⛔️ MD-MAGIC-EXAMPLE:END - Do not remove or modify this section -->
388
582
 
583
+ ## Usage examples
584
+
585
+ - [Project using markdown-magic](https://github.com/search?o=desc&q=filename%3Apackage.json+%22markdown-magic%22&s=indexed&type=Code)
586
+ - [Examples in md](https://github.com/search?l=Markdown&o=desc&q=AUTO-GENERATED-CONTENT&s=indexed&type=Code)
587
+
588
+
589
+ ## Misc Markdown helpers
590
+
591
+ - https://github.com/azu/markdown-function
592
+
389
593
  ## Prior Art
390
594
 
391
595
  This was inspired by [Kent C Dodds](https://twitter.com/kentcdodds) and [jfmengels](https://github.com/jfmengels)'s [all contributors cli](https://github.com/jfmengels/all-contributors-cli) project.
@@ -397,14 +601,4 @@ This was inspired by [Kent C Dodds](https://twitter.com/kentcdodds) and [jfmenge
397
601
  [npm-badge]:https://img.shields.io/npm/v/markdown-magic.svg?style=flat-square
398
602
  [npm-link]: http://www.npmjs.com/package/markdown-magic
399
603
  [mit]: http://opensource.org/licenses/MIT
400
- [author]: http://github.com/davidwells
401
-
402
- ## Usage examples
403
-
404
- - [Project using markdown-magic](https://github.com/search?o=desc&q=filename%3Apackage.json+%22markdown-magic%22&s=indexed&type=Code)
405
- - [Examples in md](https://github.com/search?l=Markdown&o=desc&q=AUTO-GENERATED-CONTENT&s=indexed&type=Code)
406
-
407
-
408
- ## Misc Markdown helpers
409
-
410
- - https://github.com/azu/markdown-function
604
+ [author]: http://github.com/davidwells
package/cli.js CHANGED
@@ -3,5 +3,8 @@ const { runCli } = require('./lib/cli')
3
3
  const argv = process.argv.slice(2)
4
4
  const cliArgs = mri(argv)
5
5
 
6
+ /*
7
+ console.log('Raw args:', argv)
8
+ console.log('Before args:', cliArgs)
9
+ /** */
6
10
  runCli(cliArgs)
7
-