简体   繁体   English

带有子 Blot 的 Quill Wrap Blot 值

[英]Quill Wrap Blot value with a child Blot

I want to default all text to using a font-style of Arial and a font-size of 12px.我想默认所有文本使用 Arial 字体样式和 12px 字体大小。

If I set those as the default for the toolbar, the toolbar UI does not change to a color to indicate that is what you are on (For example, if I place my cursor in some text that is styled to be 15px and Geneva, the UI for the font and size picker will be blue. But if I default the UI to 15 and Geneva, then whenever i place my cursor in some text styled that way, it will just switch to it, but the UI will not have that highlight color).如果我将这些设置为工具栏的默认值,则工具栏 UI 不会更改为指示您所在的颜色(例如,如果我将光标放在一些样式为 15px 和日内瓦的文本中,则字体和大小选择器的 UI 将是蓝色的。但是如果我将 UI 默认设置为 15 和日内瓦,那么每当我将光标置于某种样式的文本中时,它就会切换到它,但 UI 不会有那个突出显示颜色)。

To get around this, I just opt to not set a default.为了解决这个问题,我只是选择不设置默认值。 Which works great, except when I am reading in some legacy values from the database.这很好用,除非我从数据库中读取一些遗留值。 These legacy values would look something like this,这些遗留值看起来像这样,

<p> This is legacy text </p>

And should be defaulted to a font-style of Arial and a size of 12px.并且应该默认为 Arial 字体样式和 12px 大小。

So, ideally, I'd like Quill to convert it into:因此,理想情况下,我希望 Quill 将其转换为:

<p>
  <span class="ql-font-arial" style="font-size: 12px;">This is legacy text.</span>
</p>

But I cannot get Quill to accept a child node when creating the blot.但是在创建印迹时,我无法让 Quill 接受子节点。 If I append a child, it gets optimized out because that child will have no content.如果我附加一个孩子,它会得到优化,因为那个孩子将没有内容。 If I add a child and return a child node, the parent node is never acknowledged by Quill and does not appear in the styling (and puts everything on the same line because it's just one giant optimized span tag now.)如果我添加一个子节点并返回一个子节点,则父节点永远不会被 Quill 确认并且不会出现在样式中(并将所有内容放在同一行上,因为它现在只是一个巨大的优化span标签。)

Is there any way to get the blot to use format itself to have a child and stick the data into the child?有没有办法让印迹使用格式本身来生孩子并将数据粘贴到孩子身上? This is what I'm using right now to capture这就是我现在用来捕捉的

tags and keep any alignment formatting they might have.标签并保留它们可能具有的任何对齐格式。 But I can't figure out how to have it default it's data to be wrapped in a child <span> tag.但我不知道如何让它默认将数据包装在子<span>标签中。

const BlockBlot = Quill.import('blots/block');

export class PBlot extends BlockBlot {
  static create(data: { alignment: string }) {
    let node: Element = document.createElement('P');
    if (data && data.alignment) {
      node.setAttribute('class', `ql-align-${data.alignment.toLowerCase()}`);
    }
    let sNode = document.createElement('SPAN');
    node.appendChild(sNode);
    //return sNode;
    return node;
  }

  static formats(node: Element) {
    return { alignment: node.getAttribute('align') || undefined };
  }
}
PBlot.tagName = 'P';
PBlot.blotName = 'block';

Try using a const BlockEmbed = Quill.import('blots/block/embed');尝试使用const BlockEmbed = Quill.import('blots/block/embed'); instead.反而。 Changing tagName to <div> might work as well.tagName更改为<div>也可能有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM