Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove strict typograph rules #583

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading