
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
rehype-mdx-title
Advanced tools
A rehype MDX plugin for exposing the page title
npm install rehype-mdx-title
This plugins exports the page title as a string. If multiple matching headers are found, othe
highest ranking header is used. If multiple headers are found with the same rank, the first one in
the document is used. The header is converted to a string using
mdast-util-to-string
For example, given a file named example.mdx
with the following contents:
# The [answer](https://www.google.com/search?q=What+is+answer+to+life+the+universe+and+everything) to _life_, the `universe`, and **everything**
{title} is 42
The following script:
import { readFile } from 'node:fs/promises'
import { compile } from '@mdx-js/mdx'
import rehypeMdxTitle from 'rehype-mdx-title'
const { value } = await compile(await readFile('example.mdx'), {
jsx: true,
rehypePlugins: [rehypeMdxTitle]
})
console.log(value)
Roughly yields:
export const title = 'The answer to life, the universe, and everything'
export default function MDXContent() {
return (
<>
<h1>
{'The '}
<a href="https://www.google.com/search?q=What+is+answer+to+life+the+universe+and+everything">
answer
</a>
{' to '}
<em>life</em>
{', the '}
<code>universe</code>
{', and '}
<strong>everything</strong>
</h1>
<p>
{title}
{' is 42'}
</p>
</>
)
}
Use rehype-raw
if you wish to use custom <h1>
headers.
This only works if the MDX format
option is set to 'md'
. Beware this also changes the MDX
component output.
name
(string
) — The name of the variable to export the title as. (default: 'title'
)maxRank
(number
) — The maximum heading rank to consider. (default: '1'
)This project is compatible with Node.js 16 or greater.
FAQs
A rehype MDX plugin for exposing the page title
We found that rehype-mdx-title demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.