• Stars
    star
    445
  • Rank 98,085 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GitHub markdown preprocessor.

GitSpo Mentions NPM version Travis build status Dependency Status

Gitdown adds additional functionality (generating table of contents, including documents, using variables, etc.) to GitHub Flavored Markdown.

Cheat Sheet

// Generate table of contents
{"gitdown": "contents"}
{"gitdown": "contents", "maxLevel": 4}
{"gitdown": "contents", "rootId": "features"}

// Use a custom defined variable
{"gitdown": "variable", "name": "nameOfTheVariable"}

// Include file
{"gitdown": "include", "file": "./LICENSE.md"}

// Get file size
{"gitdown": "filesize", "file": "./src/gitdown.js"}
{"gitdown": "filesize", "file": "./src/gitdown.js", "gzip": true}

// Generate badges
{"gitdown": "badge", "name": "npm-version"}
{"gitdown": "badge", "name": "bower-version"}
{"gitdown": "badge", "name": "travis"}
{"gitdown": "badge", "name": "david"}
{"gitdown": "badge", "name": "david-dev"}
{"gitdown": "badge", "name": "waffle"}

// Print date
{"gitdown": "date", "format": "YYYY"}

Contents

Command Line Usage

npm install gitdown -g
gitdown ./.README/README.md --output-file ./README.md

API Usage

Gitdown is designed to be run using either of the build systems, such as Gulp or Grunt.

const Gitdown = require('gitdown');

// Read the markdown file written using the Gitdown extended markdown.
// File name is not important.
// Having all of the Gitdown markdown files under ./.README/ path is the recommended convention.
const gitdown = Gitdown.readFile('./.README/README.md');

// If you have the subject in a string, call the constructor itself:
// gitdown = Gitdown.read('literal string');

// Get config.
gitdown.getConfig()

// Set config.
gitdown.setConfig({
  gitinfo: {
    gitPath: __dirname
  }
})

// Output the markdown file.
// All of the file system operations are relative to the root of the repository.
gitdown.writeFile('README.md');

Gulp

Gitdown writeFile method returns a promise, that will make Gulp wait until the task is completed. No third-party plugins needed.

const gulp = require('gulp');
const Gitdown = require('gitdown');

gulp.task('gitdown', () => {
  return Gitdown
    .readFile('./.README/README.md')
    .writeFile('README.md');
});

gulp.task('watch', () => {
  gulp.watch(['./.README/*'], ['gitdown']);
});

Logging

Gitdown is using console object to log messages. You can set your own logger:

gitdown.setLogger({
  info: () => {},
  warn: () => {}
});

The logger is used to inform about Dead URLs and Fragment Identifiers.

Syntax

Gitdown extends markdown syntax using JSON:

{"gitdown": "helper name", "parameter name": "parameter value"}

The JSON object must have a gitdown property that identifies the helper you intend to execute. The rest is a regular JSON string, where each property is a named configuration property of the helper that you are referring to.

JSON that does not start with a "gitdown" property will remain untouched.

Ignoring Sections of the Document

Use HTML comment tags to ignore sections of the document:

Gitdown JSON will be interpolated.
<!-- gitdown: off -->
Gitdown JSON will not be interpolated.
<!-- gitdown: on -->
Gitdown JSON will be interpolated.

Register a Custom Helper

gitdown.registerHelper('my-helper-name', {
  /**
    * @var {Number} Weight determines the processing order of the helper function. Default: 10.
    */
  weight: 10,
  /**
    * @param {Object} config JSON configuration.
    * @return {mixed|Promise}
    */
  compile: (config) => {
      return 'foo: ' + config.foo;
  }
});
{"gitdown": "my-helper-name", "foo": "bar"}

Produces:

foo: bar

a

Features

Generate Table of Contents

{"gitdown": "contents"}

Generates table of contents.

The table of contents is generated using markdown-contents.

Example

