testomatio-editor-blocks 0.4.36 → 0.4.39

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.
@@ -22,7 +22,7 @@ const headingPrefixes = {
22
22
  5: "#####",
23
23
  6: "######",
24
24
  };
25
- const SPECIAL_CHAR_REGEX = /([*_`~\[\]()<>\\])/g;
25
+ const SPECIAL_CHAR_REGEX = /([*_`~\[\]()<\\])/g;
26
26
  const HTML_SPAN_REGEX = /<\/?span[^>]*>/g;
27
27
  const HTML_UNDERLINE_REGEX = /<\/?u>/g;
28
28
  const EXPECTED_LABEL_REGEX = /^(?:[*_`]*\s*)?(expected(?:\s+result)?)\s*(?:[*_`]*\s*)?\s*[:\-–—]\s*/i;
@@ -77,7 +77,7 @@ function stripLeadingFormatting(text) {
77
77
  return result;
78
78
  }
79
79
  function unescapeMarkdown(text) {
80
- return stripHtmlWrappers(text).replace(/\\([*_`~\[\]()<>\\])/g, "$1");
80
+ return stripHtmlWrappers(text).replace(/\\([*_`~\[\]()<>\\])/g, "$1").replace(/\\>/g, ">");
81
81
  }
82
82
  function applyTextStyles(text, styles) {
83
83
  if (!styles) {
@@ -426,7 +426,16 @@ function serializeBlock(block, ctx, orderedIndex, stepIndex) {
426
426
  const formatCell = (value) => {
427
427
  if (!value.length)
428
428
  return " ";
429
- return value.replace(/\n/g, "<br/>");
429
+ // Handle newlines inside backtick code spans:
430
+ // close code before <br>, reopen after
431
+ let result = value.replace(/`([^`]*)`/g, (match) => {
432
+ if (!match.includes("\n"))
433
+ return match;
434
+ const inner = match.slice(1, -1);
435
+ const parts = inner.split("\n");
436
+ return parts.map((p) => (p ? `\`${p}\`` : "")).join("<br>");
437
+ });
438
+ return result.replace(/\n/g, "<br>");
430
439
  };
