diff --git a/src/transform/plugins/notes/constants.ts b/src/transform/plugins/notes/constants.ts new file mode 100644 index 00000000..fc54bc50 --- /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', + }, +}; diff --git a/src/transform/plugins/notes.ts b/src/transform/plugins/notes/index.ts similarity index 78% rename from src/transform/plugins/notes.ts rename to src/transform/plugins/notes/index.ts index c0d46f0e..975ed0ca 100644 --- a/src/transform/plugins/notes.ts +++ b/src/transform/plugins/notes/index.ts @@ -1,66 +1,22 @@ 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', - }, - 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 +45,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 +138,4 @@ const notes: MarkdownItPluginCb = (md, {lang, notesAutotitle, path: optPath, log } }; -export = notes; +export = index; 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, + }); + } + }), ); }, };