Git Product home page Git Product logo

docsmd's Introduction

docsMD

docsMD is a Markdown to HTML generator that converts your README.md (and other .md files) to HTML using node.js.

Getting started

Install docsMD

$ npm install -g @ckogler/docsmd

Run from the command line:

$ docsmd -i readme.md -o ./docs

# or if you installed it without the -g flag:
$ npx docsmd -i readme.md -o ./docs

This will generate docs/index.html from the supplied readme.md file.

How it works

docsMD takes all input markdown files and creates a .html file in the output directory with the same name and relative path. If a file is called "readme.md" (or "README.md"), the resulting HTML file will be named "index.html", unless an "index.md" file exists in the same directory.

Example

A directory like this one:

|- readme.md
|- types.md
|- legacy
  |- index.md
  |- changelog.md

will result in the following file structure (when using default parameters):

|- docs
  |- index.html        # (renamed from readme.md)
  |- types.html
  |- legacy
    |- index.html
    |- changelog.html

Images

Images with a relative URL will be copied to the same relative location in the output directory. That way the resulting HTML files will be able to show the images when the output directory is deployed to a web server. Absolute image URLs will not be touched.

Links

If a link leads to a relative path and ends with ".md", the ending will be replaced with ".html". That way if you can link between .md files will also work in the generated HTML. Absolute links will not be touched.

Inline support

When genering a single-file documentation the content of multiple individual files might need to be merged together. This is supported by addding a link to the markdown file to include with a text set to '#'. This feature can be disabled with the --inline option.

Configuration

Parameters

Parameter Explanation
--input The files to convert. Supports the glob pattern. Defaults to **/*.md
--exclude Excludes the matching files from the 'input' parameter. Defaults to node_modules/**
--output The directory where the generated HTML files will be placed. Defaults to ./docs
--highlight Can be true or false. Determines whether highlight.js will be applied to source code. Defaults to true
--inline Can be true or false. Determines whether links with a text set to '#' will be replaced with the included markdown content.
--template Can be used to specify a template file. If none is specified, the included default style will be used.

Config file

Alternatively to the CLI parameters, the configuration can be provided via a docsmd.json file in the executing directory.

A provided CLI parameter will take precedence over the config file.

Example file:

// docsmd.json
{
  "input": "**/*.md",
  "output": "docs",
  "template": "docs-template.html"
}

Template

docsMD provides a basic template file, however it is simple to use your own by passing a filename to the "--template" parameter (or template option in the config file). The template file will be reused for each processed .md file

docsMD uses Handlebars internally to apply the template. The template context contains these entries:

name description
content The generated HTML content.
filename The name of the currently parsed file (without extension).

Sample

<html>
  <head>
    <title>{{ filename }}</title>
    </head>
    <body>
    <div>Some header.</div>
    <div>
      <!-- make sure to use triple braces for the content, so HTML is not escaped! -->
      {{{ content }}}
    </div>
    <div>Some footer.</div>
  </body>
</html>

Background

The idea behind this package is to deliver a quick and easy-to-use solution to generate HTML documentation from markdown files in your repository (ideally without any configuration).

It is intended for simple use cases where solutions like JSDoc would be overkill. It is not meant to compete with more complex products and therefore the feature set and configuration options will be kept to a minimum.

Powered by

docsMD uses marked, handlebars and highlight.js internally.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.