testomatio-editor-blocks 0.4.63 → 0.4.64
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.
|
@@ -262,7 +262,8 @@ function serializeBlock(block, ctx, orderedIndex, stepIndex) {
|
|
|
262
262
|
return lines;
|
|
263
263
|
}
|
|
264
264
|
case "codeBlock": {
|
|
265
|
-
const
|
|
265
|
+
const rawLanguage = block.props.language || "";
|
|
266
|
+
const language = /[\s`]/.test(rawLanguage) ? "" : rawLanguage;
|
|
266
267
|
const fence = "```" + language;
|
|
267
268
|
const body = inlineContentToPlainText(block.content);
|
|
268
269
|
lines.push(fence);
|
|
@@ -1087,8 +1088,17 @@ function parseCodeBlock(lines, index) {
|
|
|
1087
1088
|
nextIndex: index + 1,
|
|
1088
1089
|
};
|
|
1089
1090
|
}
|
|
1090
|
-
const
|
|
1091
|
+
const info = afterOpening.trim();
|
|
1092
|
+
let language = "";
|
|
1091
1093
|
const body = [];
|
|
1094
|
+
if (info.length > 0) {
|
|
1095
|
+
if (/[\s`]/.test(info)) {
|
|
1096
|
+
body.push(afterOpening);
|
|
1097
|
+
}
|
|
1098
|
+
else {
|
|
1099
|
+
language = info;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1092
1102
|
let next = index + 1;
|
|
1093
1103
|
while (next < lines.length && !lines[next].startsWith("```")) {
|
|
1094
1104
|
body.push(lines[next]);
|
package/package.json
CHANGED
|
@@ -2685,6 +2685,90 @@ describe("markdownToBlocks", () => {
|
|
|
2685
2685
|
},
|
|
2686
2686
|
]);
|
|
2687
2687
|
});
|
|
2688
|
+
|
|
2689
|
+
it("preserves opening-fence content when it is not a clean language identifier", () => {
|
|
2690
|
+
const markdown = [
|
|
2691
|
+
"```curl `http://localhost:3000/projects/classic-project/test/e1c1b38c/edit` \\",
|
|
2692
|
+
"{{baseURL}}/endpoint?query_param_one=value_one&query_param_two=value_two",
|
|
2693
|
+
"```",
|
|
2694
|
+
].join("\n");
|
|
2695
|
+
const blocks = markdownToBlocks(markdown);
|
|
2696
|
+
expect(blocks).toEqual([
|
|
2697
|
+
{
|
|
2698
|
+
type: "codeBlock",
|
|
2699
|
+
props: { language: "" },
|
|
2700
|
+
content: [
|
|
2701
|
+
{
|
|
2702
|
+
type: "text",
|
|
2703
|
+
text: [
|
|
2704
|
+
"curl `http://localhost:3000/projects/classic-project/test/e1c1b38c/edit` \\",
|
|
2705
|
+
"{{baseURL}}/endpoint?query_param_one=value_one&query_param_two=value_two",
|
|
2706
|
+
].join("\n"),
|
|
2707
|
+
styles: {},
|
|
2708
|
+
},
|
|
2709
|
+
],
|
|
2710
|
+
children: [],
|
|
2711
|
+
},
|
|
2712
|
+
]);
|
|
2713
|
+
});
|
|
2714
|
+
|
|
2715
|
+
it("round-trips an opening-fence-with-content code block to stable markdown", () => {
|
|
2716
|
+
const markdown = [
|
|
2717
|
+
"```curl `http://localhost:3000/projects/classic-project/test/e1c1b38c/edit` \\",
|
|
2718
|
+
"{{baseURL}}/endpoint?query_param_one=value_one&query_param_two=value_two",
|
|
2719
|
+
"```",
|
|
2720
|
+
].join("\n");
|
|
2721
|
+
const blocks = markdownToBlocks(markdown);
|
|
2722
|
+
const serialized = blocksToMarkdown(blocks as CustomEditorBlock[]);
|
|
2723
|
+
expect(serialized).toBe(
|
|
2724
|
+
[
|
|
2725
|
+
"```",
|
|
2726
|
+
"curl `http://localhost:3000/projects/classic-project/test/e1c1b38c/edit` \\",
|
|
2727
|
+
"{{baseURL}}/endpoint?query_param_one=value_one&query_param_two=value_two",
|
|
2728
|
+
"```",
|
|
2729
|
+
].join("\n"),
|
|
2730
|
+
);
|
|
2731
|
+
expect(markdownToBlocks(serialized)).toEqual(blocks);
|
|
2732
|
+
});
|
|
2733
|
+
|
|
2734
|
+
it("preserves hyphenated language identifiers like shell-session", () => {
|
|
2735
|
+
const markdown = ["```shell-session", "$ ls", "```"].join("\n");
|
|
2736
|
+
const blocks = markdownToBlocks(markdown);
|
|
2737
|
+
expect(blocks).toEqual([
|
|
2738
|
+
{
|
|
2739
|
+
type: "codeBlock",
|
|
2740
|
+
props: { language: "shell-session" },
|
|
2741
|
+
content: [{ type: "text", text: "$ ls", styles: {} }],
|
|
2742
|
+
children: [],
|
|
2743
|
+
},
|
|
2744
|
+
]);
|
|
2745
|
+
});
|
|
2746
|
+
|
|
2747
|
+
it("preserves digit-prefixed language identifiers like 1c-enterprise", () => {
|
|
2748
|
+
const markdown = ["```1c-enterprise", "code", "```"].join("\n");
|
|
2749
|
+
const blocks = markdownToBlocks(markdown);
|
|
2750
|
+
expect(blocks).toEqual([
|
|
2751
|
+
{
|
|
2752
|
+
type: "codeBlock",
|
|
2753
|
+
props: { language: "1c-enterprise" },
|
|
2754
|
+
content: [{ type: "text", text: "code", styles: {} }],
|
|
2755
|
+
children: [],
|
|
2756
|
+
},
|
|
2757
|
+
]);
|
|
2758
|
+
});
|
|
2759
|
+
|
|
2760
|
+
it("sanitizes a malformed in-memory language prop on serialize", () => {
|
|
2761
|
+
const blocks: CustomEditorBlock[] = [
|
|
2762
|
+
{
|
|
2763
|
+
id: "1",
|
|
2764
|
+
type: "codeBlock",
|
|
2765
|
+
props: { ...baseProps, language: "curl http://x" } as any,
|
|
2766
|
+
content: [{ type: "text", text: "body", styles: {} }] as any,
|
|
2767
|
+
children: [],
|
|
2768
|
+
},
|
|
2769
|
+
];
|
|
2770
|
+
expect(blocksToMarkdown(blocks)).toBe(["```", "body", "```"].join("\n"));
|
|
2771
|
+
});
|
|
2688
2772
|
});
|
|
2689
2773
|
|
|
2690
2774
|
describe("file block serialization", () => {
|
|
@@ -334,7 +334,8 @@ function serializeBlock(
|
|
|
334
334
|
return lines;
|
|
335
335
|
}
|
|
336
336
|
case "codeBlock": {
|
|
337
|
-
const
|
|
337
|
+
const rawLanguage = (block.props as any).language || "";
|
|
338
|
+
const language = /[\s`]/.test(rawLanguage) ? "" : rawLanguage;
|
|
338
339
|
const fence = "```" + language;
|
|
339
340
|
const body = inlineContentToPlainText(block.content);
|
|
340
341
|
lines.push(fence);
|
|
@@ -1290,8 +1291,16 @@ function parseCodeBlock(lines: string[], index: number): { block: CustomPartialB
|
|
|
1290
1291
|
};
|
|
1291
1292
|
}
|
|
1292
1293
|
|
|
1293
|
-
const
|
|
1294
|
+
const info = afterOpening.trim();
|
|
1295
|
+
let language = "";
|
|
1294
1296
|
const body: string[] = [];
|
|
1297
|
+
if (info.length > 0) {
|
|
1298
|
+
if (/[\s`]/.test(info)) {
|
|
1299
|
+
body.push(afterOpening);
|
|
1300
|
+
} else {
|
|
1301
|
+
language = info;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1295
1304
|
let next = index + 1;
|
|
1296
1305
|
while (next < lines.length && !lines[next].startsWith("```") ) {
|
|
1297
1306
|
body.push(lines[next]);
|