From 0298911f290fe2d51572553923927bf8b0d304b1 Mon Sep 17 00:00:00 2001 From: martyanov-av Date: Wed, 3 Apr 2024 11:37:04 +0300 Subject: [PATCH 1/3] feat: add tr-TR, kk-KZ, uz-UZ, bg-BG, zh-TW, zh-CN, pt-PT, et-EE, el-GR --- src/transform/plugins/notes/constants.ts | 98 +++++++++++++++++++ .../plugins/{notes.ts => notes/index.ts} | 56 ++--------- 2 files changed, 105 insertions(+), 49 deletions(-) create mode 100644 src/transform/plugins/notes/constants.ts rename src/transform/plugins/{notes.ts => notes/index.ts} (79%) diff --git a/src/transform/plugins/notes/constants.ts b/src/transform/plugins/notes/constants.ts new file mode 100644 index 00000000..0553fd1f --- /dev/null +++ b/src/transform/plugins/notes/constants.ts @@ -0,0 +1,98 @@ +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: 'אזהרה', + }, + bg: { + "info": "Забележка", + "tip": "Съвет", + "alert": "Внимание", + "warning": "Важно" + }, + et: { + "info": "Märkus", + "tip": "Nõuanne", + "alert": "Tähelepanu", + "warning": "Tähtis" + }, + el: { + "info": "Σημείωση", + "tip": "Συμβουλή", + "alert": "Προσοχή", + "warning": "Σημαντικό" + }, + pt: { + "info": "Observação", + "tip": "Sugestão", + "alert": "Atenção", + "warning": "Importante" + }, + zh: { + "info": "备注", + "tip": "提示", + "alert": "注意", + "warning": "重要" + }, + "zh-tw": { + "info": "備注", + "tip": "提示", + "alert": "注意", + "warning": "重要" + }, + kk: { + "info": "Ескерту", + "tip": "Кеңес", + "alert": "Назар аударыңыз", + "warning": "Маңызды" + }, + tr: { + "info": "Not", + "tip": "Öneri", + "alert": "Dikkat", + "warning": "Önemli" + }, + uz: { + "info": "Sharh", + "tip": "Maslahat", + "alert": "Diqqat", + "warning": "Bu muhim" + } +}; \ No newline at end of file diff --git a/src/transform/plugins/notes.ts b/src/transform/plugins/notes/index.ts similarity index 79% rename from src/transform/plugins/notes.ts rename to src/transform/plugins/notes/index.ts index c0d46f0e..f3d5c338 100644 --- a/src/transform/plugins/notes.ts +++ b/src/transform/plugins/notes/index.ts @@ -4,63 +4,21 @@ import Token from 'markdown-it/lib/token'; import {MarkdownItPluginCb} from './typings'; 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', - }, - 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) { + +function getTitle(type: string, originLang: keyof typeof TITLES) { let lang = originLang; - if (!lang || !Object.keys(titles).includes(lang)) { + if (!lang || !Object.keys(TITLES).includes(lang)) { lang = 'ru'; } - return titles[lang][type]; + return TITLES[lang][type]; } const matchCloseToken: MatchTokenFunction = (tokens, i) => { return ( @@ -89,7 +47,7 @@ function matchWrongNotes(tokens: Token[], i: number) { const findCloseTokenIdx = closeTokenFactory('Note', matchOpenToken, matchCloseToken); // @ts-ignore -const notes: MarkdownItPluginCb = (md, {lang, notesAutotitle, path: optPath, log}) => { +const index: MarkdownItPluginCb = (md, {lang, notesAutotitle, path: optPath, log}) => { notesAutotitle = typeof notesAutotitle === 'boolean' ? notesAutotitle : true; const plugin = (state: StateCore) => { @@ -182,4 +140,4 @@ const notes: MarkdownItPluginCb = (md, {lang, notesAutotitle, path: optPath, log } }; -export = notes; +export = index; From 072dddacb14b011c6d60a4b0141fc36ab6dc9f8c Mon Sep 17 00:00:00 2001 From: martyanov-av Date: Fri, 5 Apr 2024 17:02:00 +0300 Subject: [PATCH 2/3] lint --- src/transform/plugins/notes/constants.ts | 78 +++++++++---------- src/transform/plugins/notes/index.ts | 4 +- .../markdownlint-custom-rule/yfm007.ts | 29 ++++--- 3 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/transform/plugins/notes/constants.ts b/src/transform/plugins/notes/constants.ts index 0553fd1f..fc54bc50 100644 --- a/src/transform/plugins/notes/constants.ts +++ b/src/transform/plugins/notes/constants.ts @@ -42,57 +42,57 @@ export const TITLES: Record> = { warning: 'אזהרה', }, bg: { - "info": "Забележка", - "tip": "Съвет", - "alert": "Внимание", - "warning": "Важно" + info: 'Забележка', + tip: 'Съвет', + alert: 'Внимание', + warning: 'Важно', }, et: { - "info": "Märkus", - "tip": "Nõuanne", - "alert": "Tähelepanu", - "warning": "Tähtis" + info: 'Märkus', + tip: 'Nõuanne', + alert: 'Tähelepanu', + warning: 'Tähtis', }, el: { - "info": "Σημείωση", - "tip": "Συμβουλή", - "alert": "Προσοχή", - "warning": "Σημαντικό" + info: 'Σημείωση', + tip: 'Συμβουλή', + alert: 'Προσοχή', + warning: 'Σημαντικό', }, pt: { - "info": "Observação", - "tip": "Sugestão", - "alert": "Atenção", - "warning": "Importante" + info: 'Observação', + tip: 'Sugestão', + alert: 'Atenção', + warning: 'Importante', }, zh: { - "info": "备注", - "tip": "提示", - "alert": "注意", - "warning": "重要" + info: '备注', + tip: '提示', + alert: '注意', + warning: '重要', }, - "zh-tw": { - "info": "備注", - "tip": "提示", - "alert": "注意", - "warning": "重要" + 'zh-tw': { + info: '備注', + tip: '提示', + alert: '注意', + warning: '重要', }, kk: { - "info": "Ескерту", - "tip": "Кеңес", - "alert": "Назар аударыңыз", - "warning": "Маңызды" + info: 'Ескерту', + tip: 'Кеңес', + alert: 'Назар аударыңыз', + warning: 'Маңызды', }, tr: { - "info": "Not", - "tip": "Öneri", - "alert": "Dikkat", - "warning": "Önemli" + info: 'Not', + tip: 'Öneri', + alert: 'Dikkat', + warning: 'Önemli', }, uz: { - "info": "Sharh", - "tip": "Maslahat", - "alert": "Diqqat", - "warning": "Bu muhim" - } -}; \ No newline at end of file + info: 'Sharh', + tip: 'Maslahat', + alert: 'Diqqat', + warning: 'Bu muhim', + }, +}; diff --git a/src/transform/plugins/notes/index.ts b/src/transform/plugins/notes/index.ts index f3d5c338..c960a2a8 100644 --- a/src/transform/plugins/notes/index.ts +++ b/src/transform/plugins/notes/index.ts @@ -4,13 +4,11 @@ import Token from 'markdown-it/lib/token'; import {MarkdownItPluginCb} from './typings'; import {MatchTokenFunction, nestedCloseTokenIdxFactory as closeTokenFactory} from './utils'; -import {TITLES} from "./constants"; +import {TITLES} from './constants'; const ALERT_RE = /^{% note (alert|info|tip|warning)\s*(?:"(.*?)")? %}$/; const WRONG_NOTES = /^{% note (.*)%}/; - - function getTitle(type: string, originLang: keyof typeof TITLES) { let lang = originLang; diff --git a/src/transform/yfmlint/markdownlint-custom-rule/yfm007.ts b/src/transform/yfmlint/markdownlint-custom-rule/yfm007.ts index 6af342e3..79218903 100644 --- a/src/transform/yfmlint/markdownlint-custom-rule/yfm007.ts +++ b/src/transform/yfmlint/markdownlint-custom-rule/yfm007.ts @@ -9,21 +9,20 @@ export const yfm007: Rule = { if (!config) { return; } - params.tokens.forEach( - (el) => - el.children - ?.filter((token) => { - return token.type === '__yfm_lint'; - }) - .forEach((term) => { - // @ts-expect-error bad markdownlint typings - if (term.attrGet('YFM007')) { - onError({ - lineNumber: term.lineNumber, - context: term.line, - }); - } - }), + params.tokens.forEach((el) => + el.children + ?.filter((token) => { + return token.type === '__yfm_lint'; + }) + .forEach((term) => { + // @ts-expect-error bad markdownlint typings + if (term.attrGet('YFM007')) { + onError({ + lineNumber: term.lineNumber, + context: term.line, + }); + } + }), ); }, }; From 99a3aa6f9573fdf04c16037839a656bc7a7874d6 Mon Sep 17 00:00:00 2001 From: martyanov-av Date: Fri, 5 Apr 2024 17:05:15 +0300 Subject: [PATCH 3/3] fix tests --- src/transform/plugins/notes/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transform/plugins/notes/index.ts b/src/transform/plugins/notes/index.ts index c960a2a8..975ed0ca 100644 --- a/src/transform/plugins/notes/index.ts +++ b/src/transform/plugins/notes/index.ts @@ -1,9 +1,9 @@ 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*(?:"(.*?)")? %}$/;