1.2.0 • Published 8 months ago

@psenger/markdown-fences v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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

Table of Contents

Installation Instructions

npm install @psenger/markdown-fences --save

or

yarn add @psenger/markdown-fences

API

@psenger/markdown-fences

@psenger/markdown-fences~readContents(file) ⇒ Promise.<string>

Read the file contents of a Markdown file into a string

Kind: inner method of @psenger/markdown-fences

ParamTypeDescription
fileStringThe fully qualified input file refer to path.join and __dirname

@psenger/markdown-fences~writeContents(file, content, options) ⇒ Promise.<void>

Write the given contents ( Markdown as a string ) to the given file.

Kind: inner method of @psenger/markdown-fences

ParamTypeDefaultDescription
fileStringThe fully qualified output file refer to path.join and __dirname
contentStringthe content to write to the file.
optionsObject{encoding:'utf-8'}optional options passed to fs#writeFile

@psenger/markdown-fences~injectJsDoc(markdownContent, files, jsDocOptions) ⇒ Promise.<String>

Insert JavaScript Documentation into these fences.

Warning: this code uses an old version of jsdoc throw several other APIS. And it will not support any

Kind: inner method of @psenger/markdown-fences Returns: Promise.<String> - - The processed content.

ParamTypeDescription
markdownContentStringThe WHOLE read me file, or file that has the TOC Fence in it.
filesArray.<String>Any array of fully qualified source files and may include ** globs
jsDocOptionsOptional options passed to jsdoc-to-markdown render command see jsdoc-to-markdown
jsDocOptions.heading-depthThe initial heading depth, default 2. For example, with a value of 2 the top-level markdown headings look like "## The heading".
jsDocOptions.module-index-formatdefault table, options are: none, grouped, table, or dl
jsDocOptions.global-index-formatdefault table, options are: none, grouped, table, or dl
jsDocOptions.property-list-formatdefault table, options are: list, or table
jsDocOptions.member-index-formatdefault grouped, options are: grouped, or list

Example

File must have these meta Tags to insert the javascript docs in markdown format
  <!--START_SECTION:jsdoc-->
  <!--END_SECTION:jsdoc-->

@psenger/markdown-fences~injectFileFencePosts(markdownContent, baseDir, options) ⇒ Promise.<String>

Inject a file into the meta tag location.

Kind: inner method of @psenger/markdown-fences Returns: Promise.<String> - - The processed content.

ParamTypeDefaultDescription
markdownContentStringThe whole markdown content of a file, that has the TOC Fence in it.
baseDirStringThe base directory for all the fenced files.
optionsObject{log:false,baseDir: null}An option
options.logBooleanfalseLog flag

Example

File must have these meta Tags to insert the `tutorial.md` file.
  <!--START_SECTION:tutorial.md-->
  <!--END_SECTION:tutorial.md-->

@psenger/markdown-fences~injectCodeFencePosts(markdownContent, baseDir, options) ⇒ Promise.<String>

Inject a file into the code fence section location with optional language highlighting.

Kind: inner method of @psenger/markdown-fences Returns: Promise.<String> - - The processed content.

ParamTypeDefaultDescription
markdownContentStringThe whole markdown content of a file, that has the Code Fence in it.
baseDirStringThe base directory for all the fenced files.
optionsObject{log:false}An option
options.logBooleanfalseLog flag

Example

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-->

@psenger/markdown-fences~injectToc(markdownContent) ⇒ Promise.<String>

Inject a Table of Contents

Kind: inner method of @psenger/markdown-fences Returns: Promise.<String> - - The processed content.

ParamTypeDescription
markdownContentStringThe whole markdown file, or file that has the TOC Fence in it.

Example

File must have these meta Tags to locate the TOC.
  <!--START_SECTION:toc-->
  <!--END_SECTION:toc-->

@psenger/markdown-fences~generateMarkDownFile(markdownFile, newMarkdownFile, baseDir, indexes, options) ⇒ Promise.<void>

Generate a Markdown File, processing all the fences.

Kind: inner method of @psenger/markdown-fences

ParamTypeDescription
markdownFileStringThe file name of the base file with the fences in it.
newMarkdownFileStringThe file name of the output file
baseDirStringThe directory path that all inserted files can be found
indexesArray.<String>The JavaScript files to build the JS Doc from.
optionsObjectOptions.

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

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:

AttributeValue
heading-depth2
module-index-formattable
global-index-formattable
property-list-formattable
member-index-formatgrouped

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 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

Acknowledgments

This project directly uses the following open-source packages:

Dependencies

Development Dependencies