Typographer

Typographer is a plugin for the editor that automatically transforms text symbols, replacing straight quotes with typographic ones, converting (c) into ©, and enhancing text readability.

Code

<!DOCTYPE html>
<html>
    <head>
        <title>Redactor</title>
        <meta charset="utf-8">

        <!-- css -->
        <link rel="stylesheet" href="/your-folder/redactor.css" />
    </head>
    <body>
        <!-- element -->
        <textarea id="entry">...</textarea>

        <!-- js -->
        <script src="/your-folder/redactor.js"></script>
        <script src="/your-folder/plugins/typographer/typographer.js"></script>

        <!-- call -->
        <script>
        Redactor('#entry', {
            plugins: ['typographer']
        });
        </script>
    </body>
</html>

Usage

You can replace the plugin rules with your own like this:


Redactor('#entry', {
    plugins: ['typographer'],
    typographer: {
        rules: [
            { pattern: /(\d+) ohm/g, replacement: (_, d) => `${d}Ω` }, // ohmSymbol
            { pattern: /(\d+) micro/g, replacement: (_, d) => `${d}µ` }, // microSymbol
        ]
    }
});

You can add your own rules for the plugin like this:


Redactor('#entry', {
    plugins: ['typographer'],
    typographer: {
        addRules: [
            { pattern: /1\/6/g, replacement: '⅙' }, // oneSixth
            { pattern: /5\/6/g, replacement: '⅚' }, // fiveSixths
            { pattern: /1\/8/g, replacement: '⅛' }, // oneEighth
            { pattern: /3\/8/g, replacement: '⅜' }, // threeEighths
            { pattern: /5\/8/g, replacement: '⅝' }, // fiveEighths
            { pattern: /7\/8/g, replacement: '⅞' }, // sevenEighths
        ]
    }
});

Typographer Replacements

Here's a list of all the default rules:

Pattern Replacement Description
--Replaces double hyphen with an em dash
...Replaces three dots with an ellipsis
(^|\s)"“TextReplaces straight double quotes at the beginning of a word with an opening curly quote
"(\s|$)Text”Replaces straight double quotes at the end of a word with a closing curly quote
(^|\s)'‘TextReplaces straight single quotes at the beginning of a word with an opening curly quote
'(\s|$)Text’Replaces straight single quotes at the end of a word with a closing curly quote
<-Replaces '<-' with a left arrow
->Replaces '->' with a right arrow
(c)©Replaces '(c)' with the copyright symbol
(r)®Replaces '(r)' with the registered trademark symbol
(tm)Replaces '(tm)' with the trademark symbol
(sm)Replaces '(sm)' with the service mark symbol
1/2½Replaces '1/2' with the fraction ½
1/4¼Replaces '1/4' with the fraction ¼
3/4¾Replaces '3/4' with the fraction ¾
1/3Replaces '1/3' with the fraction ⅓
2/3Replaces '2/3' with the fraction ⅔
1/5Replaces '1/5' with the fraction ⅕
2/5Replaces '2/5' with the fraction ⅖
3/5Replaces '3/5' with the fraction ⅗
4/5Replaces '4/5' with the fraction ⅘
+/-±Replaces '+/-' with the plus-minus symbol
!=Replaces '!=' with the not equal symbol
~= or ≃Replaces '~=' or '≃' with the approximately equal symbol
<=Replaces '<=' with the less than or equal symbol
>=Replaces '>=' with the greater than or equal symbol
<<«Replaces '<<' with a left angle quote (guillemets)
>>»Replaces '>>' with a right angle quote (guillemets)
2*22×2Replaces '*' or 'x' between digits with the multiplication symbol
^2²Replaces '^2' with superscript ²
^3³Replaces '^3' with superscript ³
^4Replaces '^4' with superscript ⁴
^5Replaces '^5' with superscript ⁵
^6Replaces '^6' with superscript ⁶
^7Replaces '^7' with superscript ⁷
^8Replaces '^8' with superscript ⁸
^9Replaces '^9' with superscript ⁹
^10¹⁰Replaces '^10' with superscript ¹⁰
15 deg15°Replaces 'deg' after a number with the degree symbol