1

我正在使用 slatejs,并且我有以下 html 行, <p>Line one<br /> Line two</p>

我目前的规则br如下,

deserialize(el, next) {
    const block = BLOCK_TAGS[el.tagName.toLowerCase()];
    if (!block) return;
    return {
        kind: 'block',
        type: block,
        nodes: next(el.childNodes),
    };
},

const BLOCK_TAGS = {
  p: 'paragraph',
  li: 'list-item',
  ul: 'bulleted-list',
  ol: 'numbered-list',
  blockquote: 'quote',
  pre: 'code',
  h1: 'heading-one',
  h2: 'heading-two',
  h3: 'heading-three',
  h4: 'heading-four',
  h5: 'heading-five',
  h6: 'heading-six',
  br: 'br',
}

但这会创建一个空行,这会导致退格问题,我尝试在序列化中传递一个新块,但这给了我相同的结果。

我的反序列化规则应该是什么,以便我的文本在 slate 编辑器中呈现如下。

Line one
Line two
4

0 回答 0