├── .yarnrc ├── LICENSE ├── README.md ├── index.js ├── package.json └── yarn.lock /.yarnrc: -------------------------------------------------------------------------------- 1 | save-prefix "" 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 ZEIT, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Remark Capitalize 2 | 3 | Transform all markdown titles with [title.sh](https://github.com/zeit/title) 4 | 5 | ## Getting started 6 | 7 | ``` 8 | npm install --save remark-capitalize 9 | ``` 10 | 11 | ### Usage with MDX 12 | 13 | [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: 14 | 15 | ```js 16 | const remarkCapitalize = require('remark-capitalize') 17 | // part of webpack.config.js 18 | { 19 | test: /\.mdx$/, 20 | use: [ 21 | defaultLoaders.babel, 22 | { 23 | loader: '@compositor/markdown-loader', 24 | options: { 25 | plugins: [remarkCapitalize] 26 | } 27 | } 28 | ] 29 | } 30 | ``` 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const title = require('title') 2 | const visit = require('unist-util-visit') 3 | 4 | module.exports = () => (tree, file) => { 5 | visit(tree, 'heading', node => { 6 | visit(node, 'text', textNode => { 7 | const text = textNode.value ? textNode.value.trim() : '' 8 | textNode.value = title(text) 9 | }) 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "remark-capitalize", 3 | "version": "1.1.0", 4 | "files": [ 5 | "index.js" 6 | ], 7 | "dependencies": { 8 | "title": "3.3.1", 9 | "unist-util-visit": "1.3.1" 10 | }, 11 | "repository": "zeit/remark-capitalize" 12 | } 13 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | ansi-styles@^3.1.0: 6 | version "3.2.1" 7 | resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" 8 | dependencies: 9 | color-convert "^1.9.0" 10 | 11 | arch@^2.1.0: 12 | version "2.1.1" 13 | resolved "https://registry.yarnpkg.com/arch/-/arch-2.1.1.tgz#8f5c2731aa35a30929221bb0640eed65175ec84e" 14 | 15 | arg@1.0.0: 16 | version "1.0.0" 17 | resolved "https://registry.yarnpkg.com/arg/-/arg-1.0.0.tgz#444d885a4e25b121640b55155ef7cd03975d6050" 18 | 19 | chalk@2.3.0: 20 | version "2.3.0" 21 | resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba" 22 | dependencies: 23 | ansi-styles "^3.1.0" 24 | escape-string-regexp "^1.0.5" 25 | supports-color "^4.0.0" 26 | 27 | clipboardy@1.2.2: 28 | version "1.2.2" 29 | resolved "https://registry.yarnpkg.com/clipboardy/-/clipboardy-1.2.2.tgz#2ce320b9ed9be1514f79878b53ff9765420903e2" 30 | dependencies: 31 | arch "^2.1.0" 32 | execa "^0.8.0" 33 | 34 | color-convert@^1.9.0: 35 | version "1.9.2" 36 | resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.2.tgz#49881b8fba67df12a96bdf3f56c0aab9e7913147" 37 | dependencies: 38 | color-name "1.1.1" 39 | 40 | color-name@1.1.1: 41 | version "1.1.1" 42 | resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.1.tgz#4b1415304cf50028ea81643643bd82ea05803689" 43 | 44 | cross-spawn@^5.0.1: 45 | version "5.1.0" 46 | resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" 47 | dependencies: 48 | lru-cache "^4.0.1" 49 | shebang-command "^1.2.0" 50 | which "^1.2.9" 51 | 52 | escape-string-regexp@^1.0.5: 53 | version "1.0.5" 54 | resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" 55 | 56 | execa@^0.8.0: 57 | version "0.8.0" 58 | resolved "https://registry.yarnpkg.com/execa/-/execa-0.8.0.tgz#d8d76bbc1b55217ed190fd6dd49d3c774ecfc8da" 59 | dependencies: 60 | cross-spawn "^5.0.1" 61 | get-stream "^3.0.0" 62 | is-stream "^1.1.0" 63 | npm-run-path "^2.0.0" 64 | p-finally "^1.0.0" 65 | signal-exit "^3.0.0" 66 | strip-eof "^1.0.0" 67 | 68 | get-stream@^3.0.0: 69 | version "3.0.0" 70 | resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" 71 | 72 | has-flag@^2.0.0: 73 | version "2.0.0" 74 | resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51" 75 | 76 | is-stream@^1.1.0: 77 | version "1.1.0" 78 | resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" 79 | 80 | isexe@^2.0.0: 81 | version "2.0.0" 82 | resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" 83 | 84 | lru-cache@^4.0.1: 85 | version "4.1.3" 86 | resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.3.tgz#a1175cf3496dfc8436c156c334b4955992bce69c" 87 | dependencies: 88 | pseudomap "^1.0.2" 89 | yallist "^2.1.2" 90 | 91 | npm-run-path@^2.0.0: 92 | version "2.0.2" 93 | resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f" 94 | dependencies: 95 | path-key "^2.0.0" 96 | 97 | p-finally@^1.0.0: 98 | version "1.0.0" 99 | resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" 100 | 101 | path-key@^2.0.0: 102 | version "2.0.1" 103 | resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" 104 | 105 | pseudomap@^1.0.2: 106 | version "1.0.2" 107 | resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" 108 | 109 | shebang-command@^1.2.0: 110 | version "1.2.0" 111 | resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" 112 | dependencies: 113 | shebang-regex "^1.0.0" 114 | 115 | shebang-regex@^1.0.0: 116 | version "1.0.0" 117 | resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" 118 | 119 | signal-exit@^3.0.0: 120 | version "3.0.2" 121 | resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" 122 | 123 | strip-eof@^1.0.0: 124 | version "1.0.0" 125 | resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" 126 | 127 | supports-color@^4.0.0: 128 | version "4.5.0" 129 | resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b" 130 | dependencies: 131 | has-flag "^2.0.0" 132 | 133 | title@3.3.1: 134 | version "3.3.1" 135 | resolved "https://registry.yarnpkg.com/title/-/title-3.3.1.tgz#b3e2a8795a231ac6e5fc49aaf8190c8a5160ec52" 136 | dependencies: 137 | arg "1.0.0" 138 | chalk "2.3.0" 139 | clipboardy "1.2.2" 140 | titleize "1.0.0" 141 | 142 | titleize@1.0.0: 143 | version "1.0.0" 144 | resolved "https://registry.yarnpkg.com/titleize/-/titleize-1.0.0.tgz#7d350722061830ba6617631e0cfd3ea08398d95a" 145 | 146 | unist-util-is@^2.1.1: 147 | version "2.1.2" 148 | resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-2.1.2.tgz#1193fa8f2bfbbb82150633f3a8d2eb9a1c1d55db" 149 | 150 | unist-util-visit@1.3.1: 151 | version "1.3.1" 152 | resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-1.3.1.tgz#c019ac9337a62486be58531bc27e7499ae7d55c7" 153 | dependencies: 154 | unist-util-is "^2.1.1" 155 | 156 | which@^1.2.9: 157 | version "1.3.1" 158 | resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" 159 | dependencies: 160 | isexe "^2.0.0" 161 | 162 | yallist@^2.1.2: 163 | version "2.1.2" 164 | resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" 165 | --------------------------------------------------------------------------------