• 简体中文
  • 样式指南

    用主题让 Markdown 融入应用的颜色、字体和间距,再通过容器样式安排布局。要改变组件或交互,使用 Slot 插件。

    跟随应用主题

    import { Fluxdown } from 'fluxdown';
    
    type ArticleProps = {
      text: string;
      dark: boolean;
    };
    
    export function Article({ text, dark }: ArticleProps) {
      return <Fluxdown text={text} theme={dark ? 'dark' : 'light'} />;
    }

    默认主题为 light,不会自动跟随系统。将应用已有的主题状态传进来即可。

    调整字体与颜色

    以预设为起点,只覆盖需要改变的 token:

    <Fluxdown
      text={text}
      theme={[
        'light',
        {
          tokens: {
            colors: { accent: '#567153' },
            typography: { fontSans: 'Inter, sans-serif' },
            heading: { h1: { fontSize: '2rem' } },
            paragraph: { marginBottom: '1rem' },
          },
        },
      ]}
    />

    可以调整颜色、字体、标题、段落间距、代码高亮、圆角和间距。直接传入 token 对象时,以 light 为基础;使用 ['dark', overrides] 则以深色主题为基础。

    容器的宽度和布局可以通过 className 或 style 设置:

    <Fluxdown
      style={{
        maxWidth: '72ch',
        marginInline: 'auto',
      }}
      text={text}
    />

    完整主题选项见自定义配置。公式、脚注与其他 Markdown 语法开关见 build。

    样式字段

    以下字段均位于 theme.tokens,支持局部覆盖。颜色、尺寸和间距接受 CSS 值;行高和字重也可以使用数字。未设置的字段沿用所选主题。完整类型 ThemeTokens 可从 fluxdown 导入。

    颜色

    字段含义
    colors.fg正文文字颜色。
    colors.fgMuted引用、辅助信息等次要文字颜色。
    colors.bg内容背景色。
    colors.border默认边框颜色。
    colors.accent链接与交互控件的强调色。
    colors.accentHover链接与交互控件悬停时的颜色。
    colors.surfaceMuted代码工具栏、表头与行内代码的背景色。
    colors.surfaceSubtle代码块、引用块和表格交替行的浅背景色。
    colors.borderEmphasis引用块等需要强调的边框颜色。

    字体与排版

    字段含义
    typography.fontSans正文与标题字体。
    typography.fontMono代码与公式占位内容的等宽字体。
    typography.fontSmoothing字体平滑方式,如 antialiased。
    typography.fontSize.xs最小字号,用于代码工具栏等辅助信息。
    typography.fontSize.sm小字号,用于表格、脚注等内容。
    typography.fontSize.md正文字号。
    typography.lineHeight.sm紧凑行高。
    typography.lineHeight.md正文等常规内容的行高。
    typography.lineHeight.lg宽松行高。
    typography.fontWeight.normal正文字重。
    typography.fontWeight.medium表头、工具栏等内容的中等字重。
    typography.fontWeight.bold加粗文字的字重。

    标题

    将 <level> 换成 h1、h2、h3、h4、h5 或 h6,各级标题可以独立设置。

    字段含义
    heading.<level>.fontSize该级标题的字号。
    heading.<level>.fontWeight该级标题的字重。
    heading.<level>.lineHeight该级标题的行高。
    heading.<level>.marginTop标题上方间距。
    heading.<level>.marginBottom标题下方间距。

    段落与代码块

    字段含义
    paragraph.marginTop段落上方间距。
    paragraph.marginBottom段落下方间距。
    code.fontSize代码块字号。
    code.lineHeight代码块行高。

    行内代码

    字段含义
    inlineCode.paddingBlock上下内边距。
    inlineCode.paddingInline左右内边距。
    inlineCode.border完整边框声明,如 1px solid #ddd。
    inlineCode.borderRadius圆角大小。
    inlineCode.background背景颜色或背景声明。
    inlineCode.fontFamily字体。
    inlineCode.fontSize字号。
    inlineCode.whiteSpace空白保留与换行方式,如 break-spaces。

    分隔线

    字段含义
    divider.height分隔线高度。
    divider.marginBlock上下外边距。
    divider.marginInline左右外边距。
    divider.border完整边框声明。
    divider.borderBlockEnd下边框声明。
    divider.background背景颜色或背景声明。

    脚注

    字段含义
    footnotes.marginTop脚注区域上方外边距。
    footnotes.paddingTop脚注区域上方内边距。
    footnotes.borderTop脚注区域的上边框。
    footnotes.color脚注文字颜色。
    footnotes.fontSize脚注字号。

    代码高亮

    字段含义
    syntax.comment注释颜色。
    syntax.keyword关键字颜色。
    syntax.string字符串颜色。
    syntax.number数字字面量颜色。
    syntax.function函数名颜色。
    syntax.variable变量名颜色。
    syntax.punctuation标点与分隔符颜色。
    syntax.inserteddiff 新增内容颜色。
    syntax.deleteddiff 删除内容颜色。

    圆角与间距

    字段含义
    radius.sm小圆角,用于行内代码和小控件。
    radius.md中等圆角,用于引用块等容器。
    radius.lg大圆角,用于代码块、图片和表格。
    spacing.xs最小间距。
    spacing.sm小间距。
    spacing.md中等间距。
    spacing.lg大间距。
    spacing.xl最大间距,用于列表缩进、分隔线等。