Quill.js格式() - 方法做什么?

时间:2018-01-11 10:30:35

标签: typescript quill

我正在尝试为Quill.js实现一个自定义样式,它允许在文本中嵌套和(希望)重叠区域。我还不确定如何进行重叠,但嵌套似乎是可能的。

我已经完成了通常的一种印迹扩展(在打字稿中):

pdftron.PDF.Font font = pdftron.PDF.Font.Create(convertedPdf.GetSDFDoc(), pdftron.PDF.Font.StandardType1Font.e_helvetica);
for (int j = 0; j < ocrStream.pr_WoordList.Count; j++)
{
           wordRect = (Rectangle) ocrStream.pr_Rectangles[j];

           Element textBegin = elementBuilder.CreateTextBegin();
           gStateTextRun = textBegin.GetGState();
           gStateTextRun.SetTextRenderMode(GState.TextRenderingMode.e_stroke_text);
           elementWriter.WriteElement(textBegin);

           fontSize = wordRect.Height;
           double descent;

           if (hasColorImg)
           {
               descent = (-1 * font.GetDescent() / 1000d) * fontSize;
               textRun = elementBuilder.CreateTextRun((string)ocrStream.pr_WoordList[j], font, fontSize);

              //translate the word to its correct position on the pdf

              //the bottom line of the wordrectangle is the baseline for the font, that's why we need the descender
              textRun.SetTextMatrix(1, 0, 0, 1, wordRect.Left, wordRect.Bottom + descent );

现在,嵌套行为是不同的,这取决于我对format() - 方法的处理方式。它在上面写的方式将在我尝试嵌套时分割注释。如果我只返回'true',嵌套将被完全禁用。如果我离开它,未实现的嵌套按预期工作(一个在另一个内部),但只要我将let Inline = Quill.import('blots/inline'); class Comment extends Inline { static create(value: any) : Node { let node = super.create(); node.setAttribute('style', 'background-color: PeachPuff;'); node.setAttribute('data-comment-id', value); node.setAttribute('class', "comment comment" + value); return node; } static formats(domNode: Node) { return (<Element>domNode).getAttribute('data-comment-id'); } } Comment.blotName = 'comment'; Comment.className = 'comment'; Comment.tagName = 'span'; Quill.register({ 'formats/comment': Comment }); 留在那里。当我与node.setAttribute('style', 'background-color: PeachPuff;'); - 方法一起删除该行时,格式化根本不起作用。

当然,我可能不会实施formats()并将其留在那里。然而,目前我只是随机尝试,我非常不喜欢。这意味着我可能没有充分利用API,我可能会产生意想不到的副作用,以后很难发现错误。

我已经阅读了示例,搜索了文档并浏览了Quill.js和Parchment源代码,但我并不聪明。尽管到目前为止我真的很喜欢Quill,但遗憾的是缺少文档。

任何有更深入了解的人都可以向我解释一下这种方法的作用,或者Quill / Parchment如何进行格式转换为Delta转换/规范化?

注意:这个问题是关于Quill如何工作的,而不是关于如何进行重叠注释或者这样的事情是否是一个好主意。

0 个答案:

没有答案