Skip to content

Commit

Permalink
feat: remove strict typograph rules (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juli Ovechkina authored Sep 26, 2023
1 parent 91c8016 commit 7a8804a
Showing 1 changed file with 7 additions and 31 deletions.
38 changes: 7 additions & 31 deletions src/text-transform/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Typograf from 'typograf';

import {Lang} from '../utils/configure';

import AddRuleOptions = typograf.AddRuleOptions;

export enum TransformType {
Text = 'text',
Html = 'html',
Expand Down Expand Up @@ -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(
`(?<!<sup>\\s*)(${symbols})|(${symbols})(?!\\s*<\\/sup>)`,
'gi',
);

return text.replace(symbolsRegex, '<sup>$1</sup>');
},
htmlAttrs: false,
});
export function addTypografRules(options: AddRuleOptions[]) {
options.forEach((option) => {
Typograf.addRule(option);
});
}

function enableRules(tp: typograf.Typograf) {
const {disabled, enabled} = typografConfig;
Expand Down

0 comments on commit 7a8804a

Please sign in to comment.