Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.61 KB

File metadata and controls

55 lines (42 loc) · 1.61 KB

@fujocoded/remark-capitalize-titles

A version of this Vercel plugin that transforms all markdown titles with title.sh and also accepts options.

It also allows capitalizing the title prop of a given list of Astro components. Astro frontmatter title fields are capitalized by default.

By default it uses FujoCoded's own list of capitalization exceptions.

Sample usage

In astro.config.js:

import remarkCapitalizeTitles from "@fujocoded/remark-capitalize-titles";

export default defineConfig({
  // ...
  integrations: [
    mdx({
      remarkPlugins: [
        [
          remarkCapitalizeTitles,
          {
            // Capitalize Astro frontmatter `title` fields.
            // Defaults to true.
            frontmatterTitle: true,
            // Any component whose title prop should be capitalized
            componentNames: ["Callout", "ScenarioCallout"],
          },
        ],
      ],
    }),
  ],
});

Title-casing a string directly

To title-case a string outside a Markdown tree, use the exported capitalizeTitle function:

import { capitalizeTitle } from "@fujocoded/remark-capitalize-titles";

capitalizeTitle("merging with github via npm");
// => "Merging with GitHub via NPM"

// Override the capitalization exceptions:
capitalizeTitle("my title", { special: ["MyPersonalNitpick"] });

The default exception list is exported as DEFAULT_CAPITALIZATIONS, and overridden if special is passed as a parameter. If the change is meant to be additive, then import DEFAULT_CAPITALIZATIONS and extend it instead.