npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@portabletext/plugin-typography

v4.0.33

Published

Automatically transform text to typographic variants

Downloads

312,604

Readme

@portabletext/plugin-typography

Automatically transform text to typographic variants

Drop-in plugin for the Portable Text Editor to enable a wide variety of typographic transformations:

Typography Demo

Automatically handles smart undo with Backspace right after insertion:

Smart undo with Backspace

Usage

Import the TypographyPlugin React component and place it inside the EditorProvider:

import {
  defineSchema,
  EditorProvider,
  PortableTextEditable,
} from '@portabletext/editor'
import {TypographyPlugin} from '@portabletext/plugin-typography'

const schemaDefinition = defineSchema({
  // Your Schema
})

function App() {
  return (
    <EditorProvider
      initialConfig={{
        schemaDefinition,
      }}
    >
      <PortableTextEditable />
      <TypographyPlugin /> {/* <-- plugin added */}
    </EditorProvider>
  )
}

Rules Included

The plugin includes the following typographic transformation rules:

Default rules:

| Name | Conversion | | --------------------- | ------------ | | emDash | -- | | ellipsis | ... | | openingDoubleQuote | " | | closingDoubleQuote | " | | openingSingleQuote | ' | | closingSingleQuote | ' | | leftArrow | <- | | rightArrow | -> | | copyright | (c)© | | trademark | (tm) | | servicemark | (sm) | | registeredTrademark | (r)® |

Optional rules:

| Name | Conversion | | ------------------ | -------------------------------- | | oneHalf | 1/2½ | | plusMinus | +/-± | | notEqual | != | | laquo | <<« | | raquo | >>» | | multiplication | * or x between numbers → × | | superscriptTwo | ^2² | | superscriptThree | ^3³ | | oneQuarter | 1/4¼ | | threeQuarters | 3/4¾ |

Configuring Rules

The plugin supports flexible configuration through preset, enable, and disable props:

Using Presets

The preset prop provides quick configuration:

  • 'default' (default): Common typography rules enabled
  • 'all': Enable all rules
  • 'none': Start with no rules (use with enable)
// Use default rules (most common transformations)
<TypographyPlugin />

// Enable everything
<TypographyPlugin preset="all" />

// Start from scratch and enable only specific rules
<TypographyPlugin preset="none" enable={['emDash', 'ellipsis']} />

Enabling Additional Rules

Use enable to add rules beyond the preset:

// Add multiplication and plusMinus to default rules
<TypographyPlugin enable={['multiplication', 'plusMinus']} />

// Enable all rules except a few
<TypographyPlugin preset="all" disable={['emDash', 'ellipsis']} />

Disabling Rules

Use disable to remove rules from the preset:

// Use defaults but disable quote transformations
<TypographyPlugin
  disable={[
    'openingDoubleQuote',
    'closingDoubleQuote',
    'openingSingleQuote',
    'closingSingleQuote',
  ]}
/>

Combining Options

All three props work together. The order of operations is:

  1. Start with preset (default: 'default')
  2. Add rules from enable
  3. Remove rules from disable
// Start with all rules, then customize
<TypographyPlugin
  preset="all"
  disable={['multiplication']}
/>

// Start with none, enable only math symbols
<TypographyPlugin
  preset="none"
  enable={['multiplication', 'plusMinus', 'notEqual']}
/>

Controlling when Text Transformations Run

The TypographyPlugin has an optional guard prop that accepts any type of BehaviorGuard. Here, you'll have access to the current EditorSnapshot as well as information about the current rule being matched.

Because disallowing text transformations inside code is a common use case, this plugin ships a built-in createDecoratorGuard function. use that to create a guard that only allows text transformations inside certain decorators:

import {
  createDecoratorGuard,
  TypographyPlugin,
} from '@portabletext/plugin-typography'

return (
  <TypographyPlugin
    guard={createDecoratorGuard({
      decorators: ({context}) =>
        context.schema.decorators.flatMap((decorator) =>
          decorator.name === 'code' ? [] : [decorator.name],
        ),
    })}
  />
)

Using Individual Rules with InputRulePlugin

All included typographic rules are exported from the plugin. To use them in your own abstraction, import them from this from plugin and use them with the InputRulePlugin:

import {InputRulePlugin} from '@portabletext/plugin-input-rule'
import {ellipsisRule, emDashRule} from '@portabletext/plugin-typography'

return <InputRulePlugin rules={[emDashRule, ellipsisRule]} />