diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 576b144..65f90e1 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -9,6 +9,7 @@ import "@/styles/markdown-alert/github-base.css"; import "@/styles/markdown-alert/github-colors-dark-class.css"; import "@/styles/markdown-alert/github-colors-dark-media.css"; import "@/styles/markdown-alert/github-colors-light.css"; +import "@/styles/markdown-alert/github-i18n.css"; import type { AppProps } from "next/app"; import Head from "next/head"; import { useLanguageSync } from "@/components/LanguageSwitcher"; diff --git a/src/remark-github-alerts/index.ts b/src/remark-github-alerts/index.ts index ddcec27..81e9289 100644 --- a/src/remark-github-alerts/index.ts +++ b/src/remark-github-alerts/index.ts @@ -119,7 +119,8 @@ const remarkGithubAlerts: Plugin = ( if (!match) return; const type = match[1]?.toLowerCase() as keyof typeof icons; - const title = match[2]?.trim() || (titles[type] ?? capitalize(type)); + const customTitle = match[2]?.trim() || titles[type]; + const title = customTitle ?? capitalize(type); const icon = icons[type]; const iconDataUri = `data:image/svg+xml;utf8,${encodeSvg(icon)}`; @@ -141,7 +142,9 @@ const remarkGithubAlerts: Plugin = ( data: { hName: "p", hProperties: { - class: `${classPrefix}-title`, + class: customTitle + ? `${classPrefix}-title` + : `${classPrefix}-title ${classPrefix}-title-default`, }, }, children: [ @@ -156,10 +159,21 @@ const remarkGithubAlerts: Plugin = ( }, }, }, - { - type: "text", - value: title, - }, + customTitle + ? { + type: "text", + value: title, + } + : { + type: "text", + value: title, + data: { + hName: "span", + hProperties: { + class: `${classPrefix}-title-text`, + }, + }, + }, ], }, ...node.children, diff --git a/src/styles/markdown-alert/github-i18n.css b/src/styles/markdown-alert/github-i18n.css new file mode 100644 index 0000000..0edc0c1 --- /dev/null +++ b/src/styles/markdown-alert/github-i18n.css @@ -0,0 +1,44 @@ +html[lang="zh" i], +html:lang(zh-Hant), +html:lang(zh-HK), +html:lang(zh-TW), +html:lang(zh-MO) { + --markdown-alert-title-note: "備註"; + --markdown-alert-title-tip: "提示"; + --markdown-alert-title-important: "重要"; + --markdown-alert-title-warning: "警告"; + --markdown-alert-title-caution: "注意"; + --markdown-alert-title-text-display: none; +} + +.markdown-alert:is( + .markdown-alert-note, + .markdown-alert-tip, + .markdown-alert-important, + .markdown-alert-warning, + .markdown-alert-caution + ) + .markdown-alert-title-default + .markdown-alert-title-text { + display: var(--markdown-alert-title-text-display, inline); +} + +.markdown-alert.markdown-alert-note .markdown-alert-title-default::after { + content: var(--markdown-alert-title-note, none); +} + +.markdown-alert.markdown-alert-tip .markdown-alert-title-default::after { + content: var(--markdown-alert-title-tip, none); +} + +.markdown-alert.markdown-alert-important .markdown-alert-title-default::after { + content: var(--markdown-alert-title-important, none); +} + +.markdown-alert.markdown-alert-warning .markdown-alert-title-default::after { + content: var(--markdown-alert-title-warning, none); +} + +.markdown-alert.markdown-alert-caution .markdown-alert-title-default::after { + content: var(--markdown-alert-title-caution, none); +}