Gathering detailed insights and metrics for rehype-code-titles
Gathering detailed insights and metrics for rehype-code-titles
Gathering detailed insights and metrics for rehype-code-titles
Gathering detailed insights and metrics for rehype-code-titles
Rehype plugin for parsing code blocks and adding titles to code blocks
npm install rehype-code-titles
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (44.57%)
TypeScript (31.56%)
Shell (23.87%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
22 Stars
53 Commits
2 Forks
2 Watchers
12 Branches
1 Contributors
Updated on Feb 12, 2025
Latest Version
1.2.0
Package Id
rehype-code-titles@1.2.0
Unpacked Size
11.48 kB
Size
4.63 kB
File Count
5
NPM Version
8.19.3
Node Version
16.19.0
Published on
Feb 15, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Rehype plugin for parsing code blocks and adding titles to code blocks
I moved my blog over to using mdx-bundler
which uses xdm
under the hood to parse the markdown and MDX files. I was using remark-code-titles
prior to this move and unfortunately it no longer worked. I believe this was because of the order plugins were being applied internally for xdm
. I'd never really worked with remark
or rehype
directly before and didn't have a lot of experience with ASTs so this was a fun little project that I initially built directly into my blog before pulling it out at a plugin to ship to other developers.
Many thanks to @mottox2, @mapbox, & @wooorm for their prior work in this ecosystem it was of great help when creating this plugin.
This package is ESM only: Node 12+ is needed to use it and it must be
import
ed instead ofrequire
d.
1npm install rehype-code-titles 2 3yarn add rehype-code-titles 4 5pnpm add rehype-code-titles
This package exports no identifiers. The default export is rehypeCodeTitles
rehype().use(rehypeCodeTitles[, options])
Add support for stripping out code titles from input.
options
options.customClassName
Specify your own custom css class name to apply. Defaults to rehype-code-title
.
Note: you will have to write the CSS implementation yourself.
For example
1// some global css file 2.rehype-code-title { 3 margin-bottom: -0.6rem; 4 padding: 0.5em 1em; 5 font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', 6 'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 7 'Liberation Mono', 'Nimbus Mono L', Monaco, 'Courier New', Courier, 8 monospace; 9 10 background-color: black; 11 color: white; 12 z-index: 0; 13 14 border-top-left-radius: 0.3em; 15 border-top-right-radius: 0.3em; 16}
options.titleSeparator
Specify the title separator for rehype-code-title
. Defaults to: :
.
1// default behavior will be 2'language-typescript:lib/mdx.ts' // the title will be lib/mdx.ts 3'language-typescript:title=lib/mdx.ts' // title will be title=lib/mdx.ts 4 5// titleSeparator set to :title= 6'language-typescript:lib/mdx.ts' // Wont work! 😱. Does not match the separator 7'language-typescript:title=lib/mdx.ts' // title will be lib/mdx.ts
1## Code Example 2 3```typescript:lib/mdx.ts 4// code here 5```
1<div class="rehype-code-title">lib/mdx.ts</div> 2<pre> 3 <code class="language-typescript"> 4 <!-- HTML parse code here --> 5 </code> 6</pre>
Use this package as a rehype plugin.
1const rehype = require('rehype') 2const rehypeCodeTitles = require('rehype-code-titles') 3const rehypePrism = require('@mapbox/rehype-prism') 4 5rehype() 6 .use(rehypeCodeTitles) // should always be before rehypePrism. 7 .use(rehypePrism) 8 .process(/* some html */)
1const unified = require('unified') 2const rehypeParse = require('rehype-parse') 3const rehypeCodeTitles = require('rehype-code-titles') 4const rehypePrism = require('@mapbox/rehype-prism') 5 6unified() 7 .use(rehypeParse) 8 .use(rehypeCodeTitles) 9 .use(rehypePrism) 10 .processSync(/* some html */)
This repository makes use of @arkweid/lefthook
and will run eslint
, jest
, and prettier
against all staged files.
1git clone https://github.com/rockchalkwushock/rehype-code-titles.git 2cd rehype-code-titles 3pnpm i 4# Do cool stuff with code 5git add . 6git commit -m "feat(src): a cool new feature" 7# pre-commit hooks run: eslint, jest, and prettier 8git push
Please visit CONTRIBUTING.md
Thanks goes to these wonderful people (emoji key):
Cody Brunner 💻 📖 ⚠️ |
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 2/10 approved changesets -- score normalized to 2
Reason
9 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More