From b93a10dfacaa63884afaca07f876462d9a0437a5 Mon Sep 17 00:00:00 2001 From: martyanov-av Date: Mon, 29 Jan 2024 19:02:13 +0300 Subject: [PATCH 1/2] feat(note): support he-IL, es-ES, fr-FR, cs-CZ, ar-SA langs --- src/transform/plugins/notes/constants.ts | 44 +++++++++++++++++++ .../plugins/{notes.ts => notes/index.ts} | 20 ++------- src/transform/plugins/typings.ts | 2 +- 3 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 src/transform/plugins/notes/constants.ts rename src/transform/plugins/{notes.ts => notes/index.ts} (92%) diff --git a/src/transform/plugins/notes/constants.ts b/src/transform/plugins/notes/constants.ts new file mode 100644 index 00000000..b9c293bd --- /dev/null +++ b/src/transform/plugins/notes/constants.ts @@ -0,0 +1,44 @@ +export const titles: Record> = { + ru: { + info: 'Примечание', + tip: 'Совет', + alert: 'Внимание', + warning: 'Важно', + }, + en: { + info: 'Note', + tip: 'Tip', + alert: 'Alert', + warning: 'Warning', + }, + ar: { + info: 'ملاحظة', + tip: 'نصيحة', + alert: 'انتباه', + warning: 'هام', + }, + cs: { + info: 'Poznámka', + tip: 'Tip', + alert: 'Upozornění', + warning: 'Varování', + }, + fr: { + info: 'Remarque', + tip: 'Astuce', + alert: 'Alerte', + warning: 'Avertissement', + }, + es: { + info: 'Nota', + tip: 'Consejo', + alert: 'Alerta', + warning: 'Aviso', + }, + he: { + info: 'מידע', + tip: 'טיפ', + alert: 'התראה', + warning: 'אזהרה', + }, +}; diff --git a/src/transform/plugins/notes.ts b/src/transform/plugins/notes/index.ts similarity index 92% rename from src/transform/plugins/notes.ts rename to src/transform/plugins/notes/index.ts index 7f5c6ff0..71ab4dae 100644 --- a/src/transform/plugins/notes.ts +++ b/src/transform/plugins/notes/index.ts @@ -1,28 +1,14 @@ import {bold} from 'chalk'; import StateCore from 'markdown-it/lib/rules_core/state_core'; import Token from 'markdown-it/lib/token'; -import {MarkdownItPluginCb} from './typings'; +import {MarkdownItPluginCb} from '../typings'; -import {MatchTokenFunction, nestedCloseTokenIdxFactory as closeTokenFactory} from './utils'; +import {MatchTokenFunction, nestedCloseTokenIdxFactory as closeTokenFactory} from '../utils'; +import {titles} from './constants'; const ALERT_RE = /^{% note (alert|info|tip|warning)\s*(?:"(.*?)")? %}$/; const WRONG_NOTES = /^{% note (.*)%}/; -const titles: Record> = { - ru: { - info: 'Примечание', - tip: 'Совет', - alert: 'Внимание', - warning: 'Важно', - }, - en: { - info: 'Note', - tip: 'Tip', - alert: 'Alert', - warning: 'Warning', - }, -}; - function getTitle(type: string, originLang: keyof typeof titles) { let lang = originLang; diff --git a/src/transform/plugins/typings.ts b/src/transform/plugins/typings.ts index 3a22af81..157154b7 100644 --- a/src/transform/plugins/typings.ts +++ b/src/transform/plugins/typings.ts @@ -4,7 +4,7 @@ import type {MarkdownIt} from '../typings'; export interface MarkdownItPluginOpts { path: string; log: Logger; - lang: 'ru' | 'en'; + lang: 'ru' | 'en' | 'es' | 'fr' | 'cs' | 'ar' | 'he'; root: string; isLintRun: boolean; } From 521ba587499803a2ef1cfc7acb9e52eb7bc901ab Mon Sep 17 00:00:00 2001 From: martyanov-av Date: Thu, 1 Feb 2024 19:51:37 +0300 Subject: [PATCH 2/2] leave notes.ts so as not create a breaking change --- .../plugins/{notes/index.ts => notes.ts} | 50 +++++++++++++++++-- src/transform/plugins/notes/constants.ts | 44 ---------------- 2 files changed, 47 insertions(+), 47 deletions(-) rename src/transform/plugins/{notes/index.ts => notes.ts} (82%) delete mode 100644 src/transform/plugins/notes/constants.ts diff --git a/src/transform/plugins/notes/index.ts b/src/transform/plugins/notes.ts similarity index 82% rename from src/transform/plugins/notes/index.ts rename to src/transform/plugins/notes.ts index 71ab4dae..c0d46f0e 100644 --- a/src/transform/plugins/notes/index.ts +++ b/src/transform/plugins/notes.ts @@ -1,14 +1,58 @@ import {bold} from 'chalk'; import StateCore from 'markdown-it/lib/rules_core/state_core'; import Token from 'markdown-it/lib/token'; -import {MarkdownItPluginCb} from '../typings'; +import {MarkdownItPluginCb} from './typings'; -import {MatchTokenFunction, nestedCloseTokenIdxFactory as closeTokenFactory} from '../utils'; -import {titles} from './constants'; +import {MatchTokenFunction, nestedCloseTokenIdxFactory as closeTokenFactory} from './utils'; const ALERT_RE = /^{% note (alert|info|tip|warning)\s*(?:"(.*?)")? %}$/; const WRONG_NOTES = /^{% note (.*)%}/; +const titles: Record> = { + ru: { + info: 'Примечание', + tip: 'Совет', + alert: 'Внимание', + warning: 'Важно', + }, + en: { + info: 'Note', + tip: 'Tip', + alert: 'Alert', + warning: 'Warning', + }, + ar: { + info: 'ملاحظة', + tip: 'نصيحة', + alert: 'انتباه', + warning: 'هام', + }, + cs: { + info: 'Poznámka', + tip: 'Tip', + alert: 'Upozornění', + warning: 'Varování', + }, + fr: { + info: 'Remarque', + tip: 'Astuce', + alert: 'Alerte', + warning: 'Avertissement', + }, + es: { + info: 'Nota', + tip: 'Consejo', + alert: 'Alerta', + warning: 'Aviso', + }, + he: { + info: 'מידע', + tip: 'טיפ', + alert: 'התראה', + warning: 'אזהרה', + }, +}; + function getTitle(type: string, originLang: keyof typeof titles) { let lang = originLang; diff --git a/src/transform/plugins/notes/constants.ts b/src/transform/plugins/notes/constants.ts deleted file mode 100644 index b9c293bd..00000000 --- a/src/transform/plugins/notes/constants.ts +++ /dev/null @@ -1,44 +0,0 @@ -export const titles: Record> = { - ru: { - info: 'Примечание', - tip: 'Совет', - alert: 'Внимание', - warning: 'Важно', - }, - en: { - info: 'Note', - tip: 'Tip', - alert: 'Alert', - warning: 'Warning', - }, - ar: { - info: 'ملاحظة', - tip: 'نصيحة', - alert: 'انتباه', - warning: 'هام', - }, - cs: { - info: 'Poznámka', - tip: 'Tip', - alert: 'Upozornění', - warning: 'Varování', - }, - fr: { - info: 'Remarque', - tip: 'Astuce', - alert: 'Alerte', - warning: 'Avertissement', - }, - es: { - info: 'Nota', - tip: 'Consejo', - alert: 'Alerta', - warning: 'Aviso', - }, - he: { - info: 'מידע', - tip: 'טיפ', - alert: 'התראה', - warning: 'אזהרה', - }, -};