All Projects → Widdershin → Markdown Doctest

Widdershin / Markdown Doctest

Licence: mit
Test all the code in your markdown docs!

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Markdown Doctest

Parse Comments
Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.
Stars: ✭ 53 (-64.43%)
Mutual labels:  docs, markdown
Foliant
Comprehensive markdown-based documentation toolkit
Stars: ✭ 74 (-50.34%)
Mutual labels:  docs, markdown
Docsify Tabs
A docsify.js plugin for rendering tabbed content from markdown
Stars: ✭ 65 (-56.38%)
Mutual labels:  docs, markdown
Markdown Magic
💫 Automatically format markdown files, sync external docs/src code & make better docs
Stars: ✭ 551 (+269.8%)
Mutual labels:  docs, markdown
Catalog
Create living style guides using Markdown or React
Stars: ✭ 1,527 (+924.83%)
Mutual labels:  docs, markdown
Bluedoc
An open-source document management tool for enterprise self host.
Stars: ✭ 579 (+288.59%)
Mutual labels:  docs, markdown
Docnado
Rapid documentation tool that will blow you away...
Stars: ✭ 67 (-55.03%)
Mutual labels:  docs, markdown
Readme
👋 - The documentation for being an Artsy Engineer
Stars: ✭ 380 (+155.03%)
Mutual labels:  docs, markdown
Goreadme
Generate readme file from Go doc. Now available with Github actions!
Stars: ✭ 113 (-24.16%)
Mutual labels:  docs, markdown
Docs Cn
OpenTelemetry Markdown中文文档: 接入使用、技术标准、RFC、SDK等. 中文网站:https://ot.md
Stars: ✭ 109 (-26.85%)
Mutual labels:  docs, markdown
Verb
HEADS UP! Verb is going though a major transition, we've completely refactored everything from the ground up. If you're interested, please see the dev branch.
Stars: ✭ 442 (+196.64%)
Mutual labels:  docs, markdown
Docs
Official repository containing all docs & guides of OVH Group
Stars: ✭ 126 (-15.44%)
Mutual labels:  docs, markdown
Mdx Docs
📝 Document and develop React components with MDX and Next.js
Stars: ✭ 412 (+176.51%)
Mutual labels:  docs, markdown
Vuesence Book
Minimalistic Vue.js based documentation system component
Stars: ✭ 48 (-67.79%)
Mutual labels:  docs, markdown
Assemble
Community
Stars: ✭ 3,995 (+2581.21%)
Mutual labels:  docs, markdown
Funbook Old
I have a dream, to be a novelist someday.
Stars: ✭ 65 (-56.38%)
Mutual labels:  docs, markdown
Docma
A powerful tool to easily generate beautiful HTML documentation from JavaScript (JSDoc), Markdown and HTML files.
Stars: ✭ 287 (+92.62%)
Mutual labels:  docs, markdown
Docsify
🃏 A magical documentation site generator.
Stars: ✭ 19,310 (+12859.73%)
Mutual labels:  docs, markdown
Live Doc
💫 Convert markdown to live React demos
Stars: ✭ 97 (-34.9%)
Mutual labels:  docs, markdown
Graphql Markdown
The easiest way to document your GraphQL schema.
Stars: ✭ 114 (-23.49%)
Mutual labels:  docs, markdown

npm version Build Status Greenkeeper badge


markdown-doctest

Test all the code in your markdown docs!

Why on earth?

As an open source developer, there are few things more embarrassing than a user opening an issue to inform you that your README example is broken! With markdown-doctest, you can rest easy knowing that your example code is actually runnable.

Installation

Just npm install markdown-doctest and run markdown-doctest. It will run all of the Javascript code examples tucked away in your markdown, and let you know if any blow up.

Okay, how do I use it?

Let's try it on this repo!

var a = 5;

var b = 10;

console.log(a + c);

There's a problem with that example. markdown-doctest finds it for us:

$ markdown-doctest
x..

Failed - README.md:32:17
evalmachine.<anonymous>:7
console.log(a + c);
                ^

ReferenceError: c is not defined

Awesome! No excuse for broken documentation ever again, right? 😉

We can also run specific files or folders by running markdown-doctest with a glob, like markdown-doctest docs/**/*.md. By default markdown-doctest will recursively run all the .md or .markdown files starting with the current directory, with the exception of the node_modules directory.

Note: markdown-doctest doesn't actually attempt to provide any guarantee that your code worked, only that it didn't explode in a horrible fashion. If you would like to use markdown-doctest for actually testing the correctness of your code, you can add some asserts to your examples.

markdown-doctest is not a replacement for your test suite. It's designed to run with your CI build and give you peace of mind that all of your examples are at least vaguely runnable.

So how do I write those examples?

In your markdown files, anything inside of code blocks with 'js' or 'es6' will be run. E.g:

```js
console.log("Yay, tests in my docs");
```

```es6
const a = 5;
console.log({a, foo: 'test'});
```

I have a code example I don't want tested!

You can tell markdown-doctest to skip examples by adding <!-- skip-example --> before the example. E.g:

<!-- skip-example -->
```js
// not a runnable example

var foo = download(...);
```

How do requires work? And other setup logic?

You can require any needed modules or example helpers in .markdown-doctest-setup.js. E.g:

// .markdown-doctest-setup.js
module.exports = {
  require: {
    Rx: require('rx')
  },

  globals: {
    $: require('jquery')
  }
}

Anything exported under require will then be used by any examples that require that key. You must explicitly configure all of the dependencies used in your examples.

Anything exported under globals will be available globally across all examples.

You can also specify a regexRequire section to handle anything more complex than an exact string match!

// .markdown-doctest-setup.js
module.exports = {
  require: {
    Rx: require('rx')
  },

  regexRequire: {
    'rx/(.*)': function (fullPath, matchedModuleName) {
      return require('./dist/' + matchedModuleName);
    }
  }
}

Do I have to enable es6 support?

Nope, ES6 support is on by default. You can disable babel support in your .markdown-doctest-setup.js file. This will speed things up drastically:

//.markdown-doctest-setup.js
module.exports = {
  babel: false
}

What if I have global state that needs to be reset after my examples run?

//.markdown-doctest-setup.js
module.exports = {
  beforeEach: function () {
    // reset your awesome global state
  }
}

You can specify a function to be run before each example in your .markdown-doctest-setup.js.

What if I want to remove custom syntax from examples before processing?

//.markdown-doctest-setup.js
module.exports = {
  transformCode(code) {
    // Remove ... from code syntax
    return code.replace(/\.\.\./g, "");
  }
}

Who uses markdown-doctest?

All of these projects either run markdown-doctest with npm test or as part of their CI process:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].