Skip to content

Commit

Permalink
Merge pull request #240 from tearingItUp786/feature/optional-config
Browse files Browse the repository at this point in the history
Update rehype-code-titles to take in options
  • Loading branch information
rockchalkwushock committed Feb 14, 2023
2 parents f93a740 + f67e39e commit 1429210
Show file tree
Hide file tree
Showing 5 changed files with 1,131 additions and 2,665 deletions.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,52 @@ pnpm add rehype-code-titles

## API

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

```css
// some global css file
.rehype-code-title {
margin-bottom: -0.6rem;
padding: 0.5em 1em;
font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console',
'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono',
'Liberation Mono', 'Nimbus Mono L', Monaco, 'Courier New', Courier,
monospace;

background-color: black;
color: white;
z-index: 0;

border-top-left-radius: 0.3em;
border-top-right-radius: 0.3em;
}
```
rehype().use(rehypeCodeTitles)

##### `options.titleSeparator`

Specify the title separator for `rehype-code-title`. Defaults to: `:`.

```tsx
// default behavior will be
'language-typescript:lib/mdx.ts' // the title will be lib/mdx.ts
'language-typescript:title=lib/mdx.ts' // title will be title=lib/mdx.ts

// titleSeparator set to :title=
'language-typescript:lib/mdx.ts' // Wont work! 😱. Does not match the separator
'language-typescript:title=lib/mdx.ts' // title will be lib/mdx.ts
```

### Input
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,20 @@
"test:ci": "node --experimental-vm-modules node_modules/jest/bin/jest.js --ci --passWithNoTests --runInBand",
"test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --maxWorkers=25% --onlyChanged --watch",
"type-check": "tsc --noEmit"
"type-check": "tsc --noEmit",
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
"unist-util-visit": "~4.1.0"
"hast": "~1.0.0",
"unist-util-visit": "~4.1.2"
},
"devDependencies": {
"@arkweid/lefthook": "~0.7.7",
"@babel/core": "~7.18.0",
"@babel/plugin-transform-modules-commonjs": "~7.18.0",
"@rockchalkwushock/eslint-config": "~1.0.7",
"@types/dedent": "~0.7.0",
"@types/hast": "~2.3.4",
"@types/jest": "~27.5.1",
"@types/node": "~17.0.35",
"@types/unist": "~2.0.6",
Expand Down

0 comments on commit 1429210

Please sign in to comment.