文章 content 字段格式说明

总览

文章的content主要由三部分组成,其中“block”是baklib编辑器的“区块”内容,包括“paragraph”(段落)、"header"(标题)等类型,同时也是最主要的内容。下面从数据结构、字段说明两方面详细说明。

content 数据结构

// content的框架
"content":{
    "time": 1301090400,   
    "block": [],     
    "verison": "2.22.2" 
}

字段说明

字段 字段类型 说明
    content JSON 文章内容
        time Integer 内容更新的时间戳(Javascript 格式)
        blocks Array[JSON] 对应编辑器中显示的区块
        verison String 编辑器版本,当前值 2.22.2

下面分别对block字段的几种类型做详细介绍。

标题类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "header"
        "data": {
            "text": "产品介绍",
            "level": 1
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 header
            data JSON 区块数据
                text String 文本
                level Integer 1~6, 分别代表 HTML 的 h1 ~ h6 标签

段落类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "paragraph",
        "data": {
            "text": "这是一段很长的描述文字",
            "alignment": "left"
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 paragraph
            data JSON 区块数据
                text String 段落文字
                alignment String 对齐方式:align-left, align-center, align-right 分别表示左对齐、居中对齐、右对齐

列表类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "list",
        "data": {
            "style": "ordered",
            "items": [
                "第一个列表项",
                "第二个列表项"
            ]
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 list
            data JSON 区块数据
                style String 排序方式分为无序(unordered)、有序(ordered),默认为有序列表
                items Array[String] 列表内容

代码类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "code",
        "data": {
            "code": "Math.abs(-1)"
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 code
            data JSON 区块数据
                code String 代码内容

分割线 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "delimiter",
        "data": {}
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 delimiter
            data JSON 区块数据,固定值 {}

复选框列表类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "checklist",
        "data": {
            "items":[
                {
                    "text":"购买机票",
                    "checked": true
                },
                {
                    "text":"预定酒店",
                    "checked": false
                }
            ]
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 checklist
            data JSON 区块数据
                items Array[JSON] 列表数据
                    text String 列表文字
                    checked Boolean 是否选中

图片类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "qiniuImage",
        "data": {
            "url": "https://doc.example.com/product.jpg",
            "caption": "产品说明书",
            "withBorder": false,
            "withBackground": false,
            "stretched": false,
            "isHistoryImage": false
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 qiniuImage
            data JSON 区块数据
                url String 图片地址
                caption String 图片说明
                withBorder Boolean 是否加边框
                withBackground Boolean 是否为背景
                stretched Boolean 是否拉伸
                isHistoryImage Boolean 是否为历史图片

引用类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "quote",
        "data": {
            "text": "上善若水,水善利萬物而不爭,處眾人之所惡,故幾為道。",
            "caption":"老子",
            "alignment": "left" 
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值quote
            data JSON 区块数据
                text String 引用文字
                caption String 出处
                alignment String 对齐方式,有左对齐(left)和居中对齐(center)两种。

视频类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "embed",//嵌入视频
        "data": {
            "service": "qq" ,  // 代表腾讯视频
            "source" : "https://v.qq.com/x/cover/mzc002009sxs960/u0044wq064b.html",
            "embed": "//v.qq.com/txp/iframe/player.html?vid=u0044wq064b" ,
            "width" : "100%",
            "height": "100%" ,
            "caption": "来自腾讯视频"
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 embed
            data JSON 区块数据
                service String 视频来源,支持腾讯(qq)、爱奇艺(iqiyi)、优酷(youku)、bilibili、西瓜视频(ixigua)。
                source String 视频源链接
                embed String 视频嵌入链接
                width String 视频宽度百分比
                height String 视频高度百分比
                caption String 视频说明

markdown 类 block

数据结构

"blocks": [
    {
        "id": "XXX",
        "type": "markdown",
        "data": {
            "text": "一段 **markdown** 文字"
        }
    }
]

字段说明

字段 字段类型 说明
            id String 区块ID, 字符串随机, blocks 数组内必须唯一
            type String 格式类型,固定值 markdown
            data JSON 区块数据
                text String markdown文本
2022-11-21
0 0