mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
8c716b173a
* chore: Update editor generics * fix: Address PR review on editor generics - Restore null-guard on Link click handler so anchors aren't inert when no onClickLink is provided - Mark onClickLink optional in LinkOptions and openLink command to match runtime - Remove dead `collapsed` option from HeadingOptions - Make ToggleBlock dictionary optional and restore optional-chained access for server-side schema instantiation Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import Extension from "@shared/editor/lib/Extension";
|
||
import { InputRule } from "@shared/editor/lib/InputRule";
|
||
import type { UserPreferences } from "@shared/types";
|
||
|
||
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]*(')$/, "’");
|
||
|
||
/**
|
||
* Options for the SmartText extension.
|
||
*/
|
||
type SmartTextOptions = {
|
||
/** Display preferences for the logged in user, if any. */
|
||
userPreferences?: UserPreferences | null;
|
||
};
|
||
|
||
export default class SmartText extends Extension<SmartTextOptions> {
|
||
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 [];
|
||
}
|
||
}
|