Skip to content

editor.content

方法

html2data

javascript
html2data(html: string, options?: Object<{separator: string | Function<string>, callback: Function, fieldNames: Object<{ html: string}> }>)

将 html 转换成列表(分割线作为分隔符)

示例

javascript
editor.content.html2data('html字符串')

参数

名称说明类型默认值
htmlhtml 字符串string-
options选项Object<Option>Option
Option
名称说明类型默认值
separator分隔符string Function<string>[data-block-type="divider"]
callback转换成data后,每一条数据上附加的信息Function<Object>()=>({})
fieldNames自定义节点Object<Option>{html: 'html'}

html2structure()

js
editor.content.html2structure(html: string)

将编辑器的内容解析 json

示例

js
editor.content.html2structure('内容')

参数

名称说明类型默认值
html富文本内容string-

返回值

点击查看
json5
{
    question: {
        key: '', // 仅存在于小题
        number: '', // 序号
        separator: '', // 分隔符
        content: '', // 试题内容
        index: '', // 路径,格式:1,1-1, 1-1-1;最后一段为索引,即在当前顺序,仅存在于小题
        // 选项
        optionList: [
            {
                key: '',
                number: '', // 序号
                content: '', // 选项内容
                answerFieldKey: '', // 关联的作答区key
                index: '', // 路径,格式:1,1-1, 1-1-1;最后一段为索引,即在当前顺序
            },
        ],
        // 作答区
        answerFieldList: [
            {
                key: '',
                answerList: [
                    {
                        key: '',
                        content: '',
                    },
                ], // 答案
                answerMethod: '', // 作答方式【1=选择,2=判断,3=填空,4=问答】
                index: '', // 路径,格式:1,1-1, 1-1-1;最后一段为索引,即在当前顺序
                questionKey: '', // 关联的试题 key
            },
        ],
        // 解析
        analysisList: [
            {
                key: '',
                content: '', // 解析内容
                questionKey: '', // 试题 key
                index: '', // 路径,格式:1,1-1, 1-1-1;最后一段为索引,即在当前顺序
            },
        ],
        // 小题
        children: [],
    },
    // 纯 html 结构
    html: {
        content: '', // 试题内容
        answer: '', // 答案
        analysis: '', // 解析
    },
}

clearFormat()

js
editor.content.clearFormat(html: String)

清除格式

示例

js
editor.content.clearFormat('内容')

参数

名称说明类型默认值
html内容string-

返回值

string