diff --git a/doc/getting-started.md b/doc/getting-started.md index cb86c1e31..ec9a92524 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -1,227 +1,6 @@ -![remark][logo] - # Getting started -**remark** transforms markdown. -It’s an ecosystem of [plugins][]. -If you get stuck, [issues][] and [Discussions][] are good places to get help. - -It’s built on [unified][], make sure to read it and its [website][] too. - -## Contents - -* [Intro](#intro) -* [Command line](#command-line) -* [Using remark in a project](#using-remark-in-a-project) -* [Programmatic usage](#programmatic-usage) - -## Intro - -Out of the box, **remark** transforms markdown: markdown is given, reformatted, -and written: - -```md -# Alpha # -Bravo charlie **delta** __echo__. -- Foxtrot -``` - -Yields: - -```md -# Alpha - -Bravo charlie **delta** **echo**. - -* Foxtrot -``` - -But, much more can be done, [through plugins][plugins]. - -## Command line - -**remark**’s CLI is a simple way to process markdown files from the -command line. Its interface is provided by [**unified-args**][unified-args]. - -Install [`remark-cli`][cli] and dependencies (in this case a [linting -preset][preset] and [`remark-html`][html]) with [npm][]: - -```sh -npm install --global remark-cli remark-html remark-preset-lint-markdown-style-guide -``` - -`readme.md` contains: - -```md -_Hello_. -``` - -Now, to process `readme.md`, run the following: - -```sh -remark readme.md --use html --use preset-lint-markdown-style-guide -``` - -Yields: - -```txt -
Hello.
-readme.md.md - 1:1-1:8 warning Emphasis should use `*` as a marker emphasis-marker remark-lint - -⚠ 1 warning -``` - -## Using remark in a project - -In the previous example, `remark-cli` was installed globally. -That’s generally a bad idea. -Here we’re going to use the CLI to lint an npm package. - -Say we have the following `package.json`: - -```json -{ - "name": "my-package", - "version": "1.0.0", - "type": "module", - "scripts": { - "test": "node test.js" - } -} -``` - -And install `remark-cli`, `remark-html`, and -`remark-preset-lint-markdown-style-guide` into it as a dev-dependencies: - -```sh -npm install --save-dev remark-cli remark-html remark-preset-lint-markdown-style-guide -``` - -The `--save-dev` option stores the dependencies in our `package.json`: - -```diff - { - "name": "my-package", - "version": "1.0.0", - "type": "module", -+ "devDependencies": { -+ "remark-cli": "^10.0.0", -+ "remark-html": "^14.0.0", -+ "remark-preset-lint-markdown-style-guide": "^5.0.0" -+ }, - "scripts": { - "test": "node test.js" - } - } -``` - -Then, we change our `test` script to include remark, and add -configuration: - -```diff - { - "name": "my-package", - "version": "1.0.0", - "type": "module", - "devDependencies": { - "remark-cli": "^10.0.0", - "remark-html": "^14.0.0", - "remark-preset-lint-markdown-style-guide": "^5.0.0" - }, - "scripts": { -- "test": "node test.js" -+ "test": "remark . --quiet --frail && node test.js" -+ }, -+ "remarkConfig": { -+ "plugins": [ -+ "preset-lint-markdown-style-guide", -+ "html" -+ ] - } - } -``` - -Now from the command line we can run: - -```sh -npm test -``` - -This will lint all markdown files when we test the project. -[`--frail`][frail] ensures the command fails if a code-style violation -is found, and [`--quiet`][quiet] hides successful files from the report. - -## Programmatic usage - -The programmatic interface of **remark** is provided by -[**unified**][unified]. -In fact, [`remark`][api] is two plugins: [`remark-parse`][parse] and -[`remark-stringify`][stringify]. - -Install [`remark`][api] and dependencies with [npm][]: - -```sh -npm install vfile-reporter remark remark-html remark-preset-lint-markdown-style-guide -``` - -`index.js` contains: - -```js -import {reporter} from 'vfile-reporter' -import {remark} from 'remark' -import remarkPresetLintMarkdownStyleGuide from 'remark-preset-lint-markdown-style-guide' -import remarkHtml from 'remark-html' - -remark() - .use(remarkPresetLintMarkdownStyleGuide) - .use(remarkHtml) - .process('_Hello_.') - .then((file) => { - console.error(reporter(file)) - console.log(String(file)) - }) -``` - -`node index.js` yields: - -```txt - 1:1-1:8 warning Emphasis should use `*` as a marker emphasis-marker remark-lint - -⚠ 1 warning -Hello.
-``` - - - -[logo]: https://raw.githubusercontent.com/remarkjs/remark/1f338e72/logo.svg?sanitize=true - -[issues]: https://github.com/remarkjs/remark/issues - -[discussions]: https://github.com/remarkjs/remark/discussions - -[npm]: https://docs.npmjs.com/cli/install - -[api]: https://github.com/remarkjs/remark/tree/main/packages/remark - -[cli]: https://github.com/remarkjs/remark/tree/main/packages/remark-cli - -[plugins]: https://github.com/remarkjs/remark/tree/main/doc/plugins.md - -[unified]: https://github.com/unifiedjs/unified - -[website]: https://unifiedjs.com - -[unified-args]: https://github.com/unifiedjs/unified-args - -[frail]: https://github.com/unifiedjs/unified-args#--frail - -[quiet]: https://github.com/unifiedjs/unified-args#--quiet - -[parse]: https://github.com/remarkjs/remark/tree/main/packages/remark-parse - -[stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify - -[preset]: https://github.com/remarkjs/remark-lint/tree/HEAD/packages/remark-preset-lint-markdown-style-guide +See [the monorepo readme][remark] for what the remark ecosystem is and examples +of how to get started. -[html]: https://github.com/remarkjs/remark-html +[remark]: https://github.com/remarkjs/remark diff --git a/doc/plugins.md b/doc/plugins.md index e81fb9c3c..8da351614 100644 --- a/doc/plugins.md +++ b/doc/plugins.md @@ -2,33 +2,33 @@ # Plugins -**remark** is a markdown processor powered by plugins part of the [unified][] -[collective][]. +**remark** is a tool that transforms markdown with plugins. +See [the monorepo readme][remark] for info on what the remark ecosystem is. +This page lists existing plugins. ## Contents * [List of plugins](#list-of-plugins) * [List of presets](#list-of-presets) * [List of utilities](#list-of-utilities) -* [Using plugins](#using-plugins) -* [Creating plugins](#creating-plugins) +* [Use plugins](#use-plugins) +* [Create plugins](#create-plugins) ## List of plugins -See [awesome remark][awesome] for the most awesome projects in the ecosystem. +See [`awesome-remark`][awesome-remark] for the most awesome projects in the +ecosystem. More plugins can be found on GitHub tagged with the [`remark-plugin` topic][topic]. -Have a good idea for a new plugin? -See [Creating plugins][create] below. +> 👉 **Note**: some plugins don’t work with recent versions of remark due to +> changes in its underlying parser (micromark). +> Plugins that are up to date or unaffected are marked with `🟢` while plugins +> that are **currently broken** are marked with `⚠️`. -Some plugins are affected by the recent switch in the underlying parser of -remark. -Their status is encoded below as: - -* 🟢 This plugin **was not affected** or **a new version is already released** -* ⚠️ This plugin is affected: it’s **currently broken** and maintainers - have been notified +> 💡 **Tip**: remark plugins work with markdown and **rehype** plugins work with +> HTML. +> See rehype’s [List of plugins][rehype-plugins] for more plugins. The list of plugins: @@ -38,7 +38,7 @@ The list of plugins: — new syntax for abbreviations (new node type, rehype compatible) * ⚠️ [`remark-admonitions`](https://github.com/elviswolcott/remark-admonitions) — new syntax for admonitions - (**note: [`remark-directive`][d] is similar and up to date**) + (👉 **note**: [`remark-directive`][d] is similar and up to date) * ⚠️ [`remark-align`](https://github.com/zestedesavoir/zmarkdown/tree/HEAD/packages/remark-align#readme) — new syntax to align text or blocks (new node types, rehype compatible) @@ -72,17 +72,17 @@ The list of plugins: — new syntax to ignore things * ⚠️ [`remark-container`](https://github.com/zWingz/remark-container) — new syntax for containers - (**note: [`remark-directive`][d] is similar and up to date**) + (👉 **note**: [`remark-directive`][d] is similar and up to date) * ⚠️ [`remark-containers`](https://github.com/Nevenall/remark-containers) — new syntax for containers - (**note: [`remark-directive`][d] is similar and up to date**) + (👉 **note**: [`remark-directive`][d] is similar and up to date) * 🟢 [`remark-contributors`](https://github.com/remarkjs/remark-contributors) — add a table of contributors * 🟢 [`remark-copy-linked-files`](https://github.com/sergioramos/remark-copy-linked-files) — find and copy files linked files to a destination directory * ⚠️ [`remark-custom-blocks`](https://github.com/zestedesavoir/zmarkdown/tree/HEAD/packages/remark-custom-blocks#readme) — new syntax for custom blocks (new node types, rehype compatible) - (**note: [`remark-directive`][d] is similar and up to date**) + (👉 **note**: [`remark-directive`][d] is similar and up to date) * 🟢 [`remark-definition-list`](https://github.com/wataru-chocola/remark-definition-list) — support definition lists * 🟢 [`remark-defsplit`](https://github.com/remarkjs/remark-defsplit) @@ -113,7 +113,7 @@ The list of plugins: — better support for Gemoji shortcodes * ⚠️ [`remark-generic-extensions`](https://github.com/medfreeman/remark-generic-extensions) — new syntax for the CommonMark generic directive extension - (**note: [`remark-directive`][d] is similar and up to date**) + (👉 **note**: [`remark-directive`][d] is similar and up to date) * 🟢 [`remark-gfm`](https://github.com/remarkjs/remark-gfm) — support GFM (autolink literals, footnotes, strikethrough, tables, tasklists) @@ -163,6 +163,8 @@ The list of plugins: — serialize markdown as man pages (roff) * 🟢 [`remark-math`](https://github.com/remarkjs/remark-math) — new syntax for math (new node types, rehype compatible) +* 🟢 [`remark-mdx`](https://github.com/mdx-js/mdx/tree/main/packages/remark-mdx) + — support MDX (JSX, expressions, ESM) * 🟢 [`remark-message-control`](https://github.com/remarkjs/remark-message-control) — turn some or all messages on or off * 🟢 [`remark-normalize-headings`](https://github.com/remarkjs/remark-normalize-headings) @@ -206,7 +208,7 @@ The list of plugins: rehype compatible) * ⚠️ [`remark-shortcodes`](https://github.com/djm/remark-shortcodes) — new syntax for Wordpress- and Hugo-like shortcodes (new node type) - (**note: [`remark-directive`][d] is similar and up to date**) + (👉 **note**: [`remark-directive`][d] is similar and up to date) * 🟢 [`remark-simple-plantuml`](https://github.com/akebifiky/remark-simple-plantuml) — turn PlantUML code blocks to images * 🟢 [`remark-slate`](https://github.com/hanford/remark-slate) @@ -274,48 +276,56 @@ The list of plugins: ## List of presets -See [npm search][npm-preset-search] or [github search][github-preset-search] -for available and often inspirational presets. +Use [GitHub search][github-preset-search] to find available and often +inspirational presets. ## List of utilities -See [**mdast**][mdast-util] for a list of utilities for working with the syntax +See [mdast][mdast-util] for a list of utilities that work with the syntax tree. -See [`unist`][unist-util] for other utilities which work with **mdast** -nodes, too. -Finally, see [**vfile**][vfile-util] for a list of utilities working with -virtual files. +See [unist][unist-util] for other utilities which work with **mdast** and other +syntax trees too. +Finally, see [vfile][vfile-util] for a list of utilities working with virtual +files. -## Using plugins +## Use plugins To use a plugin programmatically, call the [`use()`][unified-use] function. - To use plugin with `remark-cli`, pass a [`--use` flag][unified-args-use] or specify it in a [configuration file][config-file-use]. -## Creating plugins - -Have an idea for a plugin? -Post it in [ideas][] and make it happen! +## Create plugins To create a plugin, first read up on the [concept of plugins][unified-plugins]. Then, read the [guide on “Creating a plugin with unified”][guide]. Finally, take one of existing plugins, which looks similar to what you’re about to make, and work from there. -If you get stuck, [ideas][], [issues][], and [discussions][] are good places to -get help. - -You should pick a name prefixed by `'remark-'`, such as `remark-lint`. +If you get stuck, [discussions][] is a good place to get help. +You should pick a name prefixed by `'remark-'` (such as `remark-lint`). **Do not use the `remark-` prefix** if the thing you create doesn’t work with `remark().use()`: it isn’t a “plugin” and will confuse users. If it works with mdast, use `'mdast-util-'`, if it works with any unist tree, use `unist-util-`, and if it works with virtual files, use `vfile-`. +Use default exports to expose plugins from your packages, add `remark-plugin` +keywords in `package.json`, add a `remark-plugin` topic to your repo on GitHub, +and create a pull request to add the plugin here on this page! + [logo]: https://raw.githubusercontent.com/remarkjs/remark/1f338e72/logo.svg?sanitize=true +[d]: https://github.com/remarkjs/remark-directive + +[remark]: https://github.com/remarkjs/remark + +[awesome-remark]: https://github.com/remarkjs/awesome-remark + +[topic]: https://github.com/topics/remark-plugin + +[github-preset-search]: https://github.com/topics/remark-preset + [mdast-util]: https://github.com/syntax-tree/mdast#list-of-utilities [unist-util]: https://github.com/syntax-tree/unist#unist-utilities @@ -330,26 +340,8 @@ use `unist-util-`, and if it works with virtual files, use `vfile-`. [unified-plugins]: https://github.com/unifiedjs/unified#plugin -[issues]: https://github.com/remarkjs/remark/issues - -[discussions]: https://github.com/remarkjs/remark/discussions - [guide]: https://unifiedjs.com/learn/guide/create-a-plugin/ -[npm-preset-search]: https://www.npmjs.com/search?q=remark-preset - -[github-preset-search]: https://github.com/topics/remark-preset - -[awesome]: https://github.com/remarkjs/awesome - -[ideas]: https://github.com/remarkjs/ideas - -[topic]: https://github.com/topics/remark-plugin - -[unified]: https://github.com/unifiedjs/unified - -[collective]: https://opencollective.com/unified - -[create]: #creating-plugins +[discussions]: https://github.com/remarkjs/remark/discussions -[d]: https://github.com/remarkjs/remark-directive +[rehype-plugins]: https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins diff --git a/packages/remark-cli/package.json b/packages/remark-cli/package.json index b3b3451b6..d4122972f 100644 --- a/packages/remark-cli/package.json +++ b/packages/remark-cli/package.json @@ -1,7 +1,7 @@ { "name": "remark-cli", "version": "10.0.0", - "description": "CLI to process markdown with remark", + "description": "Command line interface to inspect and change markdown files with remark", "license": "MIT", "keywords": [ "unified", diff --git a/packages/remark-cli/readme.md b/packages/remark-cli/readme.md index aa0472618..5c75b3cda 100644 --- a/packages/remark-cli/readme.md +++ b/packages/remark-cli/readme.md @@ -7,19 +7,47 @@ [![Backers][backers-badge]][collective] [![Chat][chat-badge]][chat] -Command line interface for [**remark**][remark]. - -* Interface by [`unified-args`][unified-args] -* Loads [`remark-` plugins][plugins] -* Searches for [markdown extensions][markdown-extensions] -* Ignores paths found in [`.remarkignore` files][ignore-file] -* Loads configuration from [`.remarkrc`, `.remarkrc.js` files][config-file] -* Uses configuration from [`remarkConfig` fields in `package.json` - files][config-file] +Command line interface to inspect and change markdown files with **[remark][]**. + +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [CLI](#cli) +* [Examples](#examples) + * [Example: checking and formatting markdown on the CLI](#example-checking-and-formatting-markdown-on-the-cli) + * [Example: config files (JSON, YAML, JS)](#example-config-files-json-yaml-js) +* [Compatibility](#compatibility) +* [Security](#security) +* [Contribute](#contribute) +* [Sponsor](#sponsor) +* [License](#license) + +## What is this? + +This package is a command line interface (CLI) that you can use in your terminal +or in npm scripts and the like to inspect and change markdown files. +This CLI is built around remark, which is a very popular ecosystem of plugins +that work with markdown as structured data, specifically ASTs (abstract syntax +trees). +You can choose from the 150+ plugins that already exist or make your own. + +See [the monorepo readme][remark] for info on what the remark ecosystem is. + +## When should I use this? + +You can use this package when you want to work with the markdown files in your +project from the command line. +`remark-cli` has many options and you can combine it with many plugins, so it +should be possible to do what you want. +If not, you can always use [`remark`][remark-core] itself manually in a script. ## Install -[npm][]: +This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). +In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: ```sh npm install remark-cli @@ -27,19 +55,23 @@ npm install remark-cli ## Use +Add a table of contents with [`remark-toc`][remark-toc] to `readme.md`: + ```sh -# Add a table of contents to `readme.md` -$ remark readme.md --use toc --output +remark readme.md --use remark-toc --output +``` -# Lint markdown files in the current directory -# according to the markdown style guide. -$ remark . --use preset-lint-markdown-style-guide +Lint all markdown files in the current directory according to the markdown style +guide with [`remark-preset-lint-markdown-style-guide`][markdown-style-guide]. + +```sh +remark . --use remark-preset-lint-markdown-style-guide ``` ## CLI -See [`unified-args`][unified-args], which provides the interface, for more -info on all available options. +The interface of `remark-cli` is explained as follows on its help page +(`remark --help`): ```txt Usage: remark [options] [path | glob ...] @@ -86,25 +118,190 @@ Examples: $ remark . -o ``` +More information on all these options is available at +[`unified-args`][unified-args], which does the work. +`remark-cli` is `unified-args` preconfigured to: + +* Load `remark-` plugins +* Search for markdown extensions + ([`.md`, `.markdown`, etc][markdown-extensions]) +* Ignore paths found in [`.remarkignore` files][ignore-file] +* Load configuration from + [`.remarkrc`, `.remarkrc.js`, etc files][config-file] +* Use configuration from + [`remarkConfig` fields in `package.json` files][config-file] + +## Examples + +### Example: checking and formatting markdown on the CLI + +This example checks and formats markdown with `remark-cli`. +It assumes you’re in a Node.js package. + +First, install the CLI and plugins: + +```sh +npm install remark-cli remark-toc remark-preset-lint-consistent remark-preset-lint-recommended --save-dev +``` + +Now, add an npm script in your `package.json`: + +```js + /* … */ + "scripts": { + /* … */ + "format": "remark . --output", + /* … */ + }, + /* … */ +``` + +> 💡 **Tip**: add ESLint and such in the `format` script too. + +Observe that the above change adds a `format` script, which can be run with +`npm run format`. +It runs remark on all markdown files (`.`) and rewrites them (`--output`). +Run `./node_modules/.bin/remark --help` for more info on the CLI. + +Then, add a `remarkConfig` to your `package.json` to configure remark: + +```js + /* … */ + "remarkConfig": { + "settings": { + "bullet": "*", // Use `*` for list item bullets (default) + // See
- Gatsby 🥇 - - |
-
- Vercel 🥇 + |
+ Vercel |
-+ |
+ Motif + + |
+
+ HashiCorp + + |
+
+ Gatsby + + |
+
Netlify |
+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- Holloway - + Coinbase + |
ThemeIsle |
+
+ Expo + + |
Boost Hub |
- Expo - + Holloway + |
++ | + | + | + | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -185,17 +403,15 @@ Support this effort and give back by sponsoring on [OpenCollective][collective]!
[chat]: https://github.com/remarkjs/remark/discussions
-[health]: https://github.com/remarkjs/.github
-
-[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
+[security]: https://github.com/remarkjs/.github/blob/main/security.md
-[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
+[health]: https://github.com/remarkjs/.github
-[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
+[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
-[ideas]: https://github.com/remarkjs/ideas
+[support]: https://github.com/remarkjs/.github/blob/main/support.md
-[awesome]: https://github.com/remarkjs/awesome-remark
+[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[license]: https://github.com/remarkjs/remark/blob/main/license
@@ -203,20 +419,24 @@ Support this effort and give back by sponsoring on [OpenCollective][collective]!
[npm]: https://docs.npmjs.com/cli/install
-[remark]: https://github.com/remarkjs/remark
+[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
+
+[rehype]: https://github.com/rehypejs/rehype
-[plugins]: https://github.com/remarkjs/remark/blob/main/doc/plugins.md
+[rehype-sanitize]: https://github.com/rehypejs/rehype-sanitize
+
+[remark]: https://github.com/remarkjs/remark
[markdown-extensions]: https://github.com/sindresorhus/markdown-extensions
-[config-file]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/configure.md
+[config-file]: https://github.com/unifiedjs/unified-engine/blob/main/doc/configure.md
-[ignore-file]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/ignore.md
+[ignore-file]: https://github.com/unifiedjs/unified-engine/blob/main/doc/ignore.md
[unified-args]: https://github.com/unifiedjs/unified-args#cli
-[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
+[remark-core]: ../remark
-[rehype]: https://github.com/rehypejs/rehype
+[remark-toc]: https://github.com/remarkjs/remark-toc
-[sanitize]: https://github.com/rehypejs/rehype-sanitize
+[markdown-style-guide]: https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide
diff --git a/packages/remark-cli/test.js b/packages/remark-cli/test.js
index a2e22e1e5..d12cb439b 100644
--- a/packages/remark-cli/test.js
+++ b/packages/remark-cli/test.js
@@ -16,7 +16,7 @@ test('remark-cli', (t) => {
[
'Usage: remark [options] [path | glob ...]',
'',
- ' CLI to process markdown with remark',
+ ' Command line interface to inspect and change markdown files with remark',
'',
'Options:',
'',
diff --git a/packages/remark-parse/package.json b/packages/remark-parse/package.json
index 294f6750a..717d29390 100644
--- a/packages/remark-parse/package.json
+++ b/packages/remark-parse/package.json
@@ -1,7 +1,7 @@
{
"name": "remark-parse",
"version": "10.0.0",
- "description": "remark plugin to parse markdown",
+ "description": "remark plugin to add support for parsing markdown input",
"license": "MIT",
"keywords": [
"unified",
diff --git a/packages/remark-parse/readme.md b/packages/remark-parse/readme.md
index 2f17387df..cc98e8e28 100644
--- a/packages/remark-parse/readme.md
+++ b/packages/remark-parse/readme.md
@@ -8,26 +8,93 @@
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
-[Parser][] for [**unified**][unified].
-Parses markdown to [**mdast**][mdast] syntax trees.
-Built on [`micromark`][micromark] and
-[`mdast-util-from-markdown`][from-markdown].
-Used in the [**remark** processor][remark] but can be used on its own as well.
-Can be [extended][extend] to change how markdown is parsed.
+**[remark][]** plugin to add support for parsing markdown input.
+
+## Contents
+
+* [What is this?](#what-is-this)
+* [When should I use this?](#when-should-i-use-this)
+* [Install](#install)
+* [Use](#use)
+* [API](#api)
+ * [`unified().use(remarkParse)`](#unifieduseremarkparse)
+* [Examples](#examples)
+ * [Example: support GFM and frontmatter](#example-support-gfm-and-frontmatter)
+ * [Example: turning markdown into a man page](#example-turning-markdown-into-a-man-page)
+* [Syntax](#syntax)
+* [Syntax tree](#syntax-tree)
+* [Types](#types)
+* [Compatibility](#compatibility)
+* [Security](#security)
+* [Contribute](#contribute)
+* [Sponsor](#sponsor)
+* [License](#license)
+
+## What is this?
+
+This package is a [unified][] ([remark][]) plugin that defines how to take
+markdown as input and turn it into a syntax tree.
+
+This plugin is built on [`mdast-util-from-markdown`][mdast-util-from-markdown],
+which in turn uses [`micromark`][micromark] for parsing markdown into tokens and
+turns those into [mdast][] syntax trees.
+remark focusses on making it easier to transform content by abstracting such
+internals away.
+
+**unified** is a project that transforms content with abstract syntax trees
+(ASTs).
+**remark** adds support for markdown to unified.
+**mdast** is the markdown AST that remark uses.
+**micromark** is the markdown parser we use.
+This is a remark plugin that defines how input markdown is turned into mdast.
+
+## When should I use this?
+
+This plugin adds support to unified for parsing markdown.
+You can alternatively use [`remark`][remark-core] instead, which combines
+unified, this plugin, and [`remark-stringify`][remark-stringify].
+
+You can combine this plugin with other plugins to add syntax extensions.
+Notable examples that deeply integrate with it are
+[`remark-gfm`][remark-gfm],
+[`remark-mdx`][remark-mdx],
+[`remark-frontmatter`][remark-frontmatter],
+[`remark-math`][remark-math], and
+[`remark-directive`][remark-directive].
+You can also use any other [remark plugin][plugin] after `remark-parse`.
+
+If you *just* want to turn markdown into HTML (with maybe a few extensions),
+we recommend [`micromark`][micromark] instead.
+If you want to handle syntax trees manually, you can use
+[`mdast-util-from-markdown`][mdast-util-from-markdown].
## Install
-This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
-Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
-
-[npm][]:
+This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
+In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
```sh
npm install remark-parse
```
+In Deno with [Skypack][]:
+
+```js
+import remarkParse from 'https://cdn.skypack.dev/remark-parse@10?dts'
+```
+
+In browsers with [Skypack][]:
+
+```html
+
+```
+
## Use
+Say we have the following module `example.js`:
+
```js
import {unified} from 'unified'
import remarkParse from 'remark-parse'
@@ -35,62 +102,152 @@ import remarkGfm from 'remark-gfm'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
-unified()
- .use(remarkParse)
- .use(remarkGfm)
- .use(remarkRehype)
- .use(rehypeStringify)
- .process('# Hi\n\n*Hello*, world!')
- .then((file) => {
- console.log(String(file))
- })
+main()
+
+async function main() {
+ const file = await unified()
+ .use(remarkParse)
+ .use(remarkGfm)
+ .use(remarkRehype)
+ .use(rehypeStringify)
+ .process('# Hi\n\n*Hello*, world!')
+
+ console.log(String(file))
+}
```
-Yields:
+Running that with `node example.js` yields:
```html
HiHello, world! ``` -[See **unified** for more examples »][unified] - ## API -[See **unified** for API docs »][unified] - This package exports no identifiers. The default export is `remarkParse`. ### `unified().use(remarkParse)` -Configure the `processor` to read markdown as input and process -[**mdast**][mdast] syntax trees. +Add support for parsing markdown input. +There are no options. + +## Examples + +### Example: support GFM and frontmatter + +We support CommonMark by default. +Non-standard markdown extensions can be enabled with plugins. +The following example adds support for GFM features (autolink literals, +footnotes, strikethrough, tables, tasklists) and frontmatter (YAML): + +```js +import {unified} from 'unified' +import remarkParse from 'remark-parse' +import remarkFrontmatter from 'remark-frontmatter' +import remarkGfm from 'remark-gfm' +import remarkRehype from 'remark-rehype' +import rehypeStringify from 'rehype-stringify' + +main() + +async function main() { + const file = await unified() + .use(remarkParse) + .use(remarkFrontmatter) + .use(remarkGfm) + .use(remarkRehype) + .use(rehypeStringify) + .process('---\nlayout: home\n---\n\n# Hi ~~Mars~~Venus!') + + console.log(String(file)) +} +``` + +Yields: + +```html +Hi
+```
+
+### Example: turning markdown into a man page
+
+Man pages (short for manual pages) are a way to document CLIs (example: type
+`man git-log` in your terminal).
+They use an old markup format called roff.
+There’s a remark plugin, [`remark-man`][remark-man], that can serialize as roff.
+The following example turns markdown into man pages by using unified with
+`remark-parse` and `remark-man`:
+
+```js
+import {unified} from 'unified'
+import remarkParse from 'remark-parse'
+import remarkMan from 'remark-man'
+
+main()
+
+async function main() {
+ const file = await unified()
+ .use(remarkParse)
+ .use(remarkMan)
+ .process('# titan(7) -- largest moon of saturn\n\nTitan is the largest moon…')
+
+ console.log(String(file))
+}
+```
+
+Yields:
+
+```roff
+.TH "TITAN" "7" "November 2021" "" ""
+.SH "NAME"
+\fBtitan\fR - largest moon of saturn
+.P
+Titan is the largest moon…
+```
+
+## Syntax
+
+Markdown is parsed according to CommonMark.
+Other plugins can add support for syntax extensions.
+If you’re interested in extending markdown,
+[more information is available in micromark’s readme][micromark-extend].
+
+## Syntax tree
+
+The syntax tree format used in remark is [mdast][].
-## Extending the parser
+## Types
-See [`micromark`][micromark] and [`mdast-util-from-markdown`][from-markdown].
-Then create a wrapper plugin such as [`remark-gfm`][gfm].
+This package is fully typed with [TypeScript][].
+There are no extra exported types.
+
+## Compatibility
+
+Projects maintained by the unified collective are compatible with all maintained
+versions of Node.js.
+As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
+Our projects sometimes work with older versions, but this is not guaranteed.
## Security
-As markdown is sometimes used for HTML, and improper use of HTML can open you up
-to a [cross-site scripting (XSS)][xss] attack, use of remark can also be unsafe.
-When going to HTML, use remark in combination with the [**rehype**][rehype]
-ecosystem, and use [`rehype-sanitize`][sanitize] to make the tree safe.
+As markdown can be turned into HTML and improper use of HTML can open you up to
+[cross-site scripting (XSS)][xss] attacks, use of remark can be unsafe.
+When going to HTML, you will likely combine remark with **[rehype][]**, in which
+case you should use [`rehype-sanitize`][rehype-sanitize].
Use of remark plugins could also open you up to other attacks.
Carefully assess each plugin and the risks involved in using them.
+For info on how to submit a report, see our [security policy][security].
+
## Contribute
See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
-Ideas for new plugins and tools can be posted in [`remarkjs/ideas`][ideas].
-
-A curated list of awesome remark resources can be found in [**awesome
-remark**][awesome].
+Join us in [Discussions][chat] to chat with the community and contributors.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
@@ -104,35 +261,56 @@ Support this effort and give back by sponsoring on [OpenCollective][collective]!
|
- Gatsby 🥇 - - |
-
- Vercel 🥇 + |
+ Vercel |
-+ |
+ Motif + + |
+
+ HashiCorp + + |
+
+ Gatsby + + |
+
Netlify |
+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- Holloway - + Coinbase + |
ThemeIsle |
+
+ Expo + + |
Boost Hub |
- Expo - + Holloway + |
++ | + | + | + | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -175,17 +353,15 @@ Support this effort and give back by sponsoring on [OpenCollective][collective]!
[chat]: https://github.com/remarkjs/remark/discussions
-[health]: https://github.com/remarkjs/.github
-
-[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
+[security]: https://github.com/remarkjs/.github/blob/main/security.md
-[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
+[health]: https://github.com/remarkjs/.github
-[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
+[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
-[ideas]: https://github.com/remarkjs/ideas
+[support]: https://github.com/remarkjs/.github/blob/main/support.md
-[awesome]: https://github.com/remarkjs/awesome-remark
+[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[license]: https://github.com/remarkjs/remark/blob/main/license
@@ -193,24 +369,42 @@ Support this effort and give back by sponsoring on [OpenCollective][collective]!
[npm]: https://docs.npmjs.com/cli/install
+[skypack]: https://www.skypack.dev
+
[unified]: https://github.com/unifiedjs/unified
-[remark]: https://github.com/remarkjs/remark/tree/main/packages/remark
+[remark]: https://github.com/remarkjs/remark
[mdast]: https://github.com/syntax-tree/mdast
-[parser]: https://github.com/unifiedjs/unified#processorparser
-
-[extend]: #extending-the-parser
-
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
+[typescript]: https://www.typescriptlang.org
+
[rehype]: https://github.com/rehypejs/rehype
-[sanitize]: https://github.com/rehypejs/rehype-sanitize
+[rehype-sanitize]: https://github.com/rehypejs/rehype-sanitize
+
+[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
[micromark]: https://github.com/micromark/micromark
-[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
+[micromark-extend]: https://github.com/micromark/micromark#extensions
+
+[remark-gfm]: https://github.com/remarkjs/remark-gfm
+
+[remark-mdx]: https://github.com/mdx-js/mdx/tree/main/packages/remark-mdx
+
+[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter
+
+[remark-math]: https://github.com/remarkjs/remark-math
+
+[remark-man]: https://github.com/remarkjs/remark-man
+
+[remark-directive]: https://github.com/remarkjs/remark-directive
+
+[remark-stringify]: ../remark-stringify/
+
+[remark-core]: ../remark/
-[gfm]: https://github.com/remarkjs/remark-gfm
+[plugin]: https://github.com/remarkjs/remark#plugin
diff --git a/packages/remark-stringify/package.json b/packages/remark-stringify/package.json
index b29b0df16..31eb09b4c 100644
--- a/packages/remark-stringify/package.json
+++ b/packages/remark-stringify/package.json
@@ -1,7 +1,7 @@
{
"name": "remark-stringify",
"version": "10.0.1",
- "description": "remark plugin to compile markdown",
+ "description": "remark plugin to add support for serializing markdown",
"license": "MIT",
"keywords": [
"unified",
diff --git a/packages/remark-stringify/readme.md b/packages/remark-stringify/readme.md
index 5a31b2773..641854cb8 100644
--- a/packages/remark-stringify/readme.md
+++ b/packages/remark-stringify/readme.md
@@ -4,108 +4,280 @@
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
-[![Chat][chat-badge]][chat]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
+[![Chat][chat-badge]][chat]
-[Compiler][] for [**unified**][unified].
-Serializes [**mdast**][mdast] syntax trees to markdown.
-Used in the [**remark** processor][remark] but can be used on its own as well.
-Can be [extended][extend] to change how markdown is serialized.
+**[remark][]** plugin to add support for serializing markdown.
+
+## Contents
+
+* [What is this?](#what-is-this)
+* [When should I use this?](#when-should-i-use-this)
+* [Install](#install)
+* [Use](#use)
+* [API](#api)
+ * [`unified().use(remarkStringify[, options])`](#unifieduseremarkstringify-options)
+* [Syntax](#syntax)
+* [Syntax tree](#syntax-tree)
+* [Types](#types)
+* [Security](#security)
+* [Contribute](#contribute)
+* [Sponsor](#sponsor)
+* [License](#license)
+
+## What is this?
+
+This package is a [unified][] ([remark][]) plugin that defines how to take a
+syntax tree as input and turn it into serialized markdown.
+
+This plugin is built on [`mdast-util-to-markdown`][mdast-util-to-markdown],
+which turns [mdast][] syntax trees into a string.
+remark focusses on making it easier to transform content by abstracting such
+internals away.
+
+**unified** is a project that transforms content with abstract syntax trees
+(ASTs).
+**remark** adds support for markdown to unified.
+**mdast** is the markdown AST that remark uses.
+This is a remark plugin that defines how mdast is turned into markdown.
+
+## When should I use this?
+
+This plugin adds support to unified for serializing markdown.
+You can alternatively use [`remark`][remark-core] instead, which combines
+unified, [`remark-parse`][remark-parse], and this plugin.
+
+You can combine this plugin with other plugins to add syntax extensions.
+Notable examples that deeply integrate with it are
+[`remark-gfm`][remark-gfm],
+[`remark-mdx`][remark-mdx],
+[`remark-frontmatter`][remark-frontmatter],
+[`remark-math`][remark-math], and
+[`remark-directive`][remark-directive].
+You can also use any other [remark plugin][plugin] before `remark-stringify`.
+
+If you want to handle syntax trees manually, you can use
+[`mdast-util-to-markdown`][mdast-util-to-markdown].
## Install
-This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
-Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
-
-[npm][]:
+This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
+In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
```sh
npm install remark-stringify
```
+In Deno with [Skypack][]:
+
+```js
+import remarkStringify from 'https://cdn.skypack.dev/remark-stringify@10?dts'
+```
+
+In browsers with [Skypack][]:
+
+```html
+
+```
+
## Use
+Say we have the following module `example.js`:
+
```js
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeRemark from 'rehype-remark'
import remarkStringify from 'remark-stringify'
-unified()
- .use(rehypeParse)
- .use(rehypeRemark)
- .use(remarkStringify, {
- bullet: '*',
- fence: '~',
- fences: true,
- incrementListMarker: false
- })
- .process('Hello, world!') - .then((file) => { - console.log(String(file)) - }) +main() + +async function main() { + const file = await unified() + .use(rehypeParse) + .use(rehypeRemark) + .use(remarkStringify, { + bullet: '*', + fence: '~', + fences: true, + incrementListMarker: false + }) + .process('Hello, world!') + + console.log(String(file)) +} ``` -Yields: +Running that with `node example.js` yields: ```markdown # Hello, world! ``` -[See **unified** for more examples »][unified] - ## API -[See **unified** for API docs »][unified] - This package exports no identifiers. The default export is `remarkStringify`. ### `unified().use(remarkStringify[, options])` -Configure the `processor` to serialize [**mdast**][mdast] syntax trees to -markdown. +Add support for serializing markdown. +Options are passed to [`mdast-util-to-markdown`][mdast-util-to-markdown]: +all formatting options are supported. -###### `options` +##### `options` -Options can be passed directly or passed later through -[`processor.data()`][data]. +Configuration (optional). -All the formatting options of [`mdast-util-to-markdown`][to-markdown-options] -are supported and will be passed through. +###### `options.bullet` -## Extending the compiler +Marker to use for bullets of items in unordered lists (`'*'`, `'+'`, or `'-'`, +default: `'*'`). -See [`mdast-util-to-markdown`][to-markdown]. -Then create a wrapper plugin such as [`remark-gfm`][remark-gfm]. +###### `options.bulletOther` -## Security +Marker to use in certain cases where the primary bullet doesn’t work (`'*'`, +`'+'`, or `'-'`, default: depends). +See [`mdast-util-to-markdown`][mdast-util-to-markdown] for more information. + +###### `options.bulletOrdered` + +Marker to use for bullets of items in ordered lists (`'.'` or `')'`, default: +`'.'`). + +###### `options.bulletOrderedOther` + +Marker to use in certain cases where the primary bullet for ordered items +doesn’t work (`'.'` or `')'`, default: none). +See [`mdast-util-to-markdown`][mdast-util-to-markdown] for more information. + +###### `options.closeAtx` + +Whether to add the same number of number signs (`#`) at the end of an ATX +heading as the opening sequence (`boolean`, default: `false`). + +###### `options.emphasis` + +Marker to use for emphasis (`'*'` or `'_'`, default: `'*'`). + +###### `options.fence` + +Marker to use for fenced code (``'`'`` or `'~'`, default: ``'`'``). + +###### `options.fences` + +Whether to use fenced code always (`boolean`, default: `false`). +The default is to use fenced code if there is a language defined, if the code is +empty, or if it starts or ends in blank lines. + +###### `options.incrementListMarker` + +Whether to increment the counter of ordered lists items (`boolean`, default: +`true`). + +###### `options.listItemIndent` + +How to indent the content of list items (`'one'`, `'tab'`, or `'mixed'`, +default: `'tab'`). +Either with the size of the bullet plus one space (when `'one'`), a tab stop +(`'tab'`), or depending on the item and its parent list (`'mixed'`, uses `'one'` +if the item and list are tight and `'tab'` otherwise). + +###### `options.quote` + +Marker to use for titles (`'"'` or `"'"`, default: `'"'`). + +###### `options.resourceLink` + +Whether to always use resource links (`boolean`, default: `false`). +The default is to use autolinks (`
|