Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for options #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,49 @@ Transform all markdown titles with [title.sh](https://github.com/zeit/title)
npm install --save remark-capitalize
```

### Usage with Markdown

Works as a remark plugin with either [unified](https://www.npmjs.com/package/unified) or [remark](https://www.npmjs.com/package/remark).

#### Without options

```js
import unified from 'unified'
import markdown from 'remark-parse'
import capitalize from 'remark-capitalize'
import html from 'remark-html'

const processedContent = await unified()
.use(markdown)
.use(capitalize)
.use(html)
.process(content)
```

#### With Options

```js
import unified from 'unified'
import markdown from 'remark-parse'
import capitalize from 'remark-capitalize'
import html from 'remark-html'

// Your casing will be enforced for these words
const options = ['iPhone', 'facebook', 'sOmeRanDOMcaSEDtiTle']

const processedContent = await unified()
.use(markdown)
.use(capitalize, { options })
.use(html)
.process(content)
```

### Usage with MDX

[mdx](https://github.com/mdx-js/mdx) uses remark to transform an MDX document into JSX tags. It has support for passing plugins through the loader options:

#### Without options

```js
const remarkCapitalize = require('remark-capitalize')
// part of webpack.config.js
Expand All @@ -28,3 +67,27 @@ const remarkCapitalize = require('remark-capitalize')
]
}
```

#### With Options

```js
// Your casing will be enforced for these words
const options = ['iPhone', 'facebook', 'sOmeRanDOMcaSEDtiTle']

const remarkCapitalize = require('remark-capitalize')
// part of webpack.config.js
{
test: /\.mdx$/,
use: [
defaultLoaders.babel,
{
loader: '@compositor/markdown-loader',
options: {
plugins: [
[remarkCapitalize, {options}]
]
}
}
]
}
```
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const title = require('title')
const visit = require('unist-util-visit')

module.exports = () => (tree, file) => {
module.exports = ({ options } = { options: [] }) => (tree, file) => {
visit(tree, 'heading', node => {
visit(node, 'text', textNode => {
const text = textNode.value ? textNode.value.trim() : ''
textNode.value = title(text)
textNode.value = title(text, { special: options })
})
})
}