md/src/config/theme.ts
YangFong 2d40869fc2
refactor: renderer upgrade to ts (#379)
* refactor: renderer upgrade to ts

* fix: options of katex

* fix: render of katex

* chore: update marked-katex-extension to version 5.1.2

* chore: build theme

* chore: update renderer

* feat: move build addition func

* chore: styled content

* chore: update renderer

* chore: update packages

* chore: update renderer

* fix: logic of merged

* chore: update renderer

* chore: update

* feat: add token type

* feat: add styles func

* chore: update renderer

* fix: parse table cell

* feat: horizontal table scrolling is supported

* fix: strong tag

* feat: parse strong and em label

* fix: parse list

* chore: update example docs

* chore: update

---------

Co-authored-by: Libin YANG <szuyanglb@outlook.com>
2024-09-04 13:00:42 +08:00

362 lines
7.0 KiB
TypeScript

import { toMerged } from 'es-toolkit'
import type { Theme } from '@/types'
const defaultTheme: Theme = {
base: {
'--md-primary-color': `#000000`,
'text-align': `left`,
'line-height': `1.75`,
},
block: {
// 一级标题
h1: {
'display': `table`,
'padding': `0 1em`,
'border-bottom': `2px solid var(--md-primary-color)`,
'margin': `2em auto 1em`,
'color': `var(--el-text-color-regular)`,
'font-size': `1.2em`,
'font-weight': `bold`,
'text-align': `center`,
},
// 二级标题
h2: {
'display': `table`,
'padding': `0 0.2em`,
'margin': `4em auto 2em`,
'color': `#fff`,
'background': `var(--md-primary-color)`,
'font-size': `1.2em`,
'font-weight': `bold`,
'text-align': `center`,
},
// 三级标题
h3: {
'padding-left': `8px`,
'border-left': `3px solid var(--md-primary-color)`,
'margin': `2em 8px 0.75em 0`,
'color': `var(--el-text-color-regular)`,
'font-size': `1.1em`,
'font-weight': `bold`,
'line-height': `1.2`,
},
// 四级标题
h4: {
'margin': `2em 8px 0.5em`,
'color': `var(--md-primary-color)`,
'font-size': `1em`,
'font-weight': `bold`,
},
// 段落
p: {
'margin': `1.5em 8px`,
'letter-spacing': `0.1em`,
'color': `var(--el-text-color-regular)`,
'text-align': `justify`,
},
// 引用
blockquote: {
'font-style': `normal`,
'border-left': `none`,
'padding': `1em`,
'border-radius': `8px`,
'color': `rgba(0,0,0,0.5)`,
'background': `#f7f7f7`,
'margin': `2em 8px`,
},
// 引用内容
blockquote_p: {
'display': `block`,
'font-size': `1em`,
'letter-spacing': `0.1em`,
'color': `rgb(80, 80, 80)`,
},
// 代码块
code_pre: {
'font-size': `14px`,
'overflow-x': `auto`,
'border-radius': `8px`,
'padding': `1em`,
'line-height': `1.5`,
'margin': `10px 8px`,
},
// 行内代码
code: {
'margin': 0,
'white-space': `nowrap`,
'font-family': `Menlo, Operator Mono, Consolas, Monaco, monospace`,
},
// 图片
image: {
'display': `block`,
'width': `100% !important`,
'margin': `0.1em auto 0.5em`,
'border-radius': `4px`,
},
// 有序列表
ol: {
'padding-left': `1em`,
'margin-left': `0`,
'color': `var(--el-text-color-regular)`,
},
// 无序列表
ul: {
'list-style': `circle`,
'padding-left': `1em`,
'margin-left': `0`,
'color': `var(--el-text-color-regular)`,
},
footnotes: {
'margin': `0.5em 8px`,
'font-size': `80%`,
'color': `var(--el-text-color-regular)`,
},
figure: {
margin: `1.5em 8px`,
color: `var(--el-text-color-regular)`,
},
hr: {
'border-style': `solid`,
'border-width': `1px 0 0`,
'border-color': `rgba(0,0,0,0.1)`,
'-webkit-transform-origin': `0 0`,
'-webkit-transform': `scale(1, 0.5)`,
'transform-origin': `0 0`,
'transform': `scale(1, 0.5)`,
},
},
inline: {
listitem: {
'text-indent': `-1em`,
'display': `block`,
'margin': `0.2em 8px`,
'color': `var(--el-text-color-regular)`,
},
codespan: {
'font-size': `90%`,
'color': `#d14`,
'background': `rgba(27,31,35,.05)`,
'padding': `3px 5px`,
'border-radius': `4px`,
// 'word-break': `break-all`,
},
em: {
'font-style': `italic`,
'font-size': `inherit`,
},
link: {
color: `#576b95`,
},
wx_link: {
'color': `#576b95`,
'text-decoration': `none`,
},
// 字体加粗样式
strong: {
'color': `var(--md-primary-color)`,
'font-weight': `bold`,
'font-size': `inherit`,
},
table: {
'border-collapse': `collapse`,
'text-align': `center`,
'margin': `1em 8px`,
'color': `var(--el-text-color-regular)`,
},
thead: {
'background': `rgba(0, 0, 0, 0.05)`,
'font-weight': `bold`,
'color': `var(--el-text-color-regular)`,
},
td: {
'border': `1px solid #dfdfdf`,
'padding': `0.25em 0.5em`,
'color': `#3f3f3f`,
'word-break': `keep-all`,
},
footnote: {
'font-size': `12px`,
'color': `var(--el-text-color-regular)`,
},
figcaption: {
'text-align': `center`,
'color': `#888`,
'font-size': `0.8em`,
},
},
}
const graceTheme = toMerged(defaultTheme, {
base: {
},
block: {
h1: {
'padding': `0.5em 1em`,
'border-bottom': `2px solid var(--md-primary-color)`,
'font-size': `1.4em`,
'text-shadow': `2px 2px 4px rgba(0,0,0,0.1)`,
},
h2: {
'padding': `0.3em 1em`,
'border-radius': `8px`,
'font-size': `1.3em`,
'box-shadow': `0 4px 6px rgba(0,0,0,0.1)`,
},
h3: {
'padding-left': `12px`,
'font-size': `1.2em`,
'border-left': `4px solid var(--md-primary-color)`,
'border-bottom': `1px dashed var(--md-primary-color)`,
},
h4: {
'font-size': `1.1em`,
},
p: {
},
blockquote: {
'font-style': `italic`,
'padding': `1em 1em 1em 2em`,
'border-left': `4px solid var(--md-primary-color)`,
'border-radius': `6px`,
'color': `rgba(0,0,0,0.6)`,
'background': `linear-gradient(to right, #f7f7f7, #ffffff)`,
'box-shadow': `0 4px 6px rgba(0,0,0,0.05)`,
},
blockquote_p: {
},
code_pre: {
'box-shadow': `inset 0 0 10px rgba(0,0,0,0.05)`,
},
code: {
'white-space': `pre-wrap`,
'font-family': `'Fira Code', Menlo, Operator Mono, Consolas, Monaco, monospace`,
},
image: {
'border-radius': `8px`,
'box-shadow': `0 4px 8px rgba(0,0,0,0.1)`,
},
ol: {
'padding-left': `1.5em`,
},
ul: {
'list-style': `none`,
'padding-left': `1.5em`,
},
footnotes: {
},
figure: {
},
hr: {
height: `1px`,
border: `none`,
margin: `2em 0`,
background: `linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.1), rgba(0,0,0,0))`,
},
},
inline: {
listitem: {
margin: `0.5em 8px`,
},
codespan: {
},
em: {
},
link: {
},
wx_link: {
},
strong: {
},
table: {
'border-collapse': `separate`,
'border-spacing': `0`,
'border-radius': `8px`,
'margin': `1em 8px`,
'color': `var(--el-text-color-regular)`,
'box-shadow': `0 4px 6px rgba(0,0,0,0.1)`,
'overflow': `hidden`,
},
thead: {
color: `#fff`,
},
td: {
padding: `0.5em 1em`,
},
footnote: {
color: `rgba(0,0,0,0.5)`,
},
figcaption: {
},
},
})
export const themeOptions = [
{
label: `经典`,
value: `default`,
desc: ``,
},
{
label: `优雅`,
value: `grace`,
desc: ``,
},
]
export const themeMap = {
default: defaultTheme,
grace: graceTheme,
}