markdown-magic 3.7.0 → 4.0.0

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.
package/README.md DELETED
@@ -1,700 +0,0 @@
1
- # Markdown Magic [![npm-version][npm-badge]][npm-link]
2
-
3
- ✨ Add a little magic to your markdown! ✨
4
-
5
- ## About
6
-
7
- <img align="right" width="200" height="183" src="https://cloud.githubusercontent.com/assets/532272/21507867/3376e9fe-cc4a-11e6-9350-7ec4f680da36.gif">Markdown magic uses comment blocks in markdown files to automatically sync or transform its contents.
8
-
9
- - Automatically keep markdown files up to date from local or remote code sources
10
- - Transform markdown content with custom transform functions
11
- - Render markdown with any template engine
12
- - Automatically generate a table of contents
13
- - ... etc
14
-
15
- The comments markdown magic uses are hidden in markdown and when viewed as HTML.
16
-
17
- This `README.md` is generated with `markdown-magic` [view the raw file](https://raw.githubusercontent.com/DavidWells/markdown-magic/master/README.md) to see how.
18
-
19
- [Video demo](http://www.youtube.com/watch?v=4V2utrvxwJ8) • [Example Repo](https://github.com/DavidWells/repo-using-markdown-magic)
20
-
21
- ## Table of Contents
22
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START TOC collapseText="Click to expand" -->
23
- <details>
24
- <summary>Click to expand</summary>
25
-
26
- - [About](#about)
27
- - [Install](#install)
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)
37
- - [API](#api)
38
- - [`MarkdownMagicOptions`](#markdownmagicoptions)
39
- - [`OutputConfig`](#outputconfig)
40
- - [`MarkdownMagicResult`](#markdownmagicresult)
41
- - [Transforms](#transforms)
42
- - [> TOC](#-toc)
43
- - [> CODE](#-code)
44
- - [> FILE](#-file)
45
- - [> REMOTE](#-remote)
46
- - [> fileTree](#-filetree)
47
- - [> install](#-install)
48
- - [Inline transforms](#inline-transforms)
49
- - [Legacy v1 & v2 plugins](#legacy-v1--v2-plugins)
50
- - [Adding Custom Transforms](#adding-custom-transforms)
51
- - [Plugin Example](#plugin-example)
52
- - [Other usage examples](#other-usage-examples)
53
- - [Custom Transform Demo](#custom-transform-demo)
54
- - [Usage examples](#usage-examples)
55
- - [Misc Markdown helpers](#misc-markdown-helpers)
56
- - [Prior Art](#prior-art)
57
- - [License](#license)
58
-
59
- </details>
60
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END -->
61
-
62
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START FILE src=./docs/1_Getting-Started.md -->
63
- ## Install
64
-
65
- To get started. Install the npm package.
66
-
67
- ```bash
68
- npm install markdown-magic --save-dev
69
- ```
70
-
71
- ## Usage
72
-
73
- Use comment blocks in your markdown
74
-
75
- **Example:**
76
- ```md
77
- <!-- doc-gen remote url=http://url-to-raw-md-file.md -->
78
- This content will be dynamically replaced from the remote url
79
- <!-- end-doc-gen -->
80
- ```
81
-
82
- Then run `markdown-magic` via it's CLI or programmatically.
83
-
84
- ### Running via CLI
85
-
86
- Run `markdown --help` to see all available CLI options
87
-
88
- ```bash
89
- markdown
90
- # or
91
- md-magic
92
- ```
93
-
94
- CLI usage example with options
95
-
96
- ```bash
97
- md-magic --path '**/*.md' --config ./config.file.js
98
- ```
99
-
100
- In NPM scripts, `npm run docs` would run the markdown magic and parse all the `.md` files in the directory.
101
-
102
- ```json
103
- "scripts": {
104
- "docs": "md-magic --path '**/*.md'"
105
- },
106
- ```
107
-
108
- 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.
109
-
110
- ### Running programmatically
111
-
112
- ```js
113
- const { markdownMagic } = require('../src')
114
-
115
- /* By default all .md files in cwd will be processed */
116
- markdownMagic().then((results) => {
117
- console.log('result keys', Object.keys(results))
118
- })
119
- ```
120
-
121
- ```js
122
- import path from 'path'
123
- import markdownMagic from 'markdown-magic'
124
-
125
- // Process a Single File
126
- const markdownPath = path.join(__dirname, 'README.md')
127
- markdownMagic(markdownPath)
128
- ```
129
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END *-->
130
-
131
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (FILE:src=./docs/Syntax.md) -->
132
- ## Syntax Examples
133
-
134
- There are various syntax options. Choose your favorite.
135
-
136
- ### Basic
137
-
138
- `openWord transformName [opts]`
139
-
140
- ```md
141
- <!-- doc-gen transformName optionOne='hello' optionTwo='there' -->
142
- content to be replaced
143
- <!-- end-doc-gen -->
144
- ```
145
-
146
- ### Curly braces
147
-
148
- `openWord {transformName} [opts]`
149
-
150
- ```md
151
- <!-- doc-gen {transformName} optionOne='hello' optionTwo='there' -->
152
- content to be replaced
153
- <!-- end-doc-gen -->
154
- ```
155
-
156
- ### Square brackets
157
-
158
- `openWord [transformName] [opts]`
159
-
160
- ```md
161
- <!-- doc-gen [transformName] optionOne='hello' optionTwo='there' -->
162
- content to be replaced
163
- <!-- end-doc-gen -->
164
- ```
165
-
166
- ### Parentheses
167
-
168
- `openWord (transformName) [opts]`
169
-
170
- ```md
171
- <!-- doc-gen (transformName) optionOne='hello' optionTwo='there' -->
172
- content to be replaced
173
- <!-- end-doc-gen -->
174
- ```
175
-
176
- ### Functions
177
-
178
- `openWord transformName([opts])`
179
-
180
- ```md
181
- <!-- doc-gen transformName(
182
- foo='bar'
183
- baz=['qux', 'quux']
184
- ) -->
185
- content to be replaced
186
- <!-- end-doc-gen -->
187
- ```
188
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END *-->
189
-
190
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START JSDocs path="./src/index.js" -->
191
- ### API
192
-
193
- Markdown Magic Instance
194
-
195
- ```js
196
- markdownMagic(globOrOpts, options)
197
- ```
198
-
199
- | Name | Type | Description |
200
- |:---------------------------|:---------------:|:-----------|
201
- | `globOrOpts` | `FilePathsOrGlobs or MarkdownMagicOptions` | Files to process or config. |
202
- | `options` (optional) | `MarkdownMagicOptions` | Markdown magic config. |
203
-
204
- **Returns**
205
-
206
- `Promise<MarkdownMagicResult>`
207
-
208
- **Example**
209
-
210
- ```js
211
- markdownMagic(['**.**.md'], options).then((result) => {
212
- console.log(`Processing complete`, result)
213
- })
214
- ```
215
-
216
- #### `MarkdownMagicOptions`
217
-
218
- Configuration for markdown magic
219
-
220
- Below is the main config for `markdown-magic`
221
-
222
- | Name | Type | Description |
223
- |:---------------------------|:---------------:|:-----------|
224
- | `files` (optional) | `FilePathsOrGlobs` | Files to process. |
225
- | `transforms` (optional) | `Array` | Custom commands to transform block contents, see transforms & custom transforms sections below. Default: `defaultTransforms` |
226
- | `output` (optional) | `OutputConfig` | Output configuration. |
227
- | `syntax` (optional) | `SyntaxType` | Syntax to parse. Default: `md` |
228
- | `open` (optional) | `string` | Opening match word. Default: `doc-gen` |
229
- | `close` (optional) | `string` | Closing match word. If not defined will be same as opening word. Default: `end-doc-gen` |
230
- | `cwd` (optional) | `string` | Current working directory. Default process.cwd(). Default: `process.cwd() ` |
231
- | `outputFlatten` (optional) | `boolean` | Flatten files that are output. |
232
- | `useGitGlob` (optional) | `boolean` | Use git glob for LARGE file directories. |
233
- | `dryRun` (optional) | `boolean` | See planned execution of matched blocks. Default: `false` |
234
- | `debug` (optional) | `boolean` | See debug details. Default: `false` |
235
- | `silent` (optional) | `boolean` | Silence all console output. Default: `false` |
236
- | `applyTransformsToSource` (optional) | `boolean` | Apply transforms to source file. Default is true. Default: `true` |
237
- | `failOnMissingTransforms` (optional) | `boolean` | Fail if transform functions are missing. Default skip blocks. Default: `false` |
238
- | `failOnMissingRemote` (optional) | `boolean` | Fail if remote file is missing. Default: `true` |
239
-
240
- #### `OutputConfig`
241
-
242
- Optional output configuration
243
-
244
- | Name | Type | Description |
245
- |:---------------------------|:---------------:|:-----------|
246
- | `directory` (optional) | `string` | Change output path of new content. Default behavior is replacing the original file. |
247
- | `removeComments` (optional) | `boolean` | Remove comments from output. Default is false. Default: `false` |
248
- | `pathFormatter` (optional) | `function` | Custom function for altering output paths. |
249
- | `applyTransformsToSource` (optional) | `boolean` | Apply transforms to source file. Default is true. This is for when outputDir is set. Default: `false` |
250
-
251
- #### `MarkdownMagicResult`
252
-
253
- Result of markdown processing
254
-
255
- | Name | Type | Description |
256
- |:---------------------------|:---------------:|:-----------|
257
- | `errors` | `Array` | Any errors encountered. |
258
- | `filesChanged` | `Array<string>` | Modified files. |
259
- | `results` | `Array` | md data. |
260
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END - Do not remove or modify this section -->
261
-
262
- ## Transforms
263
-
264
- 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.
265
-
266
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START JSDocs path="./src/transforms/index.js" -->
267
- ### > TOC
268
-
269
- Generate table of contents from markdown file
270
-
271
- **Options:**
272
- - `firstH1` - *boolean* - (optional): Show first h1 of doc in table of contents. Default `false`
273
- - `collapse` - *boolean* - (optional): Collapse the table of contents in a detail accordion. Default `false`
274
- - `collapseText` - *string* - (optional): Text the toc accordion summary
275
- - `excludeText` - *string* - (optional): Text to exclude in the table of contents. Default `Table of Contents`
276
- - `maxDepth` - *number* - (optional): Max depth of headings. Default 4
277
-
278
- **Example:**
279
- ```md
280
- <!-- doc-gen TOC -->
281
- toc will be generated here
282
- <!-- end-doc-gen -->
283
- ```
284
-
285
- Default `matchWord` is `doc-gen`
286
-
287
- ---
288
-
289
- | Name | Type | Description |
290
- |:---------------------------|:---------------:|:-----------|
291
- | `content` | `string` | The current content of the comment block. |
292
- | `options` | `object` | The options passed in from the comment declaration. |
293
-
294
- ### > CODE
295
-
296
- Get code from file or URL and put in markdown
297
-
298
- **Options:**
299
- - `src`: The relative path to the code to pull in, or the `URL` where the raw code lives
300
- - `syntax` (optional): Syntax will be inferred by fileType if not specified
301
- - `header` (optional): Will add header comment to code snippet. Useful for pointing to relative source directory or adding live doc links
302
- - `lines` (optional): a range with lines of code which will then be replaced with code from the file. The line range should be defined as: "lines=*startLine*-*EndLine*" (for example: "lines=22-44"). Please see the example below
303
-
304
- **Example:**
305
- ```md
306
- <!-- doc-gen CODE src="./relative/path/to/code.js" -->
307
- This content will be dynamically replaced with code from the file
308
- <!-- end-doc-gen -->
309
- ```
310
-
311
- ```md
312
- <!-- doc-gen CODE src="./relative/path/to/code.js" lines=22-44 -->
313
- This content will be dynamically replaced with code from the file lines 22 through 44
314
- <!-- end-doc-gen -->
315
- ```
316
-
317
- Default `matchWord` is `doc-gen`
318
-
319
- ---
320
-
321
- | Name | Type | Description |
322
- |:---------------------------|:---------------:|:-----------|
323
- | `content` | `string` | The current content of the comment block. |
324
- | `options` | `object` | The options passed in from the comment declaration. |
325
-
326
- ### > FILE
327
-
328
- Get local file contents.
329
-
330
- **Options:**
331
- - `src`: The relative path to the file to pull in
332
-
333
- **Example:**
334
- ```md
335
- <!-- doc-gen FILE src=./path/to/file -->
336
- This content will be dynamically replaced from the local file
337
- <!-- end-doc-gen -->
338
- ```
339
-
340
- Default `matchWord` is `doc-gen`
341
-
342
- ---
343
-
344
- | Name | Type | Description |
345
- |:---------------------------|:---------------:|:-----------|
346
- | `content` | `string` | The current content of the comment block. |
347
- | `options` | `object` | The options passed in from the comment declaration. |
348
-
349
- ### > REMOTE
350
-
351
- Get any remote Data and put in markdown
352
-
353
- **Options:**
354
- - `url`: The URL of the remote content to pull in
355
-
356
- **Example:**
357
- ```md
358
- <!-- doc-gen REMOTE url=http://url-to-raw-md-file.md -->
359
- This content will be dynamically replaced from the remote url
360
- <!-- end-doc-gen -->
361
- ```
362
-
363
- Default `matchWord` is `doc-gen`
364
-
365
- ---
366
-
367
- | Name | Type | Description |
368
- |:---------------------------|:---------------:|:-----------|
369
- | `content` | `string` | The current content of the comment block. |
370
- | `options` | `object` | The options passed in from the comment declaration. |
371
-
372
- ### > fileTree
373
-
374
- Generate a file tree table of contents
375
-
376
- **Options:**
377
- - `src` (optional): The directory path to generate the file tree for. Default `.` (current directory)
378
- - `maxDepth` (optional): Maximum depth to traverse in the directory tree. Default `3`
379
- - `includeFiles` (optional): Whether to include files in the tree or just directories. Default `true`
380
- - `exclude` (optional): Array of glob patterns to exclude from the tree. Default `[]`
381
- - `showSize` (optional): Whether to show file sizes. Default `false`
382
- - `format` (optional): Output format: "tree" or "list". Default `"tree"`
383
-
384
- **Example:**
385
- ```md
386
- <!-- doc-gen fileTree src="./src" maxDepth=2 -->
387
- file tree will be generated here
388
- <!-- end-doc-gen -->
389
- ```
390
-
391
- **Example Output (tree format):**
392
- ```
393
- └── src/
394
- ├── transforms/
395
- │ ├── code/
396
- │ │ ...
397
- │ ├── fileTree.js
398
- │ ├── index.js
399
- │ └── toc.js
400
- ├── utils/
401
- │ ├── fs.js
402
- │ ├── logs.js
403
- │ └── text.js
404
- └── index.js
405
- ```
406
-
407
- **Example Output (list format):**
408
- ```md
409
- - **src/**
410
- - **transforms/**
411
- - **code/**
412
- - ...
413
- - fileTree.js
414
- - index.js
415
- - toc.js
416
- - **utils/**
417
- - fs.js
418
- - logs.js
419
- - text.js
420
- - index.js
421
- ```
422
-
423
- **Example with file sizes:**
424
- ```
425
- └── src/
426
- ├── index.js (15.2 KB)
427
- └── package.json (552 B)
428
- ```
429
-
430
- Default `matchWord` is `doc-gen`
431
-
432
- ---
433
-
434
- | Name | Type | Description |
435
- |:---------------------------|:---------------:|:-----------|
436
- | `content` | `string` | The current content of the comment block. |
437
- | `options` | `object` | The options passed in from the comment declaration. |
438
-
439
- ### > install
440
-
441
- Generate installation instructions in a markdown table format
442
-
443
- **Options:**
444
- - `packageName` (optional): The name of the package to install. If not provided, will try to read from package.json
445
- - `isDev` (optional): Whether to install the package as a dev dependency. Default `false`
446
- - `header` (optional): The header to use for the installation instructions. Default `# Installation`
447
- - `body` (optional): The body to use for the installation instructions. Default `Install the \`${packageName}\` cli using your favorite package manager.`
448
-
449
- **Example:**
450
- ```md
451
- <!-- doc-gen install -->
452
- Installation instructions will be generated here
453
- <!-- end-doc-gen -->
454
- ```
455
-
456
- Default `matchWord` is `doc-gen`
457
-
458
- ---
459
-
460
- | Name | Type | Description |
461
- |:---------------------------|:---------------:|:-----------|
462
- | `content` | `string` | The current content of the comment block. |
463
- | `options` | `object` | The options passed in from the comment declaration. |
464
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END - Do not remove or modify this section -->
465
-
466
- ## Inline transforms
467
-
468
- Any transform, including custom transforms can be used inline as well to insert content into paragraphs and other places.
469
-
470
- The face symbol 👉 <!-- MD-MAGIC-EXAMPLE:START (INLINE_EXAMPLE) -->**⊂◉‿◉つ**<!-- MD-MAGIC-EXAMPLE:END --> is auto generated inline.
471
-
472
- **Example:**
473
- ```md
474
- <!-- doc-gen (FILE:src=./path/to/file) -->xyz<!-- end-doc-gen -->
475
- ```
476
-
477
- ## Legacy v1 & v2 plugins
478
-
479
- These plugins work with older versions of markdown-magic. Adapting them to the newer plugin syntax should be pretty straight forward.
480
-
481
- * [wordcount](https://github.com/DavidWells/markdown-magic-wordcount/) - Add wordcount to markdown files
482
- * [github-contributors](https://github.com/DavidWells/markdown-magic-github-contributors) - List out the contributors of a given repository
483
- * [directory-tree](https://github.com/camacho/markdown-magic-directory-tree) - Add directory tree to markdown files
484
- * [install-command](https://github.com/camacho/markdown-magic-install-command) - Add install command to markdown files with `peerDependencies` included
485
- * [subpackage-list](https://github.com/camacho/markdown-magic-subpackage-list) - Add list of all subpackages (great for projects that use [Lerna](https://github.com/lerna/lerna))
486
- * [version-badge](https://github.com/camacho/markdown-magic-version-badge) - Add a badge with the latest version of the project
487
- * [template](https://github.com/camacho/markdown-magic-template) - Add Lodash template support
488
- * [dependency-table](https://github.com/camacho/markdown-magic-dependency-table) - Add a table of dependencies with links to their repositories, version information, and a short description
489
- * [package-scripts](https://github.com/camacho/markdown-magic-package-scripts) - Add a table of `package.json` scripts with descriptions
490
- * [prettier](https://github.com/camacho/markdown-magic-prettier) - Format code blocks with [`prettier`](https://github.com/prettier/prettier)
491
- * [engines](https://github.com/camacho/markdown-magic-engines) - Print engines list from `package.json`
492
- * [jsdoc](https://github.com/bradtaylorsf/markdown-magic-jsdoc) - Adds jsdoc comment support
493
- * [build-badge](https://github.com/rishichawda/markdown-magic-build-badge) - Update branch badges to auto-magically point to current branches.
494
- * [package-json](https://github.com/forresst/markdown-magic-package-json) - Add the package.json properties to markdown files
495
- * [figlet](https://github.com/lafourchette/markdown-magic-figlet) - Add FIGfont text to markdown files
496
- * [local-image](https://github.com/stevenbenisek/markdown-magic-local-image) - plugin to add local images to markdown
497
- * [markdown-magic-build-badge](https://github.com/rishichawda/markdown-magic-build-badge) - A plugin to update your branch badges to point to correct branch status
498
-
499
- ## Adding Custom Transforms
500
-
501
- Markdown Magic is extendable via plugins.
502
-
503
- Plugins allow developers to add new transforms to the `config.transforms` object. This allows for things like using different rendering engines, custom formatting, or any other logic you might want.
504
-
505
- Plugins run in order of registration.
506
-
507
- The below code is used to generate **this markdown file** via the plugin system.
508
-
509
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (CODE:src=./examples/generate-readme.js) -->
510
- ```js
511
- const path = require('path')
512
- const { readFileSync } = require('fs')
513
- const { parseComments } = require('doxxx')
514
- const { markdownMagic } = require('../src')
515
- const { deepLog } = require('../src/utils/logs')
516
-
517
- const config = {
518
- matchWord: 'MD-MAGIC-EXAMPLE', // default matchWord is AUTO-GENERATED-CONTENT
519
- transforms: {
520
- /* Match <!-- AUTO-GENERATED-CONTENT:START (customTransform:optionOne=hi&optionOne=DUDE) --> */
521
- customTransform({ content, options }) {
522
- console.log('original content in comment block', content)
523
- console.log('options defined on transform', options)
524
- // options = { optionOne: hi, optionOne: DUDE}
525
- return `This will replace all the contents of inside the comment ${options.optionOne}`
526
- },
527
- /* Match <!-- AUTO-GENERATED-CONTENT:START JSDocs path="../file.js" --> */
528
- JSDocs(markdownMagicPluginAPI) {
529
- const { options } = markdownMagicPluginAPI
530
- const fileContents = readFileSync(options.path, 'utf8')
531
- const docBlocs = parseComments(fileContents, { skipSingleStar: true })
532
- .filter((item) => {
533
- return !item.isIgnored
534
- })
535
- /* Remove empty comments with no tags */
536
- .filter((item) => {
537
- return item.tags.length
538
- })
539
- /* Remove inline type defs */
540
- .filter((item) => {
541
- return item.description.text !== ''
542
- })
543
- /* Sort types to end */
544
- .sort((a, b) => {
545
- if (a.type && !b.type) return 1
546
- if (!a.type && b.type) return -1
547
- return 0
548
- })
549
-
550
- docBlocs.forEach((data) => {
551
- // console.log('data', data)
552
- delete data.code
553
- })
554
- // console.log('docBlocs', docBlocs)
555
-
556
- if (docBlocs.length === 0) {
557
- throw new Error('No docBlocs found')
558
- }
559
-
560
- // console.log(docBlocs.length)
561
- let updatedContent = ''
562
- docBlocs.forEach((data) => {
563
- if (data.type) {
564
- updatedContent += `#### \`${data.type}\`\n\n`
565
- }
566
-
567
- updatedContent += `${data.description.text}\n`
568
-
569
- if (data.tags.length) {
570
- let table = '| Name | Type | Description |\n'
571
- table += '|:---------------------------|:---------------:|:-----------|\n'
572
- data.tags.filter((tag) => {
573
- if (tag.tagType === 'param') return true
574
- if (tag.tagType === 'property') return true
575
- return false
576
- }).forEach((tag) => {
577
- const optionalText = tag.isOptional ? ' (optional) ' : ' '
578
- const defaultValueText = (typeof tag.defaultValue !== 'undefined') ? ` Default: \`${tag.defaultValue}\` ` : ' '
579
- table += `| \`${tag.name}\`${optionalText}`
580
- table += `| \`${tag.type.replace('|', 'or')}\` `
581
- table += `| ${tag.description.replace(/\.\s?$/, '')}.${defaultValueText}|\n`
582
- })
583
- updatedContent+= `\n${table}\n`
584
-
585
- const returnValues = data.tags.filter((tag) => tag.tagType === 'returns')
586
- if (returnValues.length) {
587
- returnValues.forEach((returnValue) => {
588
- updatedContent += `**Returns**\n\n`
589
- updatedContent += `\`${returnValue.type}\`\n\n`
590
- })
591
- }
592
-
593
- const examples = data.tags.filter((tag) => tag.tagType === 'example')
594
- if (examples.length) {
595
- examples.forEach((example) => {
596
- updatedContent += `**Example**\n\n`
597
- updatedContent += `\`\`\`js\n${example.tagValue}\n\`\`\`\n\n`
598
- })
599
- }
600
- }
601
- })
602
- return updatedContent.replace(/^\s+|\s+$/g, '')
603
- },
604
- INLINE_EXAMPLE: () => {
605
- return '**⊂◉‿◉つ**'
606
- },
607
- lolz() {
608
- return `This section was generated by the cli config markdown.config.js file`
609
- },
610
- /* Match <!-- AUTO-GENERATED-CONTENT:START (pluginExample) --> */
611
- pluginExample: require('./plugin-example')({ addNewLine: true }),
612
- /* Include plugins from NPM */
613
- // count: require('markdown-magic-wordcount'),
614
- // github: require('markdown-magic-github-contributors')
615
- }
616
- }
617
-
618
- const markdownPath = path.join(__dirname, '..', 'README.md')
619
- markdownMagic(markdownPath, config, () => {
620
- console.log('Docs ready')
621
- })
622
- ```
623
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END -->
624
-
625
- ## Plugin Example
626
-
627
- Plugins must return a transform function with the following signature.
628
-
629
- ```js
630
- return function myCustomTransform (content, options)
631
- ```
632
-
633
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (CODE:src=./examples/plugin-example.js) -->
634
- ```js
635
- /* Custom Transform Plugin example */
636
- module.exports = function customPlugin(pluginOptions) {
637
- // set plugin defaults
638
- const defaultOptions = {
639
- addNewLine: false
640
- }
641
- const userOptions = pluginOptions || {}
642
- const pluginConfig = Object.assign(defaultOptions, userOptions)
643
- // return the transform function
644
- return function myCustomTransform ({ content, options }) {
645
- const newLine = (pluginConfig.addNewLine) ? '\n' : ''
646
- const updatedContent = content + newLine
647
- return updatedContent
648
- }
649
- }
650
- ```
651
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END -->
652
-
653
- [View the raw file](https://raw.githubusercontent.com/DavidWells/markdown-magic/master/README.md) file and run `npm run docs` to see this plugin run
654
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (pluginExample) ⛔️ -->
655
- This content is altered by the `pluginExample` plugin registered in `examples/generate-readme.js`
656
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END -->
657
-
658
- ## Other usage examples
659
-
660
- - [With Github Actions](https://github.com/dineshsonachalam/repo-using-markdown-autodocs)
661
- - [Serverless Plugin Repo](https://github.com/serverless/plugins/blob/master/generate-docs.js) this example takes a `json` file and converts it into a github flavored markdown table
662
- - [MochaJS](https://github.com/mochajs/mocha/blob/4cc711fa00f7166a2303b77bf2487d1c2cc94621/scripts/markdown-magic.config.js)
663
- - [tc39/agendas](https://github.com/tc39/agendas#agendas) - [code](https://github.com/tc39/agendas/blob/65945b1b6658e9829ef95a51bf2632ff44f951e6/scripts/generate.js)
664
- - [moleculerjs/moleculer-addons](https://github.com/moleculerjs/moleculer-addons/blob/7cf0f72140717c52621b724cd54a710517106df0/readme-generator.js)
665
- - [good-first-issue](https://github.com/bnb/good-first-issue/blob/e65513a1f26167dea3c137008b8796640d8d5303/markdown.config.js)
666
- - [navikt/nav-frontend-moduler](https://github.com/navikt/nav-frontend-moduler/blob/20ad521c27a43d3203eab4bc32121e5b8270c077/_scripts/generateReadmes.js)
667
- - [country-flags-svg](https://github.com/ronatskiy/country-flags-svg/blob/cfb2368c7e634ebc1679855e13cc3e26ca11187f/markdown.config.js)
668
- - [react-typesetting](https://github.com/exogen/react-typesetting/blob/7114cdc8c4cb1b0d59ebc8b5364e808687419889/markdown.config.js)
669
- - [and many more!](https://github.com/search?o=desc&p=1&q=markdown-magic+filename%3Apackage.json+-user%3Ah13i32maru+-user%3Aesdoc+-user%3Aes-doc&s=indexed&type=Code)
670
-
671
- ## Custom Transform Demo
672
-
673
- View the raw source of this `README.md` file to see the comment block and see how the `customTransform` function in `examples/generate-readme.js` works
674
-
675
- <!-- ⛔️ MD-MAGIC-EXAMPLE:START (customTransform:optionOne=hi&optionOne=DUDE) - Do not remove or modify this section -->
676
- This will replace all the contents of inside the comment DUDE
677
- <!-- ⛔️ MD-MAGIC-EXAMPLE:END - Do not remove or modify this section -->
678
-
679
- ## Usage examples
680
-
681
- - [Projects using markdown-magic](https://github.com/search?q=path%3A**%2Fpackage.json+%22markdown-magic%22&type=code)
682
- - [Examples in md](https://github.com/search?l=Markdown&o=desc&q=AUTO-GENERATED-CONTENT&s=indexed&type=Code)
683
-
684
-
685
- ## Misc Markdown helpers
686
-
687
- - https://github.com/azu/markdown-function
688
-
689
- ## Prior Art
690
-
691
- 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.
692
-
693
- ## License
694
-
695
- [MIT][mit] © [DavidWells][author]
696
-
697
- [npm-badge]:https://img.shields.io/npm/v/markdown-magic.svg?style=flat-square
698
- [npm-link]: http://www.npmjs.com/package/markdown-magic
699
- [mit]: http://opensource.org/licenses/MIT
700
- [author]: http://github.com/davidwells