From 7a8804a2f093c9d01e36cb34730d986a1cd648ef Mon Sep 17 00:00:00 2001 From: Juli Ovechkina Date: Tue, 26 Sep 2023 15:51:38 +0100 Subject: [PATCH] feat: remove strict typograph rules (#583) --- src/text-transform/utils.ts | 38 +++++++------------------------------ 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/src/text-transform/utils.ts b/src/text-transform/utils.ts index 1925a1ef6..e75e872b6 100644 --- a/src/text-transform/utils.ts +++ b/src/text-transform/utils.ts @@ -4,6 +4,8 @@ import Typograf from 'typograf'; import {Lang} from '../utils/configure'; +import AddRuleOptions = typograf.AddRuleOptions; + export enum TransformType { Text = 'text', Html = 'html', @@ -40,37 +42,11 @@ export const sanitizeStripOptions: sanitize.IOptions = { allowedAttributes: {}, }; -Typograf.addRule({ - name: 'common/html/sup', - queue: 'end', - /* TODO mange with it: in typograf types AddRuleOptions.handler takes only one param: text. - But in cloud-www was used this notation with 3 params */ - //@ts-ignore - handler: function (text, settings, context) { - const {prefs: {htmlEntity: {type = ''} = {}} = {}} = context; - - let symbols; - switch (type) { - case 'digit': - symbols = '®|©|™'; - break; - case 'name': - symbols = '®|©|™'; - break; - default: - symbols = '®|©|™'; - break; - } - - const symbolsRegex = new RegExp( - `(?\\s*)(${symbols})|(${symbols})(?!\\s*<\\/sup>)`, - 'gi', - ); - - return text.replace(symbolsRegex, '$1'); - }, - htmlAttrs: false, -}); +export function addTypografRules(options: AddRuleOptions[]) { + options.forEach((option) => { + Typograf.addRule(option); + }); +} function enableRules(tp: typograf.Typograf) { const {disabled, enabled} = typografConfig;