Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
remark-mdx-frontmatter
Advanced tools
A remark plugin for converting frontmatter metadata into MDX exports
The remark-mdx-frontmatter package is a plugin for the remark processor that allows you to parse and transform frontmatter in MDX files. This is useful for handling metadata in your MDX content, such as titles, dates, and other custom fields.
Parsing Frontmatter
This feature allows you to parse frontmatter in MDX files. The code sample demonstrates how to use the remark-mdx-frontmatter plugin to parse frontmatter and process the MDX content.
const remark = require('remark');
const mdx = require('remark-mdx');
const frontmatter = require('remark-mdx-frontmatter');
const content = `---
title: 'Hello World'
date: '2023-10-01'
---
# Hello World`;
remark()
.use(mdx)
.use(frontmatter)
.process(content, (err, file) => {
if (err) throw err;
console.log(String(file));
});
Transforming Frontmatter
This feature allows you to transform frontmatter in MDX files. The code sample demonstrates how to use a custom transformer to manipulate the frontmatter data after it has been parsed.
const remark = require('remark');
const mdx = require('remark-mdx');
const frontmatter = require('remark-mdx-frontmatter');
const content = `---
title: 'Hello World'
date: '2023-10-01'
---
# Hello World`;
const transformer = () => (tree) => {
// Transform the frontmatter here
console.log(tree.children[0].data);
};
remark()
.use(mdx)
.use(frontmatter)
.use(transformer)
.process(content, (err, file) => {
if (err) throw err;
console.log(String(file));
});
gray-matter is a popular package for parsing frontmatter from various file types, including Markdown and MDX. It provides a simple API for extracting and manipulating frontmatter data. Unlike remark-mdx-frontmatter, gray-matter is not tied to the remark ecosystem and can be used independently.
remark-frontmatter is another plugin for the remark processor that parses frontmatter in Markdown files. It supports YAML, TOML, and other frontmatter formats. While it is similar to remark-mdx-frontmatter, it does not specifically target MDX files and lacks some of the MDX-specific features.
front-matter is a lightweight package for parsing frontmatter from strings. It is not tied to any specific file type or processing ecosystem, making it a versatile choice for various use cases. However, it does not offer the same level of integration with MDX as remark-mdx-frontmatter.
A remark plugin for converting frontmatter metadata into MDX exports
This package depends on the AST output by remark-frontmatter
npm install remark-frontmatter remark-mdx-frontmatter
This remark plugin takes frontmatter content, and outputs it as JavaScript exports. Both YAML and TOML frontmatter data are supported.
For example, given a file named example.mdx
with the following contents:
---
hello: frontmatter
---
Rest of document
The following script:
import { readFile } from 'node:fs/promises'
import { compile } from '@mdx-js/mdx'
import remarkFrontmatter from 'remark-frontmatter'
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
const { value } = await compile(await readFile('example.mdx'), {
jsx: true,
remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter]
})
console.log(value)
Roughly yields:
export const frontmatter = {
hello: 'frontmatter'
}
export default function MDXContent() {
return <p>Rest of document</p>
}
The default export is a remark plugin.
name
: The identifier name of the variable the frontmatter data is assigned to. (Default:
frontmatter
).parsers
: A mapping A mapping of node types to parsers. Each key represents a frontmatter node
type. The value is a function that accepts the frontmatter data as a string, and returns the
parsed data. By default yaml
nodes will be parsed using yaml
and toml
nodes using toml
.This project is compatible with Node.js 16 or greater.
FAQs
A remark plugin for converting frontmatter metadata into MDX exports
We found that remark-mdx-frontmatter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.