431
440
  const toAlignmentToken = (alignment) => {
432
441
  switch (alignment) {
@@ -1007,7 +1016,7 @@ function parseQuote(lines, index) {
1007
1016
  if (!trimmed.startsWith(">")) {
1008
1017
  break;
1009
1018
  }
1010
- collected.push(trimmed.replace(/^>\s?/, ""));
1019
+ collected.push(trimmed.replace(/^(?:>\s?)+/, ""));
1011
1020
  next += 1;
1012
1021
  }
1013
1022
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testomatio-editor-blocks",
3
- "version": "0.4.36",
3
+ "version": "0.4.39",
4
4
  "description": "Custom BlockNote schema, markdown conversion helpers, and UI for Testomatio-style test cases and steps.",
5
5
  "type": "module",
6
6
  "main": "./package/index.js",
@@ -389,6 +389,26 @@ describe("blocksToMarkdown", () => {
389
389
  );
390
390
  });
391
391
 
392
+ it("serializes a blockquote", () => {
393
+ const blocks: CustomEditorBlock[] = [
394
+ {
395
+ id: "q1",
396
+ type: "quote",
397
+ props: { textColor: "default", backgroundColor: "default", textAlignment: "left" },
398
+ content: [{ type: "text", text: "Hello world", styles: {} }],
399
+ children: [],
400
+ },
401
+ ];
402
+
403
+ expect(blocksToMarkdown(blocks)).toBe("> Hello world");
404
+ });
405
+
406
+ it("round-trips a blockquote without escaping > in content", () => {
407
+ const markdown = "> Some quoted text";
408
+ const blocks = markdownToBlocks(markdown);
409
+ expect(blocksToMarkdown(blocks as any)).toBe("> Some quoted text");
410
+ });
411
+
392
412
  it("serializes table cells containing newlines as <br/>", () => {
393
413
  const blocks: CustomEditorBlock[] = [
394
414
  {
@@ -438,7 +458,64 @@ describe("blocksToMarkdown", () => {
438
458
  [
439
459
  "| Steps | Expected Results |",
440
460
  "| --- | --- |",
441
- "| line1<br/>line2 | ok |",
461
+ "| line1<br>line2 | ok |",
462
+ ].join("\n"),
463
+ );
464
+ });
465
+
466
+ it("serializes table cell with code style and newline placing br outside backticks", () => {
467
+ const blocks: CustomEditorBlock[] = [
468
+ {
469
+ id: "tbl-code",
470
+ type: "table",
471
+ props: { textColor: "default" },
472
+ content: {
473
+ type: "tableContent",
474
+ columnWidths: [undefined, undefined],
475
+ headerRows: 1,
476
+ rows: [
477
+ {
478
+ cells: [
479
+ {
480
+ type: "tableCell",
481
+ props: cellProps,
482
+ content: [{ type: "text", text: "A", styles: {} }],
483
+ },
484
+ {
485
+ type: "tableCell",
486
+ props: cellProps,
487
+ content: [{ type: "text", text: "B", styles: {} }],
488
+ },
489
+ ],
490
+ },
491
+ {
492
+ cells: [
493
+ {
494
+ type: "tableCell",
495
+ props: cellProps,
496
+ content: [
497
+ { type: "text", text: "code", styles: { code: true } },
498
+ { type: "text", text: "\nnext line", styles: {} },
499
+ ],
500
+ },
501
+ {
502
+ type: "tableCell",
503
+ props: cellProps,
504
+ content: [{ type: "text", text: "ok", styles: {} }],
505
+ },
506
+ ],
507
+ },
508
+ ],
509
+ },
510
+ children: [],
511
+ },
512
+ ];
513
+
514
+ expect(blocksToMarkdown(blocks)).toBe(
515
+ [
516
+ "| A | B |",
517
+ "| --- | --- |",
518
+ "| `code`<br>next line | ok |",
442
519
  ].join("\n"),
443
520
  );
444
521
  });
@@ -494,7 +571,7 @@ describe("blocksToMarkdown", () => {
494
571
  [
495
572
  "| Col A | Col B |",
496
573
  "| --- | --- |",
497
- "| ok | **opened**<br/>**newline** |",
574
+ "| ok | **opened**<br>**newline** |",
498
575
  ].join("\n"),
499
576
  );
500
577
  });
@@ -516,6 +593,48 @@ describe("blocksToMarkdown", () => {
516
593
  });
517
594
 
518
595
  describe("markdownToBlocks", () => {
596
+ it("parses nested blockquote by flattening to single-level quote", () => {
597
+ const markdown = ">> The Witch bade her clean the pots.";
598
+ const blocks = markdownToBlocks(markdown);
599
+ expect(blocks).toEqual([
600
+ {
601
+ type: "quote",
602
+ props: { textColor: "default", backgroundColor: "default", textAlignment: "left" },
603
+ content: [{ type: "text", text: "The Witch bade her clean the pots.", styles: {} }],
604
+ children: [],
605
+ },
606
+ ]);
607
+ });
608
+
609
+ it("parses spaced nested blockquote > > text", () => {
610
+ const markdown = "> > The Witch bade her clean the pots.";
611
+ const blocks = markdownToBlocks(markdown);
612
+ expect(blocks).toEqual([
613
+ {
614
+ type: "quote",
615
+ props: { textColor: "default", backgroundColor: "default", textAlignment: "left" },
616
+ content: [{ type: "text", text: "The Witch bade her clean the pots.", styles: {} }],
617
+ children: [],
618
+ },
619
+ ]);
620
+ });
621
+
622
+ it("round-trips nested blockquote without \\> escaping", () => {
623
+ const markdown = [
624
+ "> Dorothy followed her through many of the beautiful rooms in her castle.",
625
+ ">> The Witch bade her clean the pots.",
626
+ ].join("\n");
627
+
628
+ const blocks = markdownToBlocks(markdown);
629
+ const result = blocksToMarkdown(blocks as any);
630
+ expect(result).toBe(
631
+ [
632
+ "> Dorothy followed her through many of the beautiful rooms in her castle.",
633
+ "> The Witch bade her clean the pots.",
634
+ ].join("\n"),
635
+ );
636
+ });
637
+
519
638
  it("parses test steps and test cases", () => {
520
639
  const markdown = [
521
640
  "* Open the Login page.",
@@ -1436,7 +1555,7 @@ describe("markdownToBlocks", () => {
1436
1555
  const markdown = [
1437
1556
  "| A | B |",
1438
1557
  "| --- | --- |",
1439
- "| line1<br/>line2 | ok |",
1558
+ "| line1<br>line2 | ok |",
1440
1559
  ].join("\n");
1441
1560
 
1442
1561
  const blocks = markdownToBlocks(markdown);
@@ -1530,7 +1649,7 @@ describe("markdownToBlocks", () => {
1530
1649
  ];
1531
1650
 
1532
1651
  const markdown = blocksToMarkdown(blocks);
1533
- expect(markdown).toContain("first<br/>second<br/>third");
1652
+ expect(markdown).toContain("first<br>second<br>third");
1534
1653
 
1535
1654
  const parsed = markdownToBlocks(markdown);
1536
1655
  const row = (parsed[0] as any).content.rows[1];
@@ -60,7 +60,7 @@ const headingPrefixes: Record<number, string> = {
60
60
  6: "######",
61
61
  };
62
62
 
63
- const SPECIAL_CHAR_REGEX = /([*_`~\[\]()<>\\])/g;
63
+ const SPECIAL_CHAR_REGEX = /([*_`~\[\]()<\\])/g;
64
64
  const HTML_SPAN_REGEX = /<\/?span[^>]*>/g;
65
65
  const HTML_UNDERLINE_REGEX = /<\/?u>/g;
66
66
  const EXPECTED_LABEL_REGEX = /^(?:[*_`]*\s*)?(expected(?:\s+result)?)\s*(?:[*_`]*\s*)?\s*[:\-–—]\s*/i;
@@ -125,7 +125,7 @@ function stripLeadingFormatting(text: string): string {
125
125
  }
126
126
 
127
127
  function unescapeMarkdown(text: string): string {
128
- return stripHtmlWrappers(text).replace(/\\([*_`~\[\]()<>\\])/g, "$1");
128
+ return stripHtmlWrappers(text).replace(/\\([*_`~\[\]()<>\\])/g, "$1").replace(/\\>/g, ">");
129
129
  }
130
130
 
131
131
  function applyTextStyles(text: string, styles: EditorStyles | undefined): string {
@@ -525,7 +525,15 @@ function serializeBlock(
525
525
  const formattedRows = rows.map(normalizeRow);
526
526
  const formatCell = (value: string) => {
527
527
  if (!value.length) return " ";
528
- return value.replace(/\n/g, "<br/>");
528
+ // Handle newlines inside backtick code spans:
529
+ // close code before <br>, reopen after
530
+ let result = value.replace(/`([^`]*)`/g, (match) => {
531
+ if (!match.includes("\n")) return match;
532
+ const inner = match.slice(1, -1);
533
+ const parts = inner.split("\n");
534
+ return parts.map((p) => (p ? `\`${p}\`` : "")).join("<br>");
535
+ });
536
+ return result.replace(/\n/g, "<br>");
529
537
  };
530
538
  const toAlignmentToken = (alignment: string) => {
531
539
  switch (alignment) {
@@ -1206,7 +1214,7 @@ function parseQuote(lines: string[], index: number): { block: CustomPartialBlock
1206
1214
  if (!trimmed.startsWith(">")) {
1207
1215
  break;
1208
1216
  }
1209
- collected.push(trimmed.replace(/^>\s?/, ""));
1217
+ collected.push(trimmed.replace(/^(?:>\s?)+/, ""));
1210
1218
  next += 1;
1211
1219
  }
1212
1220