Skip to content

Commit

Permalink
feat: add tr-TR, kk-KZ, uz-UZ, bg-BG, zh-TW, zh-CN, pt-PT, et-EE, el-…
Browse files Browse the repository at this point in the history
…GR langs (#396)

* feat: add tr-TR, kk-KZ, uz-UZ, bg-BG, zh-TW, zh-CN, pt-PT, et-EE, el-GR

* lint

* fix tests
  • Loading branch information
martyanovandrey authored Apr 5, 2024
1 parent 529c8b0 commit c3c5a42
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 67 deletions.
98 changes: 98 additions & 0 deletions src/transform/plugins/notes/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
export const TITLES: Record<string, Record<string, string>> = {
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',
},
};
Original file line number Diff line number Diff line change
@@ -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<string, Record<string, string>> = {
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 (
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -182,4 +138,4 @@ const notes: MarkdownItPluginCb = (md, {lang, notesAutotitle, path: optPath, log
}
};

export = notes;
export = index;
29 changes: 14 additions & 15 deletions src/transform/yfmlint/markdownlint-custom-rule/yfm007.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}),
);
},
};

0 comments on commit c3c5a42

Please sign in to comment.