微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CKEditor 5-如何在自定义标签中包装每个文本节点

如何解决CKEditor 5-如何在自定义标签中包装每个文本节点

标题中一样,如何以最简单的方式在ckeditor 5中将所有文本(始终)包装在自定义标签中?

我正在创建自定义属性元素,作为基本样式插件的扩展,但是此元素在dataDowncast上没有属性(用于架构规范需求)。可以,但是在使用方法“ setData”的表插件中,它仅返回带有文本节点的表单元格:

结构.... <td><p><customElement>text</customElement></p></td>,但是当我将此结构设置为数据时,会获取文本

function createViewTableCellElement(
  tableSlot,tableAttributes,insertPosition,conversionApi,options
) {
  const asWidget = options && options.asWidget;
  const cellElementName = getCellElementName(tableSlot,tableAttributes);

  const cellElement = asWidget
    ? toWidgetEditable(
        conversionApi.writer.createEditableElement(cellElementName),conversionApi.writer
      )
    : conversionApi.writer.createContainerElement(cellElementName);

  if (asWidget) {
    setHighlightHandling(
      cellElement,conversionApi.writer,(element,descriptor,writer) =>
        writer.addClass(normalizetoArray(descriptor.classes),element),writer) =>
        writer.removeClass(normalizetoArray(descriptor.classes),element)
    );
  }

  const tableCell = tableSlot.cell;

  const firstChild = tableCell.getChild(0);
  const isSingleParagraph =
    tableCell.childCount === 1 && firstChild.name === "paragraph";

  conversionApi.writer.insert(insertPosition,cellElement);

  conversionApi.mapper.bindElements(tableCell,cellElement);

  // Additional requirement for data pipeline to have backward compatible data tables.
  if (!asWidget && !hasAnyAttribute(firstChild) && isSingleParagraph) {
    const innerParagraph = tableCell.getChild(0);

    conversionApi.consumable.consume(innerParagraph,"insert");

    conversionApi.mapper.bindElements(innerParagraph,cellElement);
  }
}

link to the source file

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。