npm package: @psenger/markdown-fences
Description: markdown-fences creates workflow activities which inject content into Markdown files with metadata tags.
Author: Philip A Senger
Latest version: 1.2.0

# markdown-fences

> Markdown-fences provides a set of utilities that create assist in workflow related to building
> Markdown files, injecting content, table of contents, javascript documentation with metadata tags.

Features include:

1. readContents - an async read file.
2. writeContents - an async write file.
3. injectJsDoc - builds Markdown JSDocs and injects them into Markdown contents
4. injectFileFencePosts - scans ( one pass ) a Markdown file and injects another content into
   the position
5. injectToc - Scans a markdown and injects a Table of contents.
6. injectCodeFencePosts - scans ( one pass ) a Markdown file and injects another content into
   the position surrounded with GitHub Language highlighting.

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)

## Table of Contents
<!-- Start Generated markdown-toc -->
- [markdown-fences](#markdown-fences)
  * [Table of Contents](#table-of-contents)
  * [Installation Instructions](#installation-instructions)
  * [API](#api)
    + [@psenger/markdown-fences](#psengermarkdown-fences)
      - [@psenger/markdown-fences~readContents(file) ⇒ Promise.&lt;string&gt;](#psengermarkdown-fencesreadcontentsfile-%E2%87%92-promiseltstringgt)
      - [@psenger/markdown-fences~writeContents(file, content, [options]) ⇒ Promise.&lt;void&gt;](#psengermarkdown-fenceswritecontentsfile-content-options-%E2%87%92-promiseltvoidgt)
      - [@psenger/markdown-fences~injectJsDoc(markdownContent, files, [jsDocOptions]) ⇒ Promise.&lt;String&gt;](#psengermarkdown-fencesinjectjsdocmarkdowncontent-files-jsdocoptions-%E2%87%92-promiseltstringgt)
      - [@psenger/markdown-fences~injectFileFencePosts(markdownContent, baseDir, [options]) ⇒ Promise.&lt;String&gt;](#psengermarkdown-fencesinjectfilefencepostsmarkdowncontent-basedir-options-%E2%87%92-promiseltstringgt)
      - [@psenger/markdown-fences~injectCodeFencePosts(markdownContent, baseDir, [options]) ⇒ Promise.&lt;String&gt;](#psengermarkdown-fencesinjectcodefencepostsmarkdowncontent-basedir-options-%E2%87%92-promiseltstringgt)
      - [@psenger/markdown-fences~injectToc(markdownContent) ⇒ Promise.&lt;String&gt;](#psengermarkdown-fencesinjecttocmarkdowncontent-%E2%87%92-promiseltstringgt)
      - [@psenger/markdown-fences~generateMarkDownFile(markdownFile, [newMarkdownFile], baseDir, indexes, [options]) ⇒ Promise.&lt;void&gt;](#psengermarkdown-fencesgeneratemarkdownfilemarkdownfile-newmarkdownfile-basedir-indexes-options-%E2%87%92-promiseltvoidgt)
  * [JavaScript Documentation - Overrides](#javascript-documentation---overrides)
  * [JavaScript Documentation - JSDoc documentation is missing](#javascript-documentation---jsdoc-documentation-is-missing)
  * [Contributing](#contributing)
    + [Rules](#rules)
  * [Deployment Steps](#deployment-steps)
  * [License](#license)
  * [This product uses the following Open Source libraries and is subject to their License](#this-product-uses-the-following-open-source-libraries-and-is-subject-to-their-license)
  * [Acknowledgments](#acknowledgments)
    + [Dependencies](#dependencies)
    + [Development Dependencies](#development-dependencies)
<!-- End Generated markdown-toc -->

## Installation Instructions

```bash
npm install @psenger/markdown-fences --save
```

or

```bash
yarn add @psenger/markdown-fences
```

## API

<!-- Start Generated by documentation.js. Update this documentation by updating the source code. -->
<a name="module_@psenger/markdown-fences"></a>

### @psenger/markdown-fences

* [@psenger/markdown-fences](#module_@psenger/markdown-fences)
  * [~readContents(file)](#module_@psenger/markdown-fences..readContents) ⇒ <code>Promise.&lt;string&gt;</code>
  * [~writeContents(file, content, [options])](#module_@psenger/markdown-fences..writeContents) ⇒ <code>Promise.&lt;void&gt;</code>
  * [~injectJsDoc(markdownContent, files, [jsDocOptions])](#module_@psenger/markdown-fences..injectJsDoc) ⇒ <code>Promise.&lt;String&gt;</code>
  * [~injectFileFencePosts(markdownContent, baseDir, [options])](#module_@psenger/markdown-fences..injectFileFencePosts) ⇒ <code>Promise.&lt;String&gt;</code>
  * [~injectCodeFencePosts(markdownContent, baseDir, [options])](#module_@psenger/markdown-fences..injectCodeFencePosts) ⇒ <code>Promise.&lt;String&gt;</code>
  * [~injectToc(markdownContent)](#module_@psenger/markdown-fences..injectToc) ⇒ <code>Promise.&lt;String&gt;</code>
  * [~generateMarkDownFile(markdownFile, [newMarkdownFile], baseDir, indexes, [options])](#module_@psenger/markdown-fences..generateMarkDownFile) ⇒ <code>Promise.&lt;void&gt;</code>

<a name="module_@psenger/markdown-fences..readContents"></a>

#### @psenger/markdown-fences~readContents(file) ⇒ <code>Promise.&lt;string&gt;</code>
Read the file contents of a Markdown file into a string

**Kind**: inner method of [<code>@psenger/markdown-fences</code>](#module_@psenger/markdown-fences)

| Param | Type | Description |
| --- | --- | --- |
| file | <code>String</code> | The fully qualified input file refer to `path.join` and `__dirname` |

<a name="module_@psenger/markdown-fences..writeContents"></a>

#### @psenger/markdown-fences~writeContents(file, content, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
Write the given contents ( Markdown as a string ) to the given file.

**Kind**: inner method of [<code>@psenger/markdown-fences</code>](#module_@psenger/markdown-fences)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| file | <code>String</code> |  | The fully qualified output file refer to `path.join` and `__dirname` |
| content | <code>String</code> |  | the content to write to the file. |
| [options] | <code>Object</code> | <code>{encoding:&#x27;utf-8&#x27;}</code> | optional options passed to `fs#writeFile` |

<a name="module_@psenger/markdown-fences..injectJsDoc"></a>

#### @psenger/markdown-fences~injectJsDoc(markdownContent, files, [jsDocOptions]) ⇒ <code>Promise.&lt;String&gt;</code>
Insert JavaScript Documentation into these fences.

Warning: this code uses an old version of [jsdoc](https://github.com/jsdoc/jsdoc) throw
several other APIS. And it will not support any

**Kind**: inner method of [<code>@psenger/markdown-fences</code>](#module_@psenger/markdown-fences)
**Returns**: <code>Promise.&lt;String&gt;</code> - - The processed content.

| Param | Type | Description |
| --- | --- | --- |
| markdownContent | <code>String</code> | The WHOLE read me file, or file that has the TOC Fence in it. |
| files | <code>Array.&lt;String&gt;</code> | Any array of fully qualified source files and may include ** globs |
| [jsDocOptions] |  | Optional options passed to jsdoc-to-markdown render command see [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown/blob/master/docs/API.md) |
| [jsDocOptions.heading-depth] |  | The initial heading depth, default 2. For example, with a value of 2 the top-level markdown headings look like "## The heading". |
| [jsDocOptions.module-index-format] |  | default `table`, options are: `none`, `grouped`, `table`, or `dl` |
| [jsDocOptions.global-index-format] |  | default `table`, options are: `none`, `grouped`, `table`, or `dl` |
| [jsDocOptions.property-list-format] |  | default `table`, options are: `list`, or `table` |
| [jsDocOptions.member-index-format] |  | default `grouped`, options are: `grouped`, or `list` |

**Example**
```js
File must have these meta Tags to insert the javascript docs in markdown format
  <!--START_SECTION:jsdoc-->
  <!--END_SECTION:jsdoc-->
```
<a name="module_@psenger/markdown-fences..injectFileFencePosts"></a>

#### @psenger/markdown-fences~injectFileFencePosts(markdownContent, baseDir, [options]) ⇒ <code>Promise.&lt;String&gt;</code>
Inject a file into the meta tag location.

**Kind**: inner method of [<code>@psenger/markdown-fences</code>](#module_@psenger/markdown-fences)
**Returns**: <code>Promise.&lt;String&gt;</code> - - The processed content.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| markdownContent | <code>String</code> |  | The whole markdown content of a file, that has the TOC Fence in it. |
| baseDir | <code>String</code> |  | The base directory for all the fenced files. |
| [options] | <code>Object</code> | <code>{log:false,baseDir: null}</code> | An option |
| [options.log] | <code>Boolean</code> | <code>false</code> | Log flag |

**Example**
```js
File must have these meta Tags to insert the `tutorial.md` file.
  <!--START_SECTION:tutorial.md-->
  <!--END_SECTION:tutorial.md-->
```
<a name="module_@psenger/markdown-fences..injectCodeFencePosts"></a>

#### @psenger/markdown-fences~injectCodeFencePosts(markdownContent, baseDir, [options]) ⇒ <code>Promise.&lt;String&gt;</code>
Inject a file into the code fence section location with optional language highlighting.

**Kind**: inner method of [<code>@psenger/markdown-fences</code>](#module_@psenger/markdown-fences)
**Returns**: <code>Promise.&lt;String&gt;</code> - - The processed content.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| markdownContent | <code>String</code> |  | The whole markdown content of a file, that has the Code Fence in it. |
| baseDir | <code>String</code> |  | The base directory for all the fenced files. |
| [options] | <code>Object</code> | <code>{log:false}</code> | An option |
| [options.log] | <code>Boolean</code> | <code>false</code> | Log flag |

**Example**
```js
File must have these meta Tags to insert the file with optional language:
  <!--START_CODE_FENCE_SECTION:javascript:file:example.js-->
  <!--END_CODE_FENCE_SECTION:javascript:file:example.js-->

  Or without language:
  <!--START_CODE_FENCE_SECTION:file:example.txt-->
  <!--END_CODE_FENCE_SECTION:file:example.txt-->
```
<a name="module_@psenger/markdown-fences..injectToc"></a>

#### @psenger/markdown-fences~injectToc(markdownContent) ⇒ <code>Promise.&lt;String&gt;</code>
Inject a Table of Contents

**Kind**: inner method of [<code>@psenger/markdown-fences</code>](#module_@psenger/markdown-fences)
**Returns**: <code>Promise.&lt;String&gt;</code> - - The processed content.

| Param | Type | Description |
| --- | --- | --- |
| markdownContent | <code>String</code> | The whole markdown file, or file that has the TOC Fence in it. |

**Example**
```js
File must have these meta Tags to locate the TOC.
  <!--START_SECTION:toc-->
  <!--END_SECTION:toc-->
```
<a name="module_@psenger/markdown-fences..generateMarkDownFile"></a>

#### @psenger/markdown-fences~generateMarkDownFile(markdownFile, [newMarkdownFile], baseDir, indexes, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
Generate a Markdown File, processing all the fences.

**Kind**: inner method of [<code>@psenger/markdown-fences</code>](#module_@psenger/markdown-fences)

| Param | Type | Description |
| --- | --- | --- |
| markdownFile | <code>String</code> | The file name of the base file with the fences in it. |
| [newMarkdownFile] | <code>String</code> | The file name of the output file |
| baseDir | <code>String</code> | The directory path that all inserted files can be found |
| indexes | <code>Array.&lt;String&gt;</code> | The JavaScript files to build the JS Doc from. |
| [options] | <code>Object</code> | Options. |


<!-- Stop Generated by documentation.js. -->

## JavaScript Documentation - Overrides

Generating JavaScript Documentation is extremely difficult. This module has gone through a
several solutions and the current release uses the library [Jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown/)

_jsdoc-to-markdown_ has many features and functions. The function used to render JS Docs
is `jsdoc2md.render`. This function offers a variety of options to control the output. With
a mind to offer sensible defaults yet provide full access to the user these are the defaults,
you can provide a object to override it.

Defaults are:

| Attribute              | Value     |
|:-----------------------|:----------|
| `heading-depth`        | 2         |
| `module-index-format`  | `table`   |
| `global-index-format`  | `table`   |
| `property-list-format` | `table`   |
| `member-index-format`  | `grouped` |


## JavaScript Documentation - JSDoc documentation is missing

Your modules might go missing, to prevent this you need to annotate it with `@moduel` see [Annotating a Module](https://github.com/jsdoc2md/jsdoc-to-markdown/wiki/How-to-document-an-ES2015-module-(single-default-export))
for an explanation of the problem.

E.g.
```
/**
 * A module for adding two values.
 * @module add-two-values
 */
```

**Additionally**, directories that start with `_` are skipped, this is yet another feature, that
doesnt make sense till you understand this is the traditional way to skip files for JSDoc ( the
code used under the cover. )

E.g.
```
./src/__test__/*.js  <- wont be scanned.
./src/_harnes_/*.js  <- wont be scanned.
```

## Contributing

Thanks for contributing! 😁 Here are some rules that will make your change to
markdown-fences fruitful.

### Rules

* Raise a ticket to the feature or bug can be discussed
* Pull requests are welcome, but must be accompanied by a ticket approved by the repo owner
* You are expected to add a unit test or two to cover the proposed changes.
* Please run the tests and make sure tests are all passing before submitting your pull request
* Do as the Romans do and stick with existing whitespace and formatting conventions (i.e., tabs instead of spaces, etc)
  * we have provided the following: `.editorconfig` and `.eslintrc`
  * Don't tamper with or change `.editorconfig` and `.eslintrc`
* Please consider adding an example under examples/ that demonstrates any new functionality

## Deployment Steps

**NOTE** I tried to make a `.REDME.md` and build it with tags but there are so many tags within
the code it doesn't work very well. I think going forward I think we should make `README.md` to
make individual parts.

These are notes for deploying to NPM. I used `npmrc` to manage my NPM identities
(`npm i npmrc -g` to install ). Then I created a new profile called `public` with
(`npmrc -c public`) and then switch to it with `npmrc public`.

* create a pull request from `dev` to `main`
* check out `main`
* `npm version patch -m "message here" or minor`
* `npm publish --access public`
* Then switch to `dev` branch
* And then merge `main` into `dev` and push `dev` to origin

## License

MIT License

Copyright (c) 2021 Philip A Senger

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

This product uses the following Open Source libraries and is subject to their License
------

* [documentation.js - ICS](https://github.com/documentationjs/documentation/blob/master/LICENSE)
* [markdown-toc - MIT](https://github.com/jonschlinkert/markdown-toc/blob/master/LICENSE)

## Acknowledgments

This project directly uses the following open-source packages:

### Dependencies

- [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown) - MIT License,
- [markdown-toc](https://github.com/jonschlinkert/markdown-toc) - MIT License

### Development Dependencies

- [auto-changelog](https://github.com/CookPete/auto-changelog) - MIT License,
- [codecov](https://github.com/codecov/codecov-node) - MIT License,
- [eslint](https://github.com/eslint/eslint) - MIT License,
- [jest](https://github.com/jestjs/jest) - MIT License,
- [license-checker](https://github.com/davglass/license-checker) - BSD-3-Clause License,
- [rimraf](https://github.com/isaacs/rimraf) - ISC License,
- [rollup](https://github.com/rollup/rollup) - MIT License,
- [standard](https://github.com/standard/standard) - MIT License,
- [tmp](https://github.com/raszi/node-tmp) - MIT License