remark plugin to show frontmatter as a table.
- What is this?
- When should I use this?
- Install
- Use
- API
- Bugs
- Authoring
- HTML
- CSS
- Syntax
- Types
- Compatibility
- Security
- Related
- Contribute
- Notice
- License
This plugin shows metadata authored with YAML frontmatter to readers.
This behavior is specific to github.com that only work in files, not in comments.
This plugin is part of a monorepo rehype-github.
See its readme for more info.
You can use this plugin when you want to match how github.com works or when you want to build similar pipelines.
This plugin is useful if you want to display metadata when the markdown is rendered as a preview and not as a finished, production, page. If you don’t use the metadata but something else might.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install remark-github-yaml-metadataIn Deno with esm.sh:
import remarkGithubYamlMetadata from 'https://esm.sh/remark-github-yaml-metadata@1'In browsers with esm.sh:
<script type="module">
import remarkGithubYamlMetadata from 'https://esm.sh/remark-github-yaml-metadata@1?bundle'
</script>Say our module example.js looks as follows:
import remarkFrontmatter from 'remark-frontmatter'
import remarkGithubYamlMetadata from 'remark-github-yaml-metadata'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'
const file = await unified()
.use(remarkParse)
.use(remarkFrontmatter)
.use(remarkGithubYamlMetadata)
.use(remarkRehype)
.use(rehypeStringify)
.process('---\na: b\n---\n\n# hi')
console.log(String(file))…now running node example.js yields:
<table><thead><tr><th>a</th></tr></thead><tbody><tr><td><div>b</div></td></tr></tbody></table>
<h1>hi</h1>This package exports the identifiers
defaultCreateErrorMessage and
defaultParseOptions.
The default export is
remarkGithubYamlMetadata.
Create rich content to display an error message to the user,
like GitHub does
(CreateErrorMessage).
Options defining how to parse YAML like GitHub
(ParseOptions).
GH mostly follows YAML 1.1, with some non-standard behavior.
Plugin to show frontmatter as a table.
options(Options) — configuration
Create rich content to display an error message to the user (TypeScript type).
info(ErrorInfo) — info on what went wrong
One or more hast nodes (ElementContent or
Array<ElementContent>).
Info on what went wrong (TypeScript type).
👉 Note:
pointandsummaryare defined by default, but not when turningparseOptions.prettyErrors: false.
message(string) — human readable parse error (fromyaml)point(Pointorundefined) — where the error happened in the original filesummary(stringorundefined) — summary with a pointer showing a codeframe of where the error happenedyaml(string) — original input YAML
Configuration (TypeScript type).
👉 Note: it is recommended to turn
allowArrayAtRootandallowPrimitiveAtRooton, so that arrays and primitives can be shown too. You should also probably passparseOptions: {}, as that uses modern defaults ofyaml: YAML 1.2 (which for example does not turnnointofalse) and not allowing duplicate keys in objects.
allowArrayAtRoot(boolean, default:false) — whether to allow arrays at the top of the YAMLallowPrimitiveAtRoot(boolean, default:false) — whether to allow primitives (and dates) at the top of the YAMLcreateErrorMessage(CreateErrorMessage, default:defaultCreateErrorMessage) — options defining how to show YAML errorsparseOptions(ParseOptions, default:defaultParseOptions) — options defining how to parse YAML
Options defining how to parse YAML (TypeScript type).
type ParseOptions = import('yaml').ParseOptions &
import('yaml').DocumentOptions &
import('yaml').SchemaOptions &
import('yaml').ToJSOptionsGitHub only allows top-level objects, not arrays or primitives. Instead, it parses that as if it was markdown. Which I believe to be unexpected and a bug.
GitHub also mostly follows the rules of YAML 1.1,
which treats no as false,
which I consider a bug.
See § Authoring in
micromark-extension-frontmatter
for more info.
The markup for frontmatter is something like the following, for an object with one field:
<table>
<thead>
<tr><th>a</th></tr>
</thead>
<tbody>
<tr><td><div>b</div></td></tr>
</tbody>
</table>The following CSS is needed to make frontmatter tables look like GitHub.
/* Default dark */
:root {
--color-border-default: #30363d;
--color-border-muted: #21262d;
--color-canvas-default: #0d1117;
}
table {
display: block;
max-width: 100%;
overflow: auto;
width: 100%;
width: max-content;
}
tr {
background-color: var(--color-canvas-default);
border-top: 1px solid var(--color-border-muted);
}
td, th {
border: 1px solid var(--color-border-default);
padding: 6px 13px;
}
th {
font-weight: 600;
}See § Syntax in
micromark-extension-frontmatter
for more info.
This package is fully typed with TypeScript.
It exports the additional types
CreateErrorMessage,
ErrorInfo,
Options,
and
ParseOptions.
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 16+. Our projects sometimes work with older versions, but this is not guaranteed.
This plugin works with unified version 6+ and remark version 7+.
This package is safe.
remark-gfm— support GFM in remarkremark-frontmatter— support frontmatter syntax in remark
See contributing.md in rehypejs/.github for ways to get
started.
See support.md for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
This project is not affiliated with GitHub.