In my understanding, unified
is an interface for processing content with syntax trees, and remark
is a set of plugins. That means one must use unified
and attach plugins to it. For example:
import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'
const file = await unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeSanitize)
.use(rehypeStringify)
.process('# Hello, Neptune!')
console.log(String(file))
But this page lists examples that use remark
directly. E.g.:
import {remark} from 'remark'
import remarkPresetLintConsistent from 'remark-preset-lint-consistent'
import remarkPresetLintRecommended from 'remark-preset-lint-recommended'
import {reporter} from 'vfile-reporter'
const file = await remark()
.use(remarkPresetLintConsistent)
.use(remarkPresetLintRecommended)
.process('1) Hello, _Jupiter_ and *Neptune*!')
console.error(reporter(file))
I don't understand why it can work like that. Is it that remark
is a version (or fork) of unified
that is more focused on something?
Why can remark work independently from unified?
It doesn't work independently. remark
uses unified
as dependency.
https://github.com/remarkjs/remark/blob/remark-stringify%4011.0.0/packages/remark/package.json#L43
export const remark = unified().use(remarkParse).use(remarkStringify).freeze()
https://github.com/remarkjs/remark/blob/remark-stringify%4011.0.0/packages/remark/index.js#L10
const file = await remark()
.use(remarkPresetLintConsistent)
.use(remarkPresetLintRecommended)
.process('1) Hello, _Jupiter_ and *Neptune*!')
is similar to
const file = await unified()
.use(remarkParse)
.use(remarkStringify)
.use(remarkPresetLintConsistent)
.use(remarkPresetLintRecommended)
.process('1) Hello, _Jupiter_ and *Neptune*!')
Calling remark()
is only a short-cut to configure unified
with remarkParse
and remarkStringify
.