@scrider/formatter 1.10.8 → 1.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +120 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +120 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3548,7 +3548,25 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3548
3548
|
i += tableLines.length - 1;
|
|
3549
3549
|
continue;
|
|
3550
3550
|
}
|
|
3551
|
-
const { tag, isList, listType, indent, isCodeBlock } = getBlockInfo(
|
|
3551
|
+
const { tag, isList, listType, indent, isCodeBlock, isBlockquote } = getBlockInfo(
|
|
3552
|
+
line.attributes
|
|
3553
|
+
);
|
|
3554
|
+
if (isBlockquote) {
|
|
3555
|
+
html += closeAllLists(listStack, pretty);
|
|
3556
|
+
listStack = [];
|
|
3557
|
+
counters = [];
|
|
3558
|
+
const quoteLines = collectBlockquoteLines(lines, i);
|
|
3559
|
+
html += renderBlockquote(
|
|
3560
|
+
quoteLines,
|
|
3561
|
+
embedRenderers,
|
|
3562
|
+
pretty,
|
|
3563
|
+
blockHandlers,
|
|
3564
|
+
options,
|
|
3565
|
+
resolvedDocumentPresentation
|
|
3566
|
+
);
|
|
3567
|
+
i += quoteLines.length - 1;
|
|
3568
|
+
continue;
|
|
3569
|
+
}
|
|
3552
3570
|
if (isCodeBlock) {
|
|
3553
3571
|
html += closeAllLists(listStack, pretty);
|
|
3554
3572
|
listStack = [];
|
|
@@ -3577,13 +3595,7 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3577
3595
|
continue;
|
|
3578
3596
|
}
|
|
3579
3597
|
if (isList) {
|
|
3580
|
-
html += handleListOpen(
|
|
3581
|
-
listStack,
|
|
3582
|
-
listType,
|
|
3583
|
-
indent,
|
|
3584
|
-
pretty,
|
|
3585
|
-
resolvedDocumentPresentation
|
|
3586
|
-
);
|
|
3598
|
+
html += handleListOpen(listStack, listType, indent, pretty, resolvedDocumentPresentation);
|
|
3587
3599
|
if (hierarchicalNumbers && listType === "ordered") {
|
|
3588
3600
|
if (counters.length > indent + 1) {
|
|
3589
3601
|
counters = counters.slice(0, indent + 1);
|
|
@@ -3816,24 +3828,90 @@ function renderTableRow(cells, maxCol, cellTag, embedRenderers, pretty, depth, b
|
|
|
3816
3828
|
}
|
|
3817
3829
|
function getBlockInfo(attributes) {
|
|
3818
3830
|
if (!attributes) {
|
|
3819
|
-
return {
|
|
3831
|
+
return {
|
|
3832
|
+
tag: "p",
|
|
3833
|
+
isList: false,
|
|
3834
|
+
isCodeBlock: false,
|
|
3835
|
+
isBlockquote: false,
|
|
3836
|
+
listType: void 0,
|
|
3837
|
+
indent: 0
|
|
3838
|
+
};
|
|
3820
3839
|
}
|
|
3821
3840
|
const indent = typeof attributes.indent === "number" ? attributes.indent : 0;
|
|
3822
3841
|
if (attributes["code-block"]) {
|
|
3823
|
-
return {
|
|
3842
|
+
return {
|
|
3843
|
+
tag: "pre",
|
|
3844
|
+
isList: false,
|
|
3845
|
+
isCodeBlock: true,
|
|
3846
|
+
isBlockquote: false,
|
|
3847
|
+
listType: void 0,
|
|
3848
|
+
indent
|
|
3849
|
+
};
|
|
3824
3850
|
}
|
|
3825
3851
|
if (attributes.list) {
|
|
3826
3852
|
const listVal = attributes.list;
|
|
3827
3853
|
const listType = typeof listVal === "string" ? listVal : "bullet";
|
|
3828
|
-
return { tag: "li", isList: true, isCodeBlock: false, listType, indent };
|
|
3854
|
+
return { tag: "li", isList: true, isCodeBlock: false, isBlockquote: false, listType, indent };
|
|
3855
|
+
}
|
|
3856
|
+
if (attributes.blockquote) {
|
|
3857
|
+
return {
|
|
3858
|
+
tag: "blockquote",
|
|
3859
|
+
isList: false,
|
|
3860
|
+
isCodeBlock: false,
|
|
3861
|
+
isBlockquote: true,
|
|
3862
|
+
listType: void 0,
|
|
3863
|
+
indent
|
|
3864
|
+
};
|
|
3829
3865
|
}
|
|
3830
3866
|
for (const [format, tagOrFn] of Object.entries(BLOCK_FORMAT_TAGS)) {
|
|
3831
3867
|
if (format in attributes && format !== "list" && format !== "code-block") {
|
|
3832
3868
|
const tag = typeof tagOrFn === "function" ? tagOrFn(attributes[format]) : tagOrFn;
|
|
3833
|
-
return {
|
|
3869
|
+
return {
|
|
3870
|
+
tag,
|
|
3871
|
+
isList: false,
|
|
3872
|
+
isCodeBlock: false,
|
|
3873
|
+
isBlockquote: false,
|
|
3874
|
+
listType: void 0,
|
|
3875
|
+
indent
|
|
3876
|
+
};
|
|
3834
3877
|
}
|
|
3835
3878
|
}
|
|
3836
|
-
return {
|
|
3879
|
+
return {
|
|
3880
|
+
tag: "p",
|
|
3881
|
+
isList: false,
|
|
3882
|
+
isCodeBlock: false,
|
|
3883
|
+
isBlockquote: false,
|
|
3884
|
+
listType: void 0,
|
|
3885
|
+
indent
|
|
3886
|
+
};
|
|
3887
|
+
}
|
|
3888
|
+
function collectBlockquoteLines(lines, startIndex) {
|
|
3889
|
+
const quoteLines = [];
|
|
3890
|
+
for (let i = startIndex; i < lines.length; i++) {
|
|
3891
|
+
const line = lines[i];
|
|
3892
|
+
if (!line || !line.attributes?.blockquote) break;
|
|
3893
|
+
quoteLines.push(line);
|
|
3894
|
+
}
|
|
3895
|
+
return quoteLines;
|
|
3896
|
+
}
|
|
3897
|
+
function renderBlockquote(quoteLines, embedRenderers, pretty, blockHandlers, options, resolvedDocumentPresentation) {
|
|
3898
|
+
const firstAttrs = quoteLines[0]?.attributes;
|
|
3899
|
+
const wrapperIndent = firstAttrs && typeof firstAttrs.indent === "number" && firstAttrs.indent > 0 ? ` style="margin-left: ${firstAttrs.indent * 2}em"` : "";
|
|
3900
|
+
const nl = pretty ? "\n" : "";
|
|
3901
|
+
const innerIndent = pretty ? " " : "";
|
|
3902
|
+
let html = `<blockquote${wrapperIndent}>${nl}`;
|
|
3903
|
+
for (const line of quoteLines) {
|
|
3904
|
+
const content = renderLineContent(line.ops, embedRenderers, blockHandlers, options);
|
|
3905
|
+
html += `${innerIndent}${renderBlockquoteParagraph(content, line.attributes, resolvedDocumentPresentation)}${nl}`;
|
|
3906
|
+
}
|
|
3907
|
+
html += `</blockquote>`;
|
|
3908
|
+
return pretty ? html + "\n" : html;
|
|
3909
|
+
}
|
|
3910
|
+
function renderBlockquoteParagraph(content, attributes, resolvedDocumentPresentation) {
|
|
3911
|
+
const styleSource = attributes ? { ...attributes, indent: void 0 } : void 0;
|
|
3912
|
+
const styleAttr = getBlockStyleAttribute("blockquote", styleSource, resolvedDocumentPresentation);
|
|
3913
|
+
const innerContent = content || "<br>";
|
|
3914
|
+
return `<p${styleAttr}>${innerContent}</p>`;
|
|
3837
3915
|
}
|
|
3838
3916
|
function collectCodeBlockLines(lines, startIndex) {
|
|
3839
3917
|
const codeLines = [];
|
|
@@ -4084,6 +4162,22 @@ function renderEmbed(value, attributes, renderers, blockHandlers, options) {
|
|
|
4084
4162
|
|
|
4085
4163
|
// src/conversion/html/html-to-delta.ts
|
|
4086
4164
|
var import_delta9 = require("@scrider/delta");
|
|
4165
|
+
var BLOCKQUOTE_INNER_BLOCK_TAGS = /* @__PURE__ */ new Set([
|
|
4166
|
+
"p",
|
|
4167
|
+
"div",
|
|
4168
|
+
"h1",
|
|
4169
|
+
"h2",
|
|
4170
|
+
"h3",
|
|
4171
|
+
"h4",
|
|
4172
|
+
"h5",
|
|
4173
|
+
"h6",
|
|
4174
|
+
"ul",
|
|
4175
|
+
"ol",
|
|
4176
|
+
"li",
|
|
4177
|
+
"pre",
|
|
4178
|
+
"blockquote",
|
|
4179
|
+
"table"
|
|
4180
|
+
]);
|
|
4087
4181
|
function isCssWideKeyword(value) {
|
|
4088
4182
|
return /^(inherit|initial|unset|revert|revert-layer)$/i.test(value.trim());
|
|
4089
4183
|
}
|
|
@@ -4336,9 +4430,21 @@ function htmlToDelta(html, options = {}) {
|
|
|
4336
4430
|
}
|
|
4337
4431
|
}
|
|
4338
4432
|
processChildren(element);
|
|
4339
|
-
|
|
4433
|
+
if (!(format.format === "blockquote" && hasBlockChildElement(element))) {
|
|
4434
|
+
context.pushNewline();
|
|
4435
|
+
}
|
|
4340
4436
|
currentBlockAttributes = prevBlockAttrs;
|
|
4341
4437
|
}
|
|
4438
|
+
function hasBlockChildElement(element) {
|
|
4439
|
+
const children2 = element.childNodes;
|
|
4440
|
+
for (let i = 0; i < children2.length; i++) {
|
|
4441
|
+
const child = children2[i];
|
|
4442
|
+
if (!child || !isElement(child)) continue;
|
|
4443
|
+
const tag = child.tagName.toLowerCase();
|
|
4444
|
+
if (BLOCKQUOTE_INNER_BLOCK_TAGS.has(tag)) return true;
|
|
4445
|
+
}
|
|
4446
|
+
return false;
|
|
4447
|
+
}
|
|
4342
4448
|
function processCodeBlockElement(element) {
|
|
4343
4449
|
const prevBlockAttrs = { ...currentBlockAttributes };
|
|
4344
4450
|
let language;
|