Skip to content

Section

SectionSpec 定义了文档中的段落区块,是内容组织的核心单元。它支持标准的段落组织形式和完全自定义的区块结构,为文档提供了灵活的布局能力。

类型定义

ts
import type { CommonProps, CustomBlockElement } from './common';
import type { ParagraphSpec } from './paragraph';

export type StandardSectionSpec = {
  paragraphs?: ParagraphSpec[];
};

export type SectionSpec = (StandardSectionSpec | CustomBlockElement) & CommonProps;

类型说明

StandardSectionSpec

标准段落区块,用于组织常规的文档内容:

属性类型必填描述
paragraphsParagraphSpec[]段落列表,可以包含不同类型的段落

CustomBlockElement

自定义区块,用于扩展特殊的展示需求:

属性类型必填描述
customTypestring自定义区块的类型标识
stylesCSSProperties区块的 CSS 样式
classNamestring区块的 CSS 类名
keystring自定义标识
[key: string]unknown其他自定义属性

使用示例

标准段落区块

ts
const standardSection: SectionSpec = {
  paragraphs: [
    {
      type: 'heading1',
      phrases: [
        {
          type: 'text',
          value: '数据概览',
        },
      ],
    },
    {
      type: 'normal',
      phrases: [
        {
          type: 'text',
          value: '本报告将从以下几个维度分析数据:',
        },
      ],
    },
    {
      type: 'bullets',
      isOrder: false,
      bullets: [
        {
          type: 'bullet-item',
          phrases: [
            {
              type: 'text',
              value: '用户增长趋势',
            },
          ],
        },
        {
          type: 'bullet-item',
          phrases: [
            {
              type: 'text',
              value: '地域分布情况',
            },
          ],
        },
      ],
    },
  ],
};

最佳实践

  1. 内容组织

    • 使用 StandardSectionSpec 组织常规文本内容
    • 通过 paragraphs 数组合理安排段落顺序
    • 保持段落层级的清晰和一致
  2. 样式管理

    • 使用 styles 定义区块级样式
    • 通过 className 实现主题定制
    • 注意样式的作用域,避免样式污染