{"gitdown": "contents", "maxLevel": 4, "rootId": "features"}
* [Generate Table of Contents](#features-generate-table-of-contents)
    * [Example](#features-generate-table-of-contents-example)
    * [JSON Configuration](#features-generate-table-of-contents-json-configuration)
* [Heading Nesting](#features-heading-nesting)
    * [Parser Configuration](#features-heading-nesting-parser-configuration)
* [Find Dead URLs and Fragment Identifiers](#features-find-dead-urls-and-fragment-identifiers)
    * [Parser Configuration](#features-find-dead-urls-and-fragment-identifiers-parser-configuration-1)
* [Reference an Anchor in the Repository](#features-reference-an-anchor-in-the-repository)
    * [JSON Configuration](#features-reference-an-anchor-in-the-repository-json-configuration-1)
    * [Parser Configuration](#features-reference-an-anchor-in-the-repository-parser-configuration-2)
* [Variables](#features-variables)
    * [Example](#features-variables-example-1)
    * [JSON Configuration](#features-variables-json-configuration-2)
    * [Parser Configuration](#features-variables-parser-configuration-3)
* [Include File](#features-include-file)
    * [Example](#features-include-file-example-2)
    * [JSON Configuration](#features-include-file-json-configuration-3)
* [Get File Size](#features-get-file-size)
    * [Example](#features-get-file-size-example-3)
    * [JSON Configuration](#features-get-file-size-json-configuration-4)
* [Generate Badges](#features-generate-badges)
    * [Supported Services](#features-generate-badges-supported-services)
    * [Example](#features-generate-badges-example-4)
    * [JSON Configuration](#features-generate-badges-json-configuration-5)
* [Print Date](#features-print-date)
    * [Example](#features-print-date-example-5)
    * [JSON Configuration](#features-print-date-json-configuration-6)
* [Gitinfo](#features-gitinfo)
    * [Example](#features-gitinfo-example-6)
    * [Supported Properties](#features-gitinfo-supported-properties)
    * [JSON Configuration](#features-gitinfo-json-configuration-7)
    * [Parser Configuration](#features-gitinfo-parser-configuration-4)

JSON Configuration

Name Description Default
maxLevel The maximum heading level after which headings are excluded. 3
rootId ID of the root heading. Provide it when you need table of contents for a specific section of the document. Throws an error if element with the said ID does not exist in the document. N/A

Heading Nesting

Github markdown processor generates heading ID based on the text of the heading.

The conflicting IDs are solved with a numerical suffix, e.g.

# Foo
## Something
# Bar
## Something
<h1 id="foo">Foo</h1>
<h2 id="something">Something</h1>
<h1 id="bar">Bar</h1>
<h2 id="something-1">Something</h1>

The problem with this approach is that it makes the order of the content important.

Gitdown will nest the headings using parent heading names to ensure uniqueness, e.g.

# Foo
## Something
# Bar
## Something
<h1 id="foo">Foo</h1>
<h2 id="foo-something">Something</h1>
<h1 id="bar">Bar</h1>
<h2 id="bar-something">Something</h1>

Parser Configuration

Name Description Default
headingNesting.enabled Boolean flag indicating whether to nest headings. true

Find Dead URLs and Fragment Identifiers

Uses Deadlink to iterate through all of the URLs in the resulting document. Throws an error if either of the URLs is resolved with an HTTP status other than 200 or fragment identifier (anchor) is not found.

Parser Configuration

Name Description Default
deadlink.findDeadURLs Find dead URLs. false
deadlink.findDeadFragmentIdentifiers Find dead fragment identifiers. false

Reference an Anchor in the Repository

This feature is under development. Please suggest ideas https://github.com/gajus/gitdown/issues

{"gitdown": "anchor"}

Generates a Github URL to the line in the source code with the anchor documentation tag of the same name.

Place a documentation tag @gitdownanchor <name> anywhere in the code base, e.g.

/**
 * @gitdownanchor my-anchor-name
 */

Then reference the tag in the Gitdown document:

Refer to [foo]({"gitdown": "anchor", "name": "my-anchor-name"}).

The anchor name must match /^[a-z]+[a-z0-9\-_:\.]*$/i.

Gitdown will throw an error if the anchor is not found.

JSON Configuration

Name Description Default
name Anchor name. N/A

Parser Configuration

Name Description Default
anchor.exclude Array of paths to exclude. ['./dist/*']

Variables

{"gitdown": "variable"}

Prints the value of a property defined under a parser variable.scope configuration property. Throws an error if property is not set.

Example

const gitdown = Gitdown(
  '{"gitdown": "variable", "name": "name.first"}' +
  '{"gitdown": "variable", "name": "name.last"}'
);

gitdown.setConfig({
  variable: {
    scope: {
      name: {
        first: "Gajus",
        last: "Kuizinas"
      }
    }
  }
});

JSON Configuration

Name Description Default
name Name of the property defined under a parser variable.scope configuration property. N/A

Parser Configuration

Name Description Default
variable.scope Variable scope object. {}

Include File

{"gitdown": "include"}

Includes the contents of the file to the document.

The included file can have Gitdown JSON hooks.

Example

See source code of ./.README/README.md.

JSON Configuration

Name Description Default
file Path to the file. The path is relative to the root of the repository. N/A

Get File Size

{"gitdown": "filesize"}

Returns file size formatted in human friendly format.

Example

{"gitdown": "filesize", "file": "src/gitdown.js"}
{"gitdown": "filesize", "file": "src/gitdown.js", "gzip": true}

Generates:

8.47 KB
2.54 KB

JSON Configuration

Name Description Default
file Path to the file. The path is relative to the root of the repository. N/A
gzip A boolean value indicating whether to gzip the file first. false

Generate Badges

{"gitdown": "badge"}

Gitdown generates markdown for badges using the environment variables, e.g. if it is an NPM badge, Gitdown will lookup the package name from package.json.

Badges are generated using http://shields.io/.

Supported Services

Name Description
npm-version NPM package version.
bower-version Bower package version.
travis State of the Travis build.
david David state of the dependencies.
david-dev David state of the development dependencies.
waffle Issues ready on Waffle board.
gitter Join Gitter chat.
coveralls Coveralls.
codeclimate-gpa Code Climate GPA.
codeclimate-coverage Code Climate test coverage.
appveyor AppVeyor status.

What service are you missing? Raise an issue.

Example

{"gitdown": "badge", "name": "npm-version"}
{"gitdown": "badge", "name": "travis"}
{"gitdown": "badge", "name": "david"}

Generates:

[![NPM version](http://img.shields.io/npm/v/gitdown.svg?style=flat-square)](https://www.npmjs.org/package/gitdown)
[![Travis build status](http://img.shields.io/travis/gajus/gitdown/master.svg?style=flat-square)](https://travis-ci.org/gajus/gitdown)
[![Dependency Status](https://img.shields.io/david/gajus/gitdown.svg?style=flat-square)](https://david-dm.org/gajus/gitdown)

JSON Configuration

Name Description Default
name Name of the service. N/A

Print Date

{"gitdown": "date"}

Prints a string formatted according to the given moment format string using the current time.

Example

{"gitdown": "date"}
{"gitdown": "date", "format": "YYYY"}

Generates:

1563038327
2019

JSON Configuration

Name Description Default
format Moment format. X (UNIX timestamp)

Gitinfo

{"gitdown": "gitinfo"}

Gitinfo gets info about the local GitHub repository.

Example

{"gitdown": "gitinfo", "name": "username"}
{"gitdown": "gitinfo", "name": "name"}
{"gitdown": "gitinfo", "name": "url"}
{"gitdown": "gitinfo", "name": "branch"}
gajus
gitdown
https://github.com/gajus/gitdown
master

Supported Properties

Name Description
username Username of the repository author.
name Repository name.
url Repository URL.
branch Current branch name.

JSON Configuration

Name Description Default
name Name of the property. N/A

Parser Configuration

Name Description Default
gitinfo.defaultBranchName Default branch to use when the current branch name cannot be resolved. N/A
gitinfo.gitPath Path to the .git/ directory or a descendant. __dirname of the script constructing an instance of Gitdown.

Recipes

Automating Gitdown

Use Husky to check if user generated README.md before committing his changes.

"husky": {
  "hooks": {
    "pre-commit": "npm run lint && npm run test && npm run build",
    "pre-push": "gitdown ./.README/README.md --output-file ./README.md --check",
  }
}

--check attributes makes Gitdown check if the target file differes from the source template. If the file differs then the program exits with an error code and message:

Gitdown destination file does not represent the current state of the template.

Do not automate generating and committing documentation: automating commits will result in a noisy commit log.

More Repositories

1

react-css-modules

Seamless mapping of class names to CSS modules inside of React components.
JavaScript
5,232
star
2

slonik

A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.
TypeScript
4,550
star
3

swing

A swipeable cards interface. The swipe-left/swipe-right for yes/no input. As seen in apps like Jelly and Tinder.
JavaScript
2,618
star
4

babel-plugin-react-css-modules

Transforms styleName to className using compile time CSS module resolution.
JavaScript
2,044
star
5

redux-immutable

redux-immutable is used to create an equivalent function of Redux combineReducers that works with Immutable.js state.
TypeScript
1,880
star
6

eslint-plugin-flowtype

Flow type linting rules for ESLint.
JavaScript
1,078
star
7

roarr

JSON logger for Node.js and browser.
TypeScript
1,062
star
8

prepack-webpack-plugin

A webpack plugin for prepack.
JavaScript
1,039
star
9

eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
JavaScript
1,024
star
10

turbowatch

Extremely fast file change detector and task orchestrator for Node.js.
TypeScript
938
star
11

table

Formats data into a string table.
TypeScript
897
star
12

usus

Webpage pre-rendering service. ⚑️
JavaScript
805
star
13

flow-runtime

A runtime type system for JavaScript with full Flow compatibility.
JavaScript
802
star
14

surgeon

Declarative DOM extraction expression evaluator. πŸ‘¨β€βš•οΈ
JavaScript
693
star
15

liqe

Lightweight and performant Lucene-like parser, serializer and search engine.
TypeScript
636
star
16

eslint-config-canonical

The most comprehensive ES code style guide.
JavaScript
536
star
17

write-file-webpack-plugin

Forces webpack-dev-server to write bundle files to the file system.
JavaScript
528
star
18

lightship

Abstracts readiness, liveness and startup checks and graceful shutdown of Node.js services running in Kubernetes.
TypeScript
518
star
19

xhprof.io

GUI to analyze the profiling data collected using XHProf – A Hierarchical Profiler for PHP.
PHP
429
star
20

contents

Table of contents generator.
JavaScript
416
star
21

brim

View (minimal-ui) manager for iOS 8.
JavaScript
391
star
22

global-agent

Global HTTP/HTTPS proxy agent configurable using environment variables.
TypeScript
360
star
23

youtube-player

YouTube iframe API abstraction.
JavaScript
340
star
24

react-aux

A self-eradicating component for rendering multiple elements.
JavaScript
329
star
25

http-terminator

Gracefully terminates HTTP(S) server.
TypeScript
324
star
26

isomorphic-webpack

Abstracts universal consumption of application code base using webpack.
JavaScript
291
star
27

scream

Dynamic viewport management for mobile. Manage viewport in different states of device orientation. Scale document to fit viewport. Calculate the dimensions of the "minimal" iOS 8 view relative to your viewport width.
JavaScript
289
star
28

graphql-deduplicator

A GraphQL response deduplicator. Removes duplicate entities from the GraphQL response.
JavaScript
279
star
29

create-index

Creates ES6 ./index.js file in target directories that imports and exports all sibling files and directories.
JavaScript
279
star
30

gajus.com-blog

The contents of the http://gajus.com/blog/.
JavaScript
226
star
31

wholly

jQuery plugin used to select the entire table row and column in response to mouseenter and mouseleave events. Wholly supports table layouts that utilize colspan and rowspan.
JavaScript
204
star
32

puppeteer-proxy

Proxies Puppeteer Page requests.
JavaScript
203
star
33

canonical-reducer-composition

Spec for Canonical Reducer Composition design pattern.
188
star
34

angular-swing

AngularJS directive for Swing: A swipeable cards interface. The swipe-left/swipe-right for yes/no input. As seen in apps like Jelly and Tinder, and many others.
JavaScript
183
star
35

dindent

HTML indentation library for development and testing.
PHP
177
star
36

babel-plugin-graphql-tag

Compiles GraphQL tagged template strings using graphql-tag.
JavaScript
172
star
37

eslint-plugin-canonical

ESLint rules for Canonical ruleset.
TypeScript
121
star
38

vlad

Input validation library promoting succinct syntax with extendable validators and multilingual support.
PHP
104
star
39

babel-plugin-log-deprecated

Adds a console.warn statement to the functions annotated with @deprecated tag.
JavaScript
103
star
40

redux-immutable-examples

A complete application showing use of redux-immutable.
JavaScript
103
star
41

babel-preset-es2015-webpack

Babel preset for all es2015 plugins except babel-plugin-transform-es2015-modules-commonjs.
JavaScript
97
star
42

scalpel

A CSS selector parser.
JavaScript
95
star
43

eslint-plugin-sql

SQL linting rules for ESLint.
TypeScript
93
star
44

graphql-lazyloader

GraphQL directive that adds Object-level data resolvers.
TypeScript
89
star
45

pg-formatter

A PostgreSQL SQL syntax beautifier.
TypeScript
80
star
46

orientationchangeend

The orientationchangeend event is fired when the orientation of the device has changed and the associated rotation animation has been complete.
JavaScript
78
star
47

bugger

Bugger is a collection of functions for debugging PHP code.
CSS
77
star
48

planton

Database-agnostic task scheduler.
TypeScript
77
star
49

dora

Input generation library for value resolution, data persistence, templates, CSRF and protection from XSS.
CSS
73
star
50

react-css-modules-examples

Usage examples for react-css-modules.
JavaScript
72
star
51

format-graphql

Formats GraphQL schema definition language (SDL) document.
JavaScript
71
star
52

to-string-loader

to-string loader for webpack
JavaScript
64
star
53

extract-email-address

Extracts email address from an arbitrary text input.
TypeScript
62
star
54

interdependent-interactive-histograms

This is a helper function that utilises d3.js and Crossfilter to create interdependent interactive histograms.
JavaScript
60
star
55

babel-plugin-transform-function-composition

Syntactic sugar 🍧🍨🍦 for easy to read function composition. πŸ¦„
JavaScript
58
star
56

preoom

Retrieves & observes Kubernetes Pod resource (CPU, memory) utilisation.
JavaScript
55
star
57

fuss

The Facebook SDK for PHP provides an interface to the Graph API.
PHP
53
star
58

postloader

A scaffolding tool for projects using DataLoader, Flow and PostgreSQL.
JavaScript
51
star
59

moa

MOA implements dynamically generated Active Record database abstraction.
PHP
50
star
60

extract-date

Extracts date from an arbitrary text input.
JavaScript
49
star
61

gitinfo

Gets information about a Git repository.
JavaScript
47
star
62

sister

Foundation for your emitter implementation. 202 reasons to not write your own implementation of event emitter.
JavaScript
45
star
63

react-outside-event

A higher order React component that attaches an event listener for events that occur outside of the component element.
JavaScript
44
star
64

babel-plugin-annotate-console-log

Annotates console.log call expression with information about the invocation context.
JavaScript
42
star
65

react-youtube-player

React component that encapsulates YouTube IFrame Player API and exposes player controls using the component properties.
JavaScript
40
star
66

bundle-dependencies

Generates bundledDependencies package.json value using values of the dependencies property. Updates package.json definition using the generated bundledDependencies value.
JavaScript
39
star
67

facebook-friend-rank

PHP class that can calculate who are the best user's friends. Data accuracy depends on the user activity and granted permissions.
PHP
39
star
68

waitehr

Waits for HTTP response and retries request until the expected response is received.
TypeScript
37
star
69

doll

Extended PDO with inline type hinting, deferred connection support, logging and benchmarking.
PHP
36
star
70

pie-chart

This is a helper function that utilises d3.js to create pie charts.
JavaScript
36
star
71

sguid

Signed Globally Unique Identifier (SGUID) generator.
JavaScript
34
star
72

slonik-utilities

Utilities for manipulating data in PostgreSQL database using Slonik.
TypeScript
32
star
73

prepack-loader

A webpack loader for prepack.
JavaScript
31
star
74

seeql

Real-time SQL profiler.
JavaScript
30
star
75

react-strict-prop-types

A higher order component that raises an error if component is used with an unknown property.
JavaScript
29
star
76

postgres-bridge

postgres/pg compatibility layer
TypeScript
29
star
77

crack-json

Extracts all JSON objects from an arbitrary text document.
JavaScript
29
star
78

roarr-cli

A CLI program for processing Roarr logs.
TypeScript
28
star
79

paggern

Pattern interpreter for generating random strings.
PHP
28
star
80

roarr-browser-log-writer

Roarr log writer for use in a web browser.
TypeScript
27
star
81

cluster-map

Abstracts execution of tasks in parallel using Node.js cluster.
JavaScript
27
star
82

database-types

A generic type generator for various databases.
JavaScript
26
star
83

iapetus

Prometheus metrics server.
TypeScript
25
star
84

require-new

Requires a new module object.
JavaScript
23
star
85

tmdb

The Movie Database (TMDb) SDK.
JavaScript
23
star
86

pan

Touch enabled implementation of WHATWG drag and drop mechanism.
JavaScript
23
star
87

eslint-plugin-zod

Zod linting rules for ESLint.
TypeScript
21
star
88

pragmatist

A collection of tasks to standardize builds.
JavaScript
21
star
89

pianola

A declarative function composition and evaluation engine.
JavaScript
20
star
90

approximate-now

Approximate (fast) current UNIX time.
TypeScript
20
star
91

babel-plugin-transform-export-default-name

Babel plugin that transforms default exports to named exports.
JavaScript
20
star
92

xfetch

A light-weight HTTP client for Node.js.
JavaScript
19
star
93

extract-time

Extracts time from an arbitrary text input.
JavaScript
19
star
94

override-require

Overrides Node.js module resolution logic.
JavaScript
18
star
95

fastify-webpack-hot

A Fastify plugin for serving files emitted by Webpack with Hot Module Replacement (HMR).
TypeScript
18
star
96

canonical

Canonical code style linter and formatter for JavaScript, SCSS, CSS and JSON.
JavaScript
18
star
97

babel-plugin-lodash-modularize

Babel plugin that replaces lodash library import statement to individual module imports.
JavaScript
18
star
98

semantic-url-parser

Extracts content information from known URL patterns.
TypeScript
17
star
99

extract-price

Extracts prices from an arbitrary text input.
JavaScript
17
star
100

express-tus

Express middleware for tus protocol.
JavaScript
16
star