Files
outline/app/editor/extensions/SmartText.ts

54 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Extension from "@shared/editor/lib/Extension";
import { InputRule } from "@shared/editor/lib/InputRule";
const rightArrow = new InputRule(/->$/, "→");
// Note that the suppression of pipe here prevents conflict with table creation rule.
const emdash = new InputRule(/(?:^|[^\|])(--\s)$/, "— ");
const oneHalf = new InputRule(/(?:^|\s)(1\/2)$/, "½");
const threeQuarters = new InputRule(/(?:^|\s)(3\/4)$/, "¾");
const copyright = new InputRule(/\(c\)$/, "©️");
const registered = new InputRule(/\(r\)$/, "®️");
const trademarked = new InputRule(/\(tm\)$/, "™️");
const ellipsis = new InputRule(/\.\.\.$/, "…");
// Double quotes
const openDoubleQuote = new InputRule(
/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,
"“"
);
const closeDoubleQuote = new InputRule(/^(?!.*`)[\s\S]*(")$/, "”");
// Single quotes
const openSingleQuote = new InputRule(
/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,
"‘"
);
const closeSingleQuote = new InputRule(/^(?!.*`)[\s\S]*(')$/, "’");
export default class SmartText extends Extension {
get name() {
return "smart_text";
}
inputRules() {
if (this.options.userPreferences?.enableSmartText ?? true) {
return [
rightArrow,
emdash,
oneHalf,
threeQuarters,
copyright,
registered,
trademarked,
ellipsis,
openDoubleQuote,
closeDoubleQuote,
openSingleQuote,
closeSingleQuote,
];
}
return [];
}